Class JcrResourceUtil

java.lang.Object
org.apache.sling.jcr.resource.internal.helper.JcrResourceUtil

public class JcrResourceUtil extends Object
The JcrResourceUtil class provides helper methods used throughout this bundle.
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable javax.jcr.Value
    createValue(@NotNull Object value, @NotNull javax.jcr.Session session)
    Creates a JCR Value for the given object with the given Session.
    static @NotNull javax.jcr.query.QueryResult
    query(@NotNull javax.jcr.Session session, @NotNull String query, @NotNull String language)
    Helper method to execute a JCR query.
    static @NotNull Object
    toJavaObject(@NotNull javax.jcr.Property property)
    Converts the value(s) of a JCR Property to a corresponding Java Object.
    static @NotNull Object
    toJavaObject(@NotNull javax.jcr.Value value)
    Converts a JCR Value to a corresponding Java Object

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • query

      @NotNull public static @NotNull javax.jcr.query.QueryResult query(@NotNull @NotNull javax.jcr.Session session, @NotNull @NotNull String query, @NotNull @NotNull String language) throws javax.jcr.RepositoryException
      Helper method to execute a JCR query.
      Parameters:
      session - the session
      query - the query
      language - the language
      Returns:
      the query's result
      Throws:
      javax.jcr.RepositoryException - if the QueryManager cannot be retrieved
    • toJavaObject

      @NotNull public static @NotNull Object toJavaObject(@NotNull @NotNull javax.jcr.Value value) throws javax.jcr.RepositoryException
      Converts a JCR Value to a corresponding Java Object
      Parameters:
      value - the JCR Value to convert
      Returns:
      the Java Object
      Throws:
      javax.jcr.RepositoryException - if the value cannot be converted
    • toJavaObject

      @NotNull public static @NotNull Object toJavaObject(@NotNull @NotNull javax.jcr.Property property) throws javax.jcr.RepositoryException
      Converts the value(s) of a JCR Property to a corresponding Java Object. If the property has multiple values the result is an array of Java Objects representing the converted values of the property.
      Parameters:
      property - the property to be converted to the corresponding Java Object
      Returns:
      the Object resulting from the conversion
      Throws:
      javax.jcr.RepositoryException - if the conversion cannot take place
    • createValue

      @Nullable public static @Nullable javax.jcr.Value createValue(@NotNull @NotNull Object value, @NotNull @NotNull javax.jcr.Session session) throws javax.jcr.RepositoryException
      Creates a JCR Value for the given object with the given Session. Selects the the PropertyType according the instance of the object's Class
      Parameters:
      value - object
      session - to create value for
      Returns:
      the value or null if not convertible to a valid PropertyType
      Throws:
      javax.jcr.RepositoryException - in case of error, accessing the Repository