WebLab taglib

From WebLab Wiki
Jump to navigationJump to search

The WebLab taglib provides :

  • tag to easily read values for a given RDF property about a WebLab resource
  • tag to easily format in HTML some well knows values
  • EL function to test the existence of values for a given RDF property about a WebLab resource

Install WebLab taglib

If you are using Apache Tomcat container and Apache Maven then follow the following two simple steps:

   Add this maven dependency to your pom file :
    <dependency>
	<groupId>org.ow2.weblab.components</groupId>
	<artifactId>weblab-taglib</artifactId>
	<version>0.0.2</version>
    </dependency>
   To use any of the libraries, you must include a <taglib> directive at the top of each JSP that uses the library.
    <%@ taglib uri="http://org.ow2.weblab/taglib" prefix="weblab"%>

WebLab Tags

Reading RDF properties values

To ease the reading of RDF properties values about a WebLab resource inside a JSP. The taglib will try produce a list of typed Java object (String, Long, Date, etc.) as returned value based on the 'rdf:datatype' attribute value.

The values returned depends of the output page locale. If localized RDF properties values are available, only values that match the current page locale are returned. If no localized values are available, all non localized values are returned.

Tag

<weblab:getPropertyValues>

Attributes

Available attributes for this tag

Name Default Required Description
resource None no The WebLab resource. If specified, values are retrieved from the passed resource otherwise values are retrieved from "resource" attribute of the page context.
uri None yes The RDF property uri.
var None no The page variable filled with the list of type values. If not specified, the values are written in the output by using the toString() method of the list items objects.

Examples

If the attribute 'resource' is defined in the pageContext with a WebLab resource annotated with dc:title 'My resource title', then the code :

<%@ taglib uri="http://org.ow2.weblab/taglib" prefix="weblab"%>
<html>
  <body>
    <h1>
      <weblab:getPropertyValues uri="http://purl.org/dc/elements/1.1/title">
    </h1>
  </body>
</html>

will output the following HTML code:

<html>
  <body>
    <h1>
      My resource title
    </h1>
  </body>
</html>

If the attribute 'resource' is defined in the pageContext with a WebLab resource annotated with dc:title 'My resource title' and 'My alternate resource title', then the code :

<%@ taglib uri="http://org.ow2.weblab/taglib" prefix="weblab"%>
<html>
  <body>
    <h1>
      <weblab:getPropertyValues uri="http://purl.org/dc/elements/1.1/title">
    </h1>
  </body>
</html>

will output the following HTML code:

<html>
  <body>
    <h1>
      My resource titleMy alternate resource title
    </h1>
  </body>
</html>

In this case it will be better to iterate over property values :

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://org.ow2.weblab/taglib" prefix="weblab"%>

<html>
  <body>
    <h1>
      <weblab:getPropertyValues uri="http://purl.org/dc/elements/1.1/title" var="titles">
      <c:forEach var="title" items="${titles }" varStatus="status">
        <c:if test="${status.count != 1}">
	  &nbsp;-&nbsp;
	</c:if>
	${title }
      </c:forEach>	
    </h1>
  </body>
</html>

Will output the following HTML code:

<html>
  <body>
    <h1>
      My resource title - My alternate resource title
    </h1>
  </body>
</html>


If the attribute 'resource' is defined in the pageContext with a WebLab resource annotated with dc:title 'My resource title@en' and 'Mon titre@fr', and the output page locale is set to English, then the code :

<%@ taglib uri="http://org.ow2.weblab/taglib" prefix="weblab"%>
<html>
  <body>
    <h1>
      <weblab:getPropertyValues uri="http://purl.org/dc/elements/1.1/title">
    </h1>
  </body>
</html>

will output the following HTML code:

<html>
  <body>
    <h1>
      My resource title
    </h1>
  </body>
</html>

Formatting RDF properties values

To ensure coherence inside of WebLab applications, well knowed values should be presented in a normalized way. For example, values associated to the 'dc:format' property should always be presented with the same icon. To enable this functionnality and ease rendering of RDF values, the WebLab taglib propose a dedicated tag to render values regarding to a set of styles (see the styles table).

In version 0.0.1, values corresponding to format values (pdf, txt, word, etc.) and languages values (fr, en, de, etc.) are normalized regarding to the output page locale.

If the passed value to be formatted is not recognized as a format or a locale value, it is returned as passed for 'text' style. For 'icon' style, an 'unknow' icon is returned.

Tag

<weblab:renderValues>

Attributes

Available attributes for this tag

Name Default Required Description
value None no The values to render. If no set, the value is evaluated from the tag body.
style None yes The style used to render the passed value. See next table for available styles.
cssClass None no The CSS class to add in generated html tag
cssId None no The CSS id to add in generated html tag

Available styles

Available attributes for this tag

Name Description
icon produce image html tag from the passed value. Icons are based on the theme named 'weblab'.
text produce a description text in span tag. The span content is reading from the bundle file.
icon+text produce image html tag from the passed value and a description text in span tag. Icons are based on the theme named 'weblab' and span content are reading from the bundle file.
anchor the passed value is converted in anchor tag with href filled with the passed value.
fileSize the passed value is converted in the more human readable value (kb, mb, gb, tb).

Examples

If the attribute 'resource' is defined in the pageContext with a WebLab resource annotated with dc:format 'application/pdf', then the code :

<%@ taglib uri="http://org.ow2.weblab/taglib" prefix="weblab"%>
<html>
  <body>
    <weblab:renderValues style="icon+text" cssClass="myCSSClass">
      <weblab:getPropertyValues uri="http://purl.org/dc/elements/1.1/format">
    </weblab:renderValues>
  </body>
</html>

will output the following HTML code :

<html>
  <body>
    <img class="myCSSClass" title="Portable Document Format (PDF)" alt="Portable Document Format (PDF)" src="/weblab-theme/images/file_system/small/pdf.png">
    <span class="meta_data_formatIconText">Portable Document Format (PDF)</span>
  </body>
</html>

The following JSP code :

<%@ taglib uri="http://org.ow2.weblab/taglib" prefix="weblab"%>
<html>
  <body>
    <weblab:renderValues style="fileSize">
      858454
    </weblab:renderValues>
  </body>
</html>

will output the following HTML code :

<html>
  <body>
     <span>838 KB</span>
  </body>
</html>

Checking for RDF properties values

To check if a WebLab resource have a value for a given RDF property, the taglib provide a dedicated EL function.

EL Function

  weblab:hasValue(resource, propertyURI)

Examples

If the attribute 'resource' is defined in the pageContext with a WebLab resource not annotated with dc:format 'application/pdf', then the code :

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://org.ow2.weblab/taglib" prefix="weblab"%>
<html>
  <body>
    <c:choose>
       <c:when test="${weblab:hasValue(resource, 'http://purl.org/dc/elements/1.1/format')}">
          Format value!
       </c:when>
       <c:otherwise>
          No format value!
       </c:otherwise>
    </c:choose>
  </body>
</html>

will output the following HTML code :

<html>
  <body>
    No format value!
  </body>
</html>