Class ViewHelpers
- java.lang.Object
-
- org.fcrepo.http.commons.responses.ViewHelpers
-
public class ViewHelpers extends Object
General view helpers for rendering HTML responses- Author:
- awoods, ajs6f
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addOne(int i)
Yes, we really did create a method to increment a given int.org.apache.jena.graph.Node
asLiteralStringNode(String r)
Convert a URI string to an RDF nodestatic org.apache.jena.graph.Node
createURI(String uri)
Create a URI Node from the provided Stringstatic org.apache.jena.graph.Node
getContentNode(org.apache.jena.graph.Node subject)
Get the content-bearing node for the given subjectstatic ViewHelpers
getInstance()
ViewHelpers is a singleton.String
getNamespacePrefix(org.apache.jena.shared.PrefixMapping mapping, String ns, boolean compact)
Get the namespace prefix (or the namespace URI itself, if no prefix is available) from a prefix mappingMap<String,String>
getNodeBreadcrumbs(javax.ws.rs.core.UriInfo uriInfo, org.apache.jena.graph.Node subject)
Generate url to local name breadcrumbs for a given node's treeint
getNumChildren(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Get the number of child resources associated with the arg 'subject' as specified by the triple found in the arg 'graph' with the predicate RdfLexicon.HAS_CHILD_COUNT.String
getObjectsAsString(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject, org.apache.jena.rdf.model.Resource predicate, boolean uriAsLink)
Get the string version of the object that matches the given subject and predicateString
getObjectTitle(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node sub)
Get the canonical title of a subject from the graphIterator<org.apache.jena.graph.Node>
getOrderedVersions(org.apache.jena.graph.Graph g, org.apache.jena.graph.Node subject, org.apache.jena.rdf.model.Resource predicate)
Return an iterator of Triples for versions in order that they were created.org.apache.jena.graph.Node
getOriginalResource(String subjectUri)
Same as above but takes a string.org.apache.jena.graph.Node
getOriginalResource(org.apache.jena.graph.Node subject)
Returns the original resource as a URI Node if the subject represents a memento uri; otherwise it returns the subject parameter.String
getPrefixPreamble(org.apache.jena.shared.PrefixMapping mapping)
Get a prefix preamble appropriate for a SPARQL-UPDATE query from a prefix mapping objectString
getResourceId(org.apache.jena.rdf.model.Resource res)
Get the ID of a resource, this is the URI, blank node ID or just the local name.List<org.apache.jena.graph.Triple>
getSortedTriples(org.apache.jena.rdf.model.Model model, Iterator<org.apache.jena.graph.Triple> it)
Sort a Iterator of Triples alphabetically by its subject, predicate, and objectstatic String
getString(Map<String,Object> input, String key)
Find a key in a map and format it as a stringInstant
getVersionDate(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Gets a modification date of a subject from the graphString
getVersionLabel(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Get the date time as the version label.Iterator<org.apache.jena.graph.Node>
getVersions(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Return an iterator of Triples for versions.String
getVersionSubjectUrl(javax.ws.rs.core.UriInfo uriInfo, org.apache.jena.graph.Node subject)
Gets the URL of the node whose version is represented by the current node.static boolean
isManagedProperty(org.apache.jena.graph.Node property)
Test if a Predicate is managedboolean
isRdfResource(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject, String namespace, String resource)
Determines whether the subject is kind of RDF resourceboolean
isRootResource(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Is the subject the repository root resource.boolean
isVersionedNode(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Determines whether the subject is of type memento:Memento.boolean
isWritable(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Determines whether the subject is writable true if node is writablestatic String
parameterize(String source)
Transform a source string to something appropriate for HTML idsorg.apache.jena.rdf.model.Resource
rdfsClass()
Proxying access to the RDFS class static propertyorg.apache.jena.rdf.model.Property
rdfsDomain()
Proxying access to the RDFS domain static propertyorg.apache.jena.rdf.model.Property
rdfType()
Proxying access to the RDF type static property
-
-
-
Method Detail
-
getInstance
public static ViewHelpers getInstance()
ViewHelpers is a singleton. Initialize or return the existing object- Returns:
- an instance of ViewHelpers
-
getVersions
public Iterator<org.apache.jena.graph.Node> getVersions(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Return an iterator of Triples for versions.- Parameters:
graph
- the graphsubject
- the subject- Returns:
- iterator
-
getOrderedVersions
public Iterator<org.apache.jena.graph.Node> getOrderedVersions(org.apache.jena.graph.Graph g, org.apache.jena.graph.Node subject, org.apache.jena.rdf.model.Resource predicate)
Return an iterator of Triples for versions in order that they were created.- Parameters:
g
- the graphsubject
- the subjectpredicate
- the predicate- Returns:
- iterator
-
getVersionSubjectUrl
public String getVersionSubjectUrl(javax.ws.rs.core.UriInfo uriInfo, org.apache.jena.graph.Node subject)
Gets the URL of the node whose version is represented by the current node. The current implementation assumes the URI of that node will be the same as the breadcrumb entry that precedes one with the path "fcr:versions".- Parameters:
uriInfo
- the uri infosubject
- the subject- Returns:
- the URL of the node
-
getVersionLabel
public String getVersionLabel(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Get the date time as the version label.- Parameters:
graph
- the graphsubject
- the subject- Returns:
- the datetime in RFC 1123 format.
-
getVersionDate
public Instant getVersionDate(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Gets a modification date of a subject from the graph- Parameters:
graph
- the graphsubject
- the subject- Returns:
- the modification date if it exists
-
getObjectTitle
public String getObjectTitle(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node sub)
Get the canonical title of a subject from the graph- Parameters:
graph
- the graphsub
- the subject- Returns:
- canonical title of the subject in the graph
-
getResourceId
public String getResourceId(org.apache.jena.rdf.model.Resource res)
Get the ID of a resource, this is the URI, blank node ID or just the local name. Used in resource.vsl- Parameters:
res
- The resource to get the ID for- Returns:
- The ID as a string.
-
isWritable
public boolean isWritable(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Determines whether the subject is writable true if node is writable- Parameters:
graph
- the graphsubject
- the subject- Returns:
- whether the subject is writable
-
isVersionedNode
public boolean isVersionedNode(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Determines whether the subject is of type memento:Memento.- Parameters:
graph
- the graphsubject
- the subject- Returns:
- whether the subject is a versioned node
-
getObjectsAsString
public String getObjectsAsString(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject, org.apache.jena.rdf.model.Resource predicate, boolean uriAsLink)
Get the string version of the object that matches the given subject and predicate- Parameters:
graph
- the graphsubject
- the subjectpredicate
- the predicateuriAsLink
- the boolean value of uri as link- Returns:
- string version of the object
-
getOriginalResource
public org.apache.jena.graph.Node getOriginalResource(org.apache.jena.graph.Node subject)
Returns the original resource as a URI Node if the subject represents a memento uri; otherwise it returns the subject parameter.- Parameters:
subject
- the subject- Returns:
- a URI node of the original resource.
-
getOriginalResource
public org.apache.jena.graph.Node getOriginalResource(String subjectUri)
Same as above but takes a string. NB: This method is currently used in fcrepo-http-api/src/main/resources/views/default.vsl- Parameters:
subjectUri
- the URI- Returns:
- a node
-
getNumChildren
public int getNumChildren(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Get the number of child resources associated with the arg 'subject' as specified by the triple found in the arg 'graph' with the predicate RdfLexicon.HAS_CHILD_COUNT.- Parameters:
graph
- of triplessubject
- for which child resources is sought- Returns:
- number of child resources
-
getNodeBreadcrumbs
public Map<String,String> getNodeBreadcrumbs(javax.ws.rs.core.UriInfo uriInfo, org.apache.jena.graph.Node subject)
Generate url to local name breadcrumbs for a given node's tree- Parameters:
uriInfo
- the uri infosubject
- the subject- Returns:
- breadcrumbs
-
getSortedTriples
public List<org.apache.jena.graph.Triple> getSortedTriples(org.apache.jena.rdf.model.Model model, Iterator<org.apache.jena.graph.Triple> it)
Sort a Iterator of Triples alphabetically by its subject, predicate, and object- Parameters:
model
- the modelit
- the iterator of triples- Returns:
- iterator of alphabetized triples
-
getNamespacePrefix
public String getNamespacePrefix(org.apache.jena.shared.PrefixMapping mapping, String ns, boolean compact)
Get the namespace prefix (or the namespace URI itself, if no prefix is available) from a prefix mapping- Parameters:
mapping
- the prefix mappingns
- the namespacecompact
- the boolean value of compact- Returns:
- namespace prefix
-
getPrefixPreamble
public String getPrefixPreamble(org.apache.jena.shared.PrefixMapping mapping)
Get a prefix preamble appropriate for a SPARQL-UPDATE query from a prefix mapping object- Parameters:
mapping
- the prefix mapping- Returns:
- prefix preamble
-
isRdfResource
public boolean isRdfResource(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject, String namespace, String resource)
Determines whether the subject is kind of RDF resource- Parameters:
graph
- the graphsubject
- the subjectnamespace
- the namespaceresource
- the resource- Returns:
- whether the subject is kind of RDF resource
-
isRootResource
public boolean isRootResource(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
Is the subject the repository root resource.- Parameters:
graph
- The graphsubject
- The current subject- Returns:
- true if has rdf:type http://fedora.info/definitions/v4/repository#RepositoryRoot
-
asLiteralStringNode
public org.apache.jena.graph.Node asLiteralStringNode(String r)
Convert a URI string to an RDF node- Parameters:
r
- the uri string- Returns:
- RDF node representation of the given string
-
addOne
public int addOne(int i)
Yes, we really did create a method to increment a given int. You can't do math in a velocity template.- Parameters:
i
- the given integer- Returns:
- maths
-
rdfType
public org.apache.jena.rdf.model.Property rdfType()
Proxying access to the RDF type static property- Returns:
- RDF type property
-
rdfsDomain
public org.apache.jena.rdf.model.Property rdfsDomain()
Proxying access to the RDFS domain static property- Returns:
- RDFS domain property
-
rdfsClass
public org.apache.jena.rdf.model.Resource rdfsClass()
Proxying access to the RDFS class static property- Returns:
- RDFS class resource
-
getContentNode
public static org.apache.jena.graph.Node getContentNode(org.apache.jena.graph.Node subject)
Get the content-bearing node for the given subject- Parameters:
subject
- the subject- Returns:
- content-bearing node for the given subject
-
createURI
public static org.apache.jena.graph.Node createURI(String uri)
Create a URI Node from the provided String- Parameters:
uri
- from which a URI Node will be created- Returns:
- URI Node
-
parameterize
public static String parameterize(String source)
Transform a source string to something appropriate for HTML ids- Parameters:
source
- the source string- Returns:
- transformed source string
-
isManagedProperty
public static boolean isManagedProperty(org.apache.jena.graph.Node property)
Test if a Predicate is managed- Parameters:
property
- the property- Returns:
- whether the property is managed
-
-