com.hp.hpl.swade.portal
Class ResourceWrapper

java.lang.Object
  |
  +--com.hp.hpl.swade.portal.NodeWrapper
        |
        +--com.hp.hpl.swade.portal.ResourceWrapper
All Implemented Interfaces:
java.lang.Comparable

public class ResourceWrapper
extends NodeWrapper

A bean wrapper round an RDFNode used to communicate model information to the rendering templates.

Version:
$Revision: 1.5 $ on $Date: 2004/07/16 15:43:50 $
Author:
Dave Reynolds

Field Summary
protected  java.util.Map cache
          Cache of properties values stored as a map from Property to MultiStatementWrapper
 
Fields inherited from class com.hp.hpl.swade.portal.NodeWrapper
datasource, name, node
 
Constructor Summary
ResourceWrapper(com.hp.hpl.jena.rdf.model.Resource node, DataSource datasource)
          Constructor.
 
Method Summary
 void checkCache()
          Ensure the cache is loaded with property values for this resource.
protected  java.util.Collection findProperties(com.hp.hpl.jena.util.iterator.Filter filter, java.util.Collection exclude)
          Helper function, find all properties of the resource which pass the given filter and return a collection of MulitStatementWrappers over those values.
 java.util.Collection findProperties(java.lang.String prop)
          Locates a subset of the properties of a resource as a collection suitable for traversal and rendering.
 java.util.Collection findProperties(java.lang.String prop, java.util.Collection exclude)
          Locates a subset of the properties of a resource as a collection suitable for traversal and rendering.
 java.util.Collection findPropertiesByClass(java.lang.String markerType)
          Locates a subset of the properties of a resource as a collection suitable for traversal and rendering.
 java.util.Collection findPropertiesByClass(java.lang.String markerType, java.util.Collection exclude)
          Locates a subset of the properties of a resource as a collection suitable for traversal and rendering.
 java.util.Collection findPropertiesByPrefix(java.lang.String prefix, java.util.Collection exclude)
          Locates a subset of the properties of a resource as a collection suitable for traversal and rendering.
 void flushCache()
          Flush the cache of property values (because some internal state has changed)
 java.lang.String getActionLink(java.lang.String action, javax.servlet.http.HttpServletRequest request)
          Return the link address which can be used apply the given action to the resource
 java.lang.String getInstancesLink(javax.servlet.http.HttpServletRequest request)
          The resource is assumed to a concept in a search facet and this call returns the html link address which can be used to search for all instances of the concept.
 java.lang.String getPageLink(javax.servlet.http.HttpServletRequest request)
          Return the link address which can be used for rendering this resource to link to a page view
 NodeWrapper getPrimarySource()
          Return the primary source for the properties of this "object".
 java.util.Collection getProperties()
          Return all the properties of this node as a list of MultiStatementWrappers
 MultiStatementWrapper getProperty(java.lang.String prop)
          Return the values of the given property using the appropriate wrapper class.
 java.lang.String getPropertyValue(java.lang.String prop)
          Return a render of a single valued property as a single string.
 com.hp.hpl.jena.rdf.model.Resource getResource()
          Return the wrapped resource
 java.lang.String getTrucatedTextPropertyValue(java.lang.String prop, int words)
          Return a render of a single valued property as a single string, truncated to the given number of space-separated words.
 java.lang.String getUri()
          Return the URI for this node.
 boolean hasProperty(java.lang.String prop)
          Return true if there is at least one value for the property
 boolean hasType(java.lang.String type)
          Return true if one of the rdf:types of this resource is the given resource.
 java.lang.String render(java.lang.String context, javax.servlet.http.HttpServletRequest request)
          Return the HMTL rendering of this resource as a string.
 
Methods inherited from class com.hp.hpl.swade.portal.NodeWrapper
compareTo, getDataSource, getEncoding, getName, getNode, isLiteral
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected java.util.Map cache
Cache of properties values stored as a map from Property to MultiStatementWrapper

Constructor Detail

ResourceWrapper

public ResourceWrapper(com.hp.hpl.jena.rdf.model.Resource node,
                       DataSource datasource)
Constructor.

Method Detail

getUri

public java.lang.String getUri()
Return the URI for this node. In the case of a literal it returns null.


getResource

public com.hp.hpl.jena.rdf.model.Resource getResource()
Return the wrapped resource


checkCache

public void checkCache()
Ensure the cache is loaded with property values for this resource.


flushCache

public void flushCache()
Flush the cache of property values (because some internal state has changed)


getProperty

public MultiStatementWrapper getProperty(java.lang.String prop)
Return the values of the given property using the appropriate wrapper class.

Parameters:
prop - the name of the property which might use prefix notation (with the prefix map of the model in which this node sits) or a full URL.

hasProperty

public boolean hasProperty(java.lang.String prop)
Return true if there is at least one value for the property


hasType

public boolean hasType(java.lang.String type)
Return true if one of the rdf:types of this resource is the given resource.


getPropertyValue

public java.lang.String getPropertyValue(java.lang.String prop)
Return a render of a single valued property as a single string.


getTrucatedTextPropertyValue

public java.lang.String getTrucatedTextPropertyValue(java.lang.String prop,
                                                     int words)
Return a render of a single valued property as a single string, truncated to the given number of space-separated words.


getProperties

public java.util.Collection getProperties()
Return all the properties of this node as a list of MultiStatementWrappers


findProperties

public java.util.Collection findProperties(java.lang.String prop)
Locates a subset of the properties of a resource as a collection suitable for traversal and rendering. In this case the properties are identified as any subProperty of the named property.


findProperties

public java.util.Collection findProperties(java.lang.String prop,
                                           java.util.Collection exclude)
Locates a subset of the properties of a resource as a collection suitable for traversal and rendering. In this case the properties are identified as any subProperty of the named property.

Parameters:
exclude - an optional collection of properties which have already been rendered elsewhere and should be excluded from this find, will be updated by the find, can be null.

findPropertiesByClass

public java.util.Collection findPropertiesByClass(java.lang.String markerType)
Locates a subset of the properties of a resource as a collection suitable for traversal and rendering. In this case the properties are identified as any property which is also marked as having rdf:type of the given class.

Parameters:
markerType - the Class name which is used to mark properties to retain

findPropertiesByClass

public java.util.Collection findPropertiesByClass(java.lang.String markerType,
                                                  java.util.Collection exclude)
Locates a subset of the properties of a resource as a collection suitable for traversal and rendering. In this case the properties are identified as any property which is also marked as having rdf:type of the given class.

Parameters:
markerType - the Class name which is used to mark properties to retain
exclude - an optional collection of properties which have already been rendered elsewhere and should be excluded from this find, will be updated by the find, can be null.

findPropertiesByPrefix

public java.util.Collection findPropertiesByPrefix(java.lang.String prefix,
                                                   java.util.Collection exclude)
Locates a subset of the properties of a resource as a collection suitable for traversal and rendering. In this case the properties are identified by means of a string prefix, often a namespace.

Parameters:
exclude - an optional collection of properties which have already been rendered elsewhere and should be excluded from this find, will be updated by the find, can be null.

findProperties

protected java.util.Collection findProperties(com.hp.hpl.jena.util.iterator.Filter filter,
                                              java.util.Collection exclude)
Helper function, find all properties of the resource which pass the given filter and return a collection of MulitStatementWrappers over those values.


render

public java.lang.String render(java.lang.String context,
                               javax.servlet.http.HttpServletRequest request)
Return the HMTL rendering of this resource as a string. The template for the rendering is controlled by the type of the resource and the rendering context. Here "rendering contexts" are just arbitrary string lables used to group sets of templates together. The only exception is the the context "leaf" is used to force rendering of an inline link to a normal page view of the resource.

Overrides:
render in class NodeWrapper

getPrimarySource

public NodeWrapper getPrimarySource()
Return the primary source for the properties of this "object". The datasource configuration defines a "primaryProperty". We check whether this resource has a value for that property and if so return the source of that value as the primary source for this resource.


getPageLink

public java.lang.String getPageLink(javax.servlet.http.HttpServletRequest request)
Return the link address which can be used for rendering this resource to link to a page view


getInstancesLink

public java.lang.String getInstancesLink(javax.servlet.http.HttpServletRequest request)
The resource is assumed to a concept in a search facet and this call returns the html link address which can be used to search for all instances of the concept.


getActionLink

public java.lang.String getActionLink(java.lang.String action,
                                      javax.servlet.http.HttpServletRequest request)
Return the link address which can be used apply the given action to the resource



Copyright © 2004 Hewlett-Packard. All Rights Reserved.