org.opentox.toxotis.core.html
Class HTMLUtils

java.lang.Object
  extended by org.opentox.toxotis.core.html.HTMLUtils

public class HTMLUtils
extends Object

Utilities for automatically creating HTML code.

Author:
Pantelis Sopasakis, Charalampos Chomenides

Constructor Summary
HTMLUtils()
           
 
Method Summary
static HTMLContainer createComponentList(Collection<? extends OTComponent> objects, String listTag, String divElement)
          Returns a list of objects in an HTML container out of a given list of ToxOtis Components.
static HTMLContainer createLiteralList(Collection<LiteralValue> objects, String listTag, String divElement, boolean displayType)
          Returns a list of elements in an HTML container out of a given list of Literals.
static HTMLContainer createObjectList(Collection objects, String listTag, String divElement)
          Returns a list of objects in an HTML container out of a given list of objects.
static HTMLContainer createOntClassList(Collection<OntologicalClass> objects, String listTag, String divElement, boolean doLink)
          Returns a list of elements in an HTML container out of a given list of OntologicalClass instances.
static HTMLContainer createResourceList(Collection<ResourceValue> objects, String listTag, String divElement, boolean doLink)
          Returns a list of elements in an HTML container out of a given list of Resources.
static String linkUrlsInText(String plainText)
          Detects all URLs in a given text and replaces them with HTML links using the a tag.
static String normalizeTextForHtml(String plainText)
          Normalizes a text for use in HTML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTMLUtils

public HTMLUtils()
Method Detail

createObjectList

public static HTMLContainer createObjectList(Collection objects,
                                             String listTag,
                                             String divElement)
Returns a list of objects in an HTML container out of a given list of objects. The method creates a list invoking the method toString() defined in Object for each one of the objects in the list.

Parameters:
objects - List of objects for which a list in HTML is needed
listTag - The tag that defines the list. It's default value is ol, so in case null is provided, a numbered list will be created.
divElement - The div class to enclose the list. The value _list is the default in case null is provided.
Returns:
A list of the submitted objects in HTML wrapped in an HTMLContainer.

createComponentList

public static HTMLContainer createComponentList(Collection<? extends OTComponent> objects,
                                                String listTag,
                                                String divElement)
Returns a list of objects in an HTML container out of a given list of ToxOtis Components. The method creates a list invoking the method OTComponent.getUri() for each one of the components in the list.

Parameters:
objects - List of components for which a uri list in HTML is needed
listTag - The tag that defines the list. It's default value is ol, so in case null is provided, a numbered list will be created.
divElement - The div class to enclose the list. The value _list is the default in case null is provided.
Returns:
A list of the submitted components in HTML wrapped in an HTMLContainer.

createLiteralList

public static HTMLContainer createLiteralList(Collection<LiteralValue> objects,
                                              String listTag,
                                              String divElement,
                                              boolean displayType)
Returns a list of elements in an HTML container out of a given list of Literals. Users can specify whether the type of each literal should appear in the list.

Parameters:
objects - List of literals for which a uri list in HTML is needed
listTag - The tag that defines the list. It's default value is ol, so in case null is provided, a numbered list will be created.
divElement - The div class to enclose the list. The value _list is the default in case null is provided.
displayType - If true the datatype of each literal value will be displayed in the generated list using the notation value^^type.
Returns:
A list of the submitted literals in HTML wrapped in an HTMLContainer.

createResourceList

public static HTMLContainer createResourceList(Collection<ResourceValue> objects,
                                               String listTag,
                                               String divElement,
                                               boolean doLink)
Returns a list of elements in an HTML container out of a given list of Resources. Users can specify whether the HTML elements will appear as links or in plain text format. The list is compiled as a list of URIs and is constructed my iterated invokation of the method ResourceValue.getUri().

Parameters:
objects - List of resources for which a uri list in HTML is needed
listTag - The tag that defines the list. It's default value is ol, so in case null is provided, a numbered list will be created.
divElement - The div class to enclose the list. The value _list is the default in case null is provided.
doLink - If true the URI of each resource will appear as a link, wrapped in an a tag like <a href="uri">uri</a>
Returns:
A list of the submitted resources in HTML wrapped in an HTMLContainer.

createOntClassList

public static HTMLContainer createOntClassList(Collection<OntologicalClass> objects,
                                               String listTag,
                                               String divElement,
                                               boolean doLink)
Returns a list of elements in an HTML container out of a given list of OntologicalClass instances. Users can specify whether the HTML elements will appear as links or in plain text format. The list is compiled as a list of URIs and is constructed my iterated invokation of the method OntologicalClass.getUri().

Parameters:
objects - List of ontological classes for which a uri list in HTML is needed
listTag - The tag that defines the list. It's default value is ol, so in case null is provided, a numbered list will be created.
divElement - The div class to enclose the list. The value _list is the default in case null is provided.
doLink - If true the URI of each resource will appear as a link, wrapped in an a tag like <a href="uri">uri</a>
Returns:
A list of the submitted ontological classes in HTML wrapped in an HTMLContainer.

linkUrlsInText

public static String linkUrlsInText(String plainText)
Detects all URLs in a given text and replaces them with HTML links using the a tag. For example the text 'My new site is http://mysite.com' is converted into 'My new site is http://mysite.com'. The method's implementation is based on a code snippet found at http://blog.houen.net/java-get-url-from-string/

Parameters:
plainText - Given text
Returns:
Text where all URLs are replaces by links.

normalizeTextForHtml

public static String normalizeTextForHtml(String plainText)
Normalizes a text for use in HTML. Replaces all new lines (/n) by the HTML element
and all & by &.

Parameters:
plainText - Text to be HTML-normalized
Returns:
HTML-normalized text.


Copyright © 2011-2012 OpenTox. All Rights Reserved.