Class 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 node
      static org.apache.jena.graph.Node createURI​(String uri)
      Create a URI Node from the provided String
      static org.apache.jena.graph.Node getContentNode​(org.apache.jena.graph.Node subject)
      Get the content-bearing node for the given subject
      static 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 mapping
      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
      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.
      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
      String getObjectTitle​(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node sub)
      Get the canonical title of a subject from the graph
      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.
      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 object
      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
      static String getString​(Map<String,​Object> input, String key)
      Find a key in a map and format it as a string
      Instant getVersionDate​(org.apache.jena.graph.Graph graph, org.apache.jena.graph.Node subject)
      Gets a modification date of a subject from the graph
      String 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 managed
      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
      boolean 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 writable
      static String parameterize​(String source)
      Transform a source string to something appropriate for HTML ids
      org.apache.jena.rdf.model.Resource rdfsClass()
      Proxying access to the RDFS class static property
      org.apache.jena.rdf.model.Property rdfsDomain()
      Proxying access to the RDFS domain static property
      org.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 graph
        subject - 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 graph
        subject - the subject
        predicate - 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 info
        subject - 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 graph
        subject - 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 graph
        subject - 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 graph
        sub - the subject
        Returns:
        canonical title of the subject in the graph
      • 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 graph
        subject - 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 graph
        subject - 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 graph
        subject - the subject
        predicate - the predicate
        uriAsLink - 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 triples
        subject - for which child resources is sought
        Returns:
        number of child resources
      • getNodeBreadcrumbs

        public Map<String,​StringgetNodeBreadcrumbs​(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 info
        subject - 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 model
        it - 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 mapping
        ns - the namespace
        compact - 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 graph
        subject - the subject
        namespace - the namespace
        resource - 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 graph
        subject - 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
      • getString

        public static String getString​(Map<String,​Object> input,
                                       String key)
        Find a key in a map and format it as a string
        Parameters:
        input - map of objects.
        key - the key to locate in the map.
        Returns:
        the result string.