Class JcrUtils
- java.lang.Object
-
- org.apache.jackrabbit.commons.JcrUtils
-
public class JcrUtils extends Object
Collection of static utility methods for use with the JCR API.- Since:
- Apache Jackrabbit 2.0
-
-
Field Summary
Fields Modifier and Type Field Description static Value[]
NO_VALUES
A pre-allocated empty array of values.static String
REPOSITORY_URI
The repository URI parameter name used by thegetRepository(String)
method.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Binary
getBinaryProperty(Node baseNode, String relPath, Binary defaultValue)
Returns the binary property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static Binary
getBinaryProperty(Session session, String absPath, Binary defaultValue)
Returns the binary property value atabsPath
ordefaultValue
if no such property exists.static boolean
getBooleanProperty(Node baseNode, String relPath, boolean defaultValue)
Returns the boolean property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static boolean
getBooleanProperty(Session session, String absPath, boolean defaultValue)
Returns the boolean property value atabsPath
ordefaultValue
if no such property exists.static Iterable<Node>
getChildNodes(Node node)
Returns anIterable
over the children of the given node.static Iterable<Node>
getChildNodes(Node node, String pattern)
Returns anIterable
over those children of the given node that match the given name pattern.static Iterable<Node>
getChildNodes(Node node, String[] globs)
Returns anIterable
over those children of the given node that match the given name patterns.static Calendar
getDateProperty(Node baseNode, String relPath, Calendar defaultValue)
Returns the date property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static Calendar
getDateProperty(Session session, String absPath, Calendar defaultValue)
Returns the date property value atabsPath
ordefaultValue
if no such property exists.static BigDecimal
getDecimalProperty(Node baseNode, String relPath, BigDecimal defaultValue)
Returns the decimal property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static BigDecimal
getDecimalProperty(Session session, String absPath, BigDecimal defaultValue)
Returns the decimal property value atabsPath
ordefaultValue
if no such property exists.static double
getDoubleProperty(Node baseNode, String relPath, double defaultValue)
Returns the double property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static double
getDoubleProperty(Session session, String absPath, double defaultValue)
Returns the double property value atabsPath
ordefaultValue
if no such property exists.static Calendar
getLastModified(Node node)
Returns the last modified date of the given file node.static long
getLongProperty(Node baseNode, String relPath, long defaultValue)
Returns the long property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static long
getLongProperty(Session session, String absPath, long defaultValue)
Returns the long property value atabsPath
ordefaultValue
if no such property exists.static Node
getNodeIfExists(String absPath, Session session)
Gets the node atabsPath
ornull
if no such node exists.static Node
getNodeIfExists(Node baseNode, String relPath)
Get the node atrelPath
frombaseNode
ornull
if no such node exists.static Iterable<Node>
getNodes(QueryResult result)
Returns anIterable
over nodes in the given query result.static Node
getOrAddFolder(Node parent, String name)
Returns the named child of the given node, creating it as an nt:folder node if it does not already exist.static Node
getOrAddNode(Node parent, String name)
Returns the named child of the given node, creating the child if it does not already exist.static Node
getOrAddNode(Node parent, String name, String type)
Returns the named child of the given node, creating the child if it does not already exist.static Node
getOrCreateByPath(String absolutePath, boolean createUniqueLeaf, String intermediateNodeType, String nodeType, Session session, boolean autoSave)
Creates or gets theNode
at the given Path.static Node
getOrCreateByPath(String absolutePath, String intermediateNodeType, String nodeType, Session session, boolean autoSave)
Creates or gets theNode
at the given Path.static Node
getOrCreateByPath(String absolutePath, String nodeType, Session session)
Creates or gets theNode
at the given Path.static Node
getOrCreateByPath(Node baseNode, String path, boolean createUniqueLeaf, String intermediateNodeType, String nodeType, boolean autoSave)
Creates or gets thenode
at the given path relative to the baseNode.static Node
getOrCreateUniqueByPath(String pathHint, String nodeType, Session session)
Creates aNode
at the given Path.static Node
getOrCreateUniqueByPath(Node parent, String nodeNameHint, String nodeType)
Creates or gets thenode
at the given path.static Iterable<Property>
getProperties(Node node)
Returns anIterable
over the properties of the given node.static Iterable<Property>
getProperties(Node node, String pattern)
Returns anIterable
over those properties of the given node that match the given name pattern.static Iterable<Property>
getProperties(Node node, String[] globs)
Returns anIterable
over those properties of the given node that match the given name patterns.static int
getPropertyType(String name)
Returns the numeric constant value of the property type with the specified name.static String[]
getPropertyTypeNames(boolean includeUndefined)
Return the property type names including or excluding 'undefined' depending on the specified flag.static Iterable<Property>
getReferences(Node node)
Returns anIterable
over references to the given node.static Iterable<Property>
getReferences(Node node, String name)
Returns anIterable
over those references to the given node that have the given name.static Repository
getRepository()
Returns the default repository of the current environment.static Repository
getRepository(String uri)
Returns the repository identified by the given URI.static Repository
getRepository(Map<String,String> parameters)
Looks up the availablerepository factories
and returns therepository
that one of the factories returns for the given settings.static Iterable<Row>
getRows(QueryResult result)
Returns anIterable
over nodes in the given query result.static Iterable<Node>
getSharedSet(Node node)
Returns anIterable
over the shared set of the given node.static String
getStringProperty(Node baseNode, String relPath, String defaultValue)
Returns the string property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.static String
getStringProperty(Session session, String absPath, String defaultValue)
Returns the string property value atabsPath
ordefaultValue
if no such property exists.static Iterable<Property>
getWeakReferences(Node node)
Returns anIterable
over weak references to the given node.static Iterable<Property>
getWeakReferences(Node node, String name)
Returns anIterable
over those weak references to the given node that have the given name.static <I> Iterable<I>
in(Iterator<I> iterator)
static Iterable<Node>
in(NodeIterator iterator)
Transform anNodeIterator
into anIterable
for single use in a Java 5 for-each loop.static Iterable<NodeType>
in(NodeTypeIterator iterator)
Transform anNodeTypeIterator
into anIterable
for single use in a Java 5 for-each loop.static Iterable<Event>
in(EventIterator iterator)
Transform anEventIterator
into anIterable
for single use in a Java 5 for-each loop.static Iterable<EventListener>
in(EventListenerIterator iterator)
Transform anEventListenerIterator
into anIterable
for single use in a Java 5 for-each loop.static Iterable<Property>
in(PropertyIterator iterator)
Transform anPropertyIterator
into anIterable
for single use in a Java 5 for-each loop.static Iterable<Row>
in(RowIterator iterator)
Transform anRowIterator
into anIterable
for single use in a Java 5 for-each loop.static Iterable<AccessControlPolicyIterator>
in(AccessControlPolicyIterator iterator)
Transform anAccessControlPolicyIterator
into anIterable
for single use in a Java 5 for-each loop.static Iterable<Version>
in(VersionIterator iterator)
Transform anVersionIterator
into anIterable
for single use in a Java 5 for-each loop.static Node
putFile(Node parent, String name, String mime, InputStream data)
Creates or updates the named child of the given node.static Node
putFile(Node parent, String name, String mime, InputStream data, Calendar date)
Creates or updates the named child of the given node.static InputStream
readFile(Node node)
Returns a stream for reading the contents of the file stored at the given node.static void
readFile(Node node, OutputStream output)
Writes the contents of file stored at the given node to the given stream.static void
setLastModified(Node node, Calendar date)
Sets the last modified date of the given file node.static String
toString(Item item)
Returns a string representation of the given item.
-
-
-
Field Detail
-
REPOSITORY_URI
public static final String REPOSITORY_URI
The repository URI parameter name used by thegetRepository(String)
method. AllRepositoryFactory
implementations that want to support this repository access convention should implement processing of this parameter.Client applications are recommended to use the
getRepository(String)
method instead of directly referencing this constant unless they explicitly want to pass also otherRepositoryFactory
parameters through thegetRepository(Map)
method.- See Also:
- Constant Field Values
-
NO_VALUES
public static final Value[] NO_VALUES
A pre-allocated empty array of values.- Since:
- Apache Jackrabbit 2.3
-
-
Method Detail
-
getRepository
public static Repository getRepository() throws RepositoryException
Returns the default repository of the current environment. Implemented by callinggetRepository(Map)
with anull
parameter map.- Returns:
- default repository
- Throws:
RepositoryException
- if a default repository is not available or can not be accessed- See Also:
RepositoryFactory.getRepository(Map)
-
getRepository
public static Repository getRepository(Map<String,String> parameters) throws RepositoryException
Looks up the availablerepository factories
and returns therepository
that one of the factories returns for the given settings.Note that unlike
RepositoryFactory.getRepository(Map)
this method will throw an exception instead of returningnull
if the given parameters can not be interpreted.- Parameters:
parameters
- repository settings- Returns:
- repository reference
- Throws:
RepositoryException
- if the repository can not be accessed, or if an appropriate repository factory is not available
-
getRepository
public static Repository getRepository(String uri) throws RepositoryException
Returns the repository identified by the given URI. This feature is implemented by calling thegetRepository(Map)
method with theREPOSITORY_URI
parameter set to the given URI. Any query parameters are moved from the URI to the parameter map.See the documentation of the repository implementation you want to use for whether it supports this repository URI convention and for what the repository URI should look like. For example, Jackrabbit 2.0 supports the following types of repository URIs:
- http(s)://...
- A remote repository connection using SPI2DAVex with the given URL. See the jackrabbit-jcr2dav component for more details.
- file://...
- An embedded Jackrabbit repository located in the given directory. See the jackrabbit-core component for more details.
- jndi:...
-
JNDI lookup for the named repository. See the
JndiRepositoryFactory
class for more details.
- Parameters:
uri
- repository URI- Returns:
- repository instance
- Throws:
RepositoryException
- if the repository can not be accessed, or if the given URI is unknown or invalid
-
getSharedSet
public static Iterable<Node> getSharedSet(Node node) throws RepositoryException
Returns anIterable
over the shared set of the given node.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
node
- shared node- Returns:
- nodes in the shared set
- Throws:
RepositoryException
- if theNode.getSharedSet()
call fails- See Also:
Node.getSharedSet()
-
getChildNodes
public static Iterable<Node> getChildNodes(Node node) throws RepositoryException
Returns anIterable
over the children of the given node.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
node
- parent node- Returns:
- child nodes
- Throws:
RepositoryException
- if theNode.getNodes()
call fails- See Also:
Node.getNodes()
-
getChildNodes
public static Iterable<Node> getChildNodes(Node node, String pattern) throws RepositoryException
Returns anIterable
over those children of the given node that match the given name pattern.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
node
- parent nodepattern
- node name pattern- Returns:
- matching child nodes
- Throws:
RepositoryException
- if theNode.getNodes(String)
call fails- See Also:
Node.getNodes(String)
-
getChildNodes
public static Iterable<Node> getChildNodes(Node node, String[] globs) throws RepositoryException
Returns anIterable
over those children of the given node that match the given name patterns.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
node
- parent nodeglobs
- node name pattern- Returns:
- matching child nodes
- Throws:
RepositoryException
- if theNode.getNodes(String[])
call fails- See Also:
Node.getNodes(String[])
-
getProperties
public static Iterable<Property> getProperties(Node node) throws RepositoryException
Returns anIterable
over the properties of the given node.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
node
- node- Returns:
- properties of the node
- Throws:
RepositoryException
- if theNode.getProperties()
call fails- See Also:
Node.getProperties()
-
getProperties
public static Iterable<Property> getProperties(Node node, String pattern) throws RepositoryException
Returns anIterable
over those properties of the given node that match the given name pattern.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
node
- nodepattern
- property name pattern- Returns:
- matching properties of the node
- Throws:
RepositoryException
- if theNode.getProperties(String)
call fails- See Also:
Node.getProperties(String)
-
getProperties
public static Iterable<Property> getProperties(Node node, String[] globs) throws RepositoryException
Returns anIterable
over those properties of the given node that match the given name patterns.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
node
- nodeglobs
- property name globs- Returns:
- matching properties of the node
- Throws:
RepositoryException
- if theNode.getProperties(String[])
call fails- See Also:
Node.getProperties(String[])
-
getReferences
public static Iterable<Property> getReferences(Node node) throws RepositoryException
Returns anIterable
over references to the given node.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
node
- reference target- Returns:
- references that point to the given node
- Throws:
RepositoryException
- if theNode.getReferences()
call fails- See Also:
Node.getReferences()
-
getReferences
public static Iterable<Property> getReferences(Node node, String name) throws RepositoryException
Returns anIterable
over those references to the given node that have the given name.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
node
- reference targetname
- reference property name- Returns:
- references with the given name that point to the given node
- Throws:
RepositoryException
- if theNode.getReferences(String)
call fails- See Also:
Node.getReferences(String)
-
getWeakReferences
public static Iterable<Property> getWeakReferences(Node node) throws RepositoryException
Returns anIterable
over weak references to the given node.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
node
- reference target- Returns:
- weak references that point to the given node
- Throws:
RepositoryException
- if theNode.getWeakReferences()
call fails- See Also:
Node.getWeakReferences()
-
getWeakReferences
public static Iterable<Property> getWeakReferences(Node node, String name) throws RepositoryException
Returns anIterable
over those weak references to the given node that have the given name.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
node
- reference targetname
- reference property name- Returns:
- weak references with the given name that point to the given node
- Throws:
RepositoryException
- if theNode.getWeakReferences(String)
call fails- See Also:
Node.getWeakReferences(String)
-
getNodes
public static Iterable<Node> getNodes(QueryResult result) throws RepositoryException
Returns anIterable
over nodes in the given query result.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
result
- query result- Returns:
- nodes in the query result
- Throws:
RepositoryException
- if theQueryResult.getNodes()
call fails- See Also:
QueryResult.getNodes()
-
getRows
public static Iterable<Row> getRows(QueryResult result) throws RepositoryException
Returns anIterable
over nodes in the given query result.The first iterator is acquired directly during this method call to allow a possible
RepositoryException
to be thrown as-is. Further iterators are acquired lazily when needed, with possibleRepositoryException
s wrapped intoRuntimeException
s.- Parameters:
result
- query result- Returns:
- rows in the query result
- Throws:
RepositoryException
- if theQueryResult.getRows()
call fails- See Also:
QueryResult.getRows()
-
in
public static <I> Iterable<I> in(Iterator<I> iterator)
Transform any type ofIterator
into anIterable
for single use in a Java 5 for-each loop.While general purpose
Iterables
tend to be reusable, this wrapperIterable
consumes the argumentIterator
, leaving it in a non-reusable state. The returnedIterable
will throw anIllegalStateException
if itsiterator()
method is invoked a second time.- Type Parameters:
I
- type- Parameters:
iterator
- The inputIterator
- Returns:
- The wrapping
Iterable
-
in
public static Iterable<AccessControlPolicyIterator> in(AccessControlPolicyIterator iterator)
Transform anAccessControlPolicyIterator
into anIterable
for single use in a Java 5 for-each loop.While general purpose
Iterables
tend to be reusable, this wrapperIterable
consumes the argumentIterator
, leaving it in a non-reusable state. The returnedIterable
will throw anIllegalStateException
if itsiterator()
method is invoked a second time.- Parameters:
iterator
- The inputIterator
- Returns:
- The wrapping
Iterable
-
in
public static Iterable<Event> in(EventIterator iterator)
Transform anEventIterator
into anIterable
for single use in a Java 5 for-each loop.While general purpose
Iterables
tend to be reusable, this wrapperIterable
consumes the argumentIterator
, leaving it in a non-reusable state. The returnedIterable
will throw anIllegalStateException
if itsiterator()
method is invoked a second time.- Parameters:
iterator
- The inputIterator
- Returns:
- The wrapping
Iterable
-
in
public static Iterable<EventListener> in(EventListenerIterator iterator)
Transform anEventListenerIterator
into anIterable
for single use in a Java 5 for-each loop.While general purpose
Iterables
tend to be reusable, this wrapperIterable
consumes the argumentIterator
, leaving it in a non-reusable state. The returnedIterable
will throw anIllegalStateException
if itsiterator()
method is invoked a second time.- Parameters:
iterator
- The inputIterator
- Returns:
- The wrapping
Iterable
-
in
public static Iterable<Node> in(NodeIterator iterator)
Transform anNodeIterator
into anIterable
for single use in a Java 5 for-each loop.While general purpose
Iterables
tend to be reusable, this wrapperIterable
consumes the argumentIterator
, leaving it in a non-reusable state. The returnedIterable
will throw anIllegalStateException
if itsiterator()
method is invoked a second time.- Parameters:
iterator
- The inputIterator
- Returns:
- The wrapping
Iterable
-
in
public static Iterable<NodeType> in(NodeTypeIterator iterator)
Transform anNodeTypeIterator
into anIterable
for single use in a Java 5 for-each loop.While general purpose
Iterables
tend to be reusable, this wrapperIterable
consumes the argumentIterator
, leaving it in a non-reusable state. The returnedIterable
will throw anIllegalStateException
if itsiterator()
method is invoked a second time.- Parameters:
iterator
- The inputIterator
- Returns:
- The wrapping
Iterable
-
in
public static Iterable<Property> in(PropertyIterator iterator)
Transform anPropertyIterator
into anIterable
for single use in a Java 5 for-each loop.While general purpose
Iterables
tend to be reusable, this wrapperIterable
consumes the argumentIterator
, leaving it in a non-reusable state. The returnedIterable
will throw anIllegalStateException
if itsiterator()
method is invoked a second time.- Parameters:
iterator
- The inputIterator
- Returns:
- The wrapping
Iterable
-
in
public static Iterable<Row> in(RowIterator iterator)
Transform anRowIterator
into anIterable
for single use in a Java 5 for-each loop.While general purpose
Iterables
tend to be reusable, this wrapperIterable
consumes the argumentIterator
, leaving it in a non-reusable state. The returnedIterable
will throw anIllegalStateException
if itsiterator()
method is invoked a second time.- Parameters:
iterator
- The inputIterator
- Returns:
- The wrapping
Iterable
-
in
public static Iterable<Version> in(VersionIterator iterator)
Transform anVersionIterator
into anIterable
for single use in a Java 5 for-each loop.While general purpose
Iterables
tend to be reusable, this wrapperIterable
consumes the argumentIterator
, leaving it in a non-reusable state. The returnedIterable
will throw anIllegalStateException
if itsiterator()
method is invoked a second time.- Parameters:
iterator
- The inputIterator
- Returns:
- The wrapping
Iterable
-
getOrAddNode
public static Node getOrAddNode(Node parent, String name) throws RepositoryException
Returns the named child of the given node, creating the child if it does not already exist. If the child node gets added, then its type will be determined by the child node definitions associated with the parent node. The caller is expected to take care of saving or discarding any transient changes.- Parameters:
parent
- parent nodename
- name of the child node- Returns:
- the child node
- Throws:
RepositoryException
- if the child node can not be accessed or created- See Also:
Node.getNode(String)
,Node.addNode(String)
-
getOrAddNode
public static Node getOrAddNode(Node parent, String name, String type) throws RepositoryException
Returns the named child of the given node, creating the child if it does not already exist. If the child node gets added, then it is created with the given node type. The caller is expected to take care of saving or discarding any transient changes.- Parameters:
parent
- parent nodename
- name of the child nodetype
- type of the child node ornull
, ignored if the child already exists- Returns:
- the child node
- Throws:
RepositoryException
- if the child node can not be accessed or created- See Also:
Node.getNode(String)
,Node.addNode(String, String)
,Node.isNodeType(String)
-
getOrAddFolder
public static Node getOrAddFolder(Node parent, String name) throws RepositoryException
Returns the named child of the given node, creating it as an nt:folder node if it does not already exist. The caller is expected to take care of saving or discarding any transient changes.Note that the type of the returned node is not guaranteed to match nt:folder in case the node already existed. The caller can use an explicit
Node.isNodeType(String)
check if needed, or simply use a data-first approach and not worry about the node type until a constraint violation is encountered.- Parameters:
parent
- parent nodename
- name of the child node- Returns:
- the child node
- Throws:
RepositoryException
- if the child node can not be accessed or created
-
putFile
public static Node putFile(Node parent, String name, String mime, InputStream data) throws RepositoryException
Creates or updates the named child of the given node. If the child does not already exist, then it is created using the nt:file node type. This file child node is returned from this method.If the file node does not already contain a jcr:content child, then one is created using the nt:resource node type. The following properties are set on the jcr:content node:
- jcr:mimeType
- media type
- jcr:encoding (optional)
- charset parameter of the media type, if any
- jcr:lastModified
- current time
- jcr:data
- binary content
Note that the types of the returned node or the jcr:content child are not guaranteed to match nt:file and nt:resource in case the nodes already existed. The caller can use an explicit
Node.isNodeType(String)
check if needed, or simply use a data-first approach and not worry about the node type until a constraint violation is encountered.The given binary content stream is closed by this method.
- Parameters:
parent
- parent nodename
- name of the filemime
- media type of the filedata
- binary content of the file- Returns:
- the child node
- Throws:
RepositoryException
- if the child node can not be created or updated
-
putFile
public static Node putFile(Node parent, String name, String mime, InputStream data, Calendar date) throws RepositoryException
Creates or updates the named child of the given node. If the child does not already exist, then it is created using the nt:file node type. This file child node is returned from this method.If the file node does not already contain a jcr:content child, then one is created using the nt:resource node type. The following properties are set on the jcr:content node:
- jcr:mimeType
- media type
- jcr:encoding (optional)
- charset parameter of the media type, if any
- jcr:lastModified
- date of last modification
- jcr:data
- binary content
Note that the types of the returned node or the jcr:content child are not guaranteed to match nt:file and nt:resource in case the nodes already existed. The caller can use an explicit
Node.isNodeType(String)
check if needed, or simply use a data-first approach and not worry about the node type until a constraint violation is encountered.The given binary content stream is closed by this method.
- Parameters:
parent
- parent nodename
- name of the filemime
- media type of the filedata
- binary content of the filedate
- date of last modification- Returns:
- the child node
- Throws:
RepositoryException
- if the child node can not be created or updated
-
readFile
public static InputStream readFile(Node node) throws RepositoryException
Returns a stream for reading the contents of the file stored at the given node. This method works with both on nt:file and nt:resource and on any other similar node types, as it only looks for the jcr:data property or a jcr:content child node.The returned stream contains a reference to the underlying
Binary
value instance that will be disposed when the stream is closed. It is the responsibility of the caller to close the stream once it is no longer needed.- Parameters:
node
- node to be read- Returns:
- stream for reading the file contents
- Throws:
RepositoryException
- if the file can not be accessed- Since:
- Apache Jackrabbit 2.3
-
readFile
public static void readFile(Node node, OutputStream output) throws RepositoryException, IOException
Writes the contents of file stored at the given node to the given stream. Similar file handling logic is used as in thereadFile(Node)
method.- Parameters:
node
- node to be readoutput
- to which the file contents are written- Throws:
RepositoryException
- if the file can not be accessedIOException
- if the file can not be read or written- Since:
- Apache Jackrabbit 2.3
-
getLastModified
public static Calendar getLastModified(Node node) throws RepositoryException
Returns the last modified date of the given file node. The value is read from the jcr:lastModified property of this node or alternatively from a jcr:content child node.- Parameters:
node
- file node- Returns:
- last modified date, or
null
if not available - Throws:
RepositoryException
- if the last modified date can not be accessed- Since:
- Apache Jackrabbit 2.3
-
setLastModified
public static void setLastModified(Node node, Calendar date) throws RepositoryException
Sets the last modified date of the given file node. The value is written to the jcr:lastModified property of a jcr:content child node or this node if such a child does not exist.- Parameters:
node
- file nodedate
- modified date- Throws:
RepositoryException
- if the last modified date can not be set- Since:
- Apache Jackrabbit 2.3
-
toString
public static String toString(Item item)
Returns a string representation of the given item. The returned string is designed to be easily readable while providing maximum amount of information for logging and debugging purposes.The returned string is not meant to be parsed and the exact contents can change in future releases. The current string representation of a node is "/path/to/node [type]" and the representation of a property is "@name = value(s)". Binary values are expressed like "<123 bytes>" and other values as their standard binary representation. Multi-valued properties have their values listed in like "[ v1, v2, v3, ... ]". No more than the three first values are included. Long string values are truncated.
- Parameters:
item
- given node or property- Returns:
- string representation of the given item
-
getPropertyType
public static int getPropertyType(String name) throws IllegalArgumentException
Returns the numeric constant value of the property type with the specified name. This method is likePropertyType.valueFromName(String)
, but the name lookup is case insensitive.- Parameters:
name
- name of the property type (case insensitive)- Returns:
- property type constant
- Throws:
IllegalArgumentException
- if the given name is not a valid property type name- Since:
- Apache Jackrabbit 2.3
-
getPropertyTypeNames
public static String[] getPropertyTypeNames(boolean includeUndefined)
Return the property type names including or excluding 'undefined' depending on the specified flag.- Parameters:
includeUndefined
- If true the returned array will contain the name of the 'undefined' property type.- Returns:
- array of property type names.
-
getOrCreateByPath
public static Node getOrCreateByPath(String absolutePath, String nodeType, Session session) throws RepositoryException
Creates or gets theNode
at the given Path. In case it has to create the Node all non-existent intermediate path-elements will be created with the given NodeType.Changes made are not saved by this method, so
session.save()
has to be called to persist them.- Parameters:
absolutePath
- absolute path to createnodeType
- to use for creation of nodes Ifnull
the node type is determined by the child node definitions of the parent node.session
- to use- Returns:
- the Node at path
- Throws:
RepositoryException
- in case of exception accessing the Repository
-
getOrCreateByPath
public static Node getOrCreateByPath(String absolutePath, String intermediateNodeType, String nodeType, Session session, boolean autoSave) throws RepositoryException
Creates or gets theNode
at the given Path. In case it has to create the Node all non-existent intermediate path-elements will be created with the given intermediate node type and the returned node will be created with the given nodeType.- Parameters:
absolutePath
- absolute path to createintermediateNodeType
- to use for creation of intermediate nodes. Ifnull
the node type is determined by the child node definitions of the parent node.nodeType
- to use for creation of the final node. Ifnull
the node type is determined by the child node definitions of the parent node.session
- to useautoSave
- Should save be called when a new node is created?- Returns:
- the Node at absolutePath
- Throws:
RepositoryException
- in case of exception accessing the Repository
-
getOrCreateUniqueByPath
public static Node getOrCreateUniqueByPath(String pathHint, String nodeType, Session session) throws RepositoryException
Creates aNode
at the given Path. In case it has to create the Node all non-existent intermediate path-elements will be created with the given intermediate node type and the returned node will be created with the given nodeType.If the path points to an existing node, the leaf node name will be regarded as a name hint and a unique node name will be created by appending a number to the given name (eg.
/some/path/foobar2
). Please note that the uniqueness check is not an atomic JCR operation, so it is possible that you get aRepositoryException
(path already exists) if another concurrent session created the same node in the meantime.Changes made are not saved by this method, so
session.save()
has to be called to persist them.- Parameters:
pathHint
- path to createnodeType
- to use for creation of nodes. . Ifnull
the node type is determined by the child node definitions of the parent node.session
- to use- Returns:
- the newly created Node
- Throws:
RepositoryException
- in case of exception accessing the Repository
-
getOrCreateByPath
public static Node getOrCreateByPath(String absolutePath, boolean createUniqueLeaf, String intermediateNodeType, String nodeType, Session session, boolean autoSave) throws RepositoryException
Creates or gets theNode
at the given Path. In case it has to create the Node all non-existent intermediate path-elements will be created with the given intermediate node type and the returned node will be created with the given nodeType.If the parameter
createUniqueLeaf
is set, it will not get an existing node but rather try to create a unique node by appending a number to the last path element (leaf node). Please note that the uniqueness check is not an atomic JCR operation, so it is possible that you get aRepositoryException
(path already exists) if another concurrent session created the same node in the meantime.- Parameters:
absolutePath
- absolute path to createcreateUniqueLeaf
- whether the leaf of the path should be regarded as a name hint and a unique node name should be created by appending a number to the given name (eg./some/path/foobar2
)intermediateNodeType
- to use for creation of intermediate nodes. Ifnull
the node type is determined by the child node definitions of the parent node.nodeType
- to use for creation of the final node. Ifnull
the node type is determined by the child node definitions of the parent node.session
- to useautoSave
- Should save be called when a new node is created?- Returns:
- the Node at absolutePath
- Throws:
RepositoryException
- in case of exception accessing the Repository
-
getOrCreateUniqueByPath
public static Node getOrCreateUniqueByPath(Node parent, String nodeNameHint, String nodeType) throws RepositoryException
Creates or gets thenode
at the given path. In case it has to create the node, nodes for all non-existent intermediate path-elements will be created with the given intermediate node type and the returned node will be created with the given nodeType. Note: When the given path contains parent elements this method might create multiple nodes at leaf position (e.g "a/../b" will create the child nodes "a" and "b" on the current node).If the node name points to an existing node, the node name will be regarded as a name hint and a unique node name will be created by appending a number to the given name (eg.
/some/path/foobar2
). Please note that the uniqueness check is not an atomic JCR operation, so it is possible that you get aRepositoryException
(path already exists) if another concurrent session created the same node in the meantime.Changes made are not saved by this method, so
session.save()
has to be called to persist them.- Parameters:
parent
- existing parent node for the new nodenodeNameHint
- name hint for the new nodenodeType
- to use for creation of the node. Ifnull
the node type is determined by the child node definitions of the parent node.- Returns:
- the newly created Node
- Throws:
RepositoryException
- in case of exception accessing the Repository
-
getOrCreateByPath
public static Node getOrCreateByPath(Node baseNode, String path, boolean createUniqueLeaf, String intermediateNodeType, String nodeType, boolean autoSave) throws RepositoryException
Creates or gets thenode
at the given path relative to the baseNode. In case it has to create the node, nodes for all non-existent intermediate path-elements will be created with the given intermediate node type and the returned node will be created with the given nodeType. Note: When the given path contains parent elements this method might create multiple nodes at leaf position (e.g "a/../b" will create the child nodes "a" and "b" on the current node).If the parameter
createUniqueLeaf
is set, it will not get an existing node but rather try to create a unique node by appending a number to the last path element (leaf node). Please note that the uniqueness check is not an atomic JCR operation, so it is possible that you get aRepositoryException
(path already exists) if another concurrent session created the same node in the meantime.- Parameters:
baseNode
- existing node that should be the base for the relative pathpath
- relative path to createcreateUniqueLeaf
- whether the leaf of the path should be regarded as a name hint and a unique node name should be created by appending a number to the given name (eg./some/path/foobar2
)intermediateNodeType
- to use for creation of intermediate nodes. Ifnull
the node type is determined by the child node definitions of the parent node.nodeType
- to use for creation of the final node. Ifnull
the node type is determined by the child node definitions of the parent node.autoSave
- Should save be called when a new node is created?- Returns:
- the Node at path
- Throws:
RepositoryException
- in case of exception accessing the Repository
-
getNodeIfExists
public static Node getNodeIfExists(Node baseNode, String relPath) throws RepositoryException
Get the node atrelPath
frombaseNode
ornull
if no such node exists.- Parameters:
baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the node to get- Returns:
- the node at
relPath
frombaseNode
ornull
if no such node exists. - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getNodeIfExists
public static Node getNodeIfExists(String absPath, Session session) throws RepositoryException
Gets the node atabsPath
ornull
if no such node exists.- Parameters:
absPath
- the absolute path to the node to returnsession
- to use- Returns:
- the node at
absPath
ornull
if no such node exists. - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getStringProperty
public static String getStringProperty(Node baseNode, String relPath, String defaultValue) throws RepositoryException
Returns the string property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the string property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getLongProperty
public static long getLongProperty(Node baseNode, String relPath, long defaultValue) throws RepositoryException
Returns the long property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the long property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getDoubleProperty
public static double getDoubleProperty(Node baseNode, String relPath, double defaultValue) throws RepositoryException
Returns the double property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the double property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getBooleanProperty
public static boolean getBooleanProperty(Node baseNode, String relPath, boolean defaultValue) throws RepositoryException
Returns the boolean property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the boolean property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getDateProperty
public static Calendar getDateProperty(Node baseNode, String relPath, Calendar defaultValue) throws RepositoryException
Returns the date property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the date property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getDecimalProperty
public static BigDecimal getDecimalProperty(Node baseNode, String relPath, BigDecimal defaultValue) throws RepositoryException
Returns the decimal property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the decimal property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getBinaryProperty
public static Binary getBinaryProperty(Node baseNode, String relPath, Binary defaultValue) throws RepositoryException
Returns the binary property value atrelPath
frombaseNode
ordefaultValue
if no such property exists.- Parameters:
baseNode
- existing node that should be the base for the relative pathrelPath
- relative path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the binary property value at
relPath
frombaseNode
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getStringProperty
public static String getStringProperty(Session session, String absPath, String defaultValue) throws RepositoryException
Returns the string property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the string property value at
absPath
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getLongProperty
public static long getLongProperty(Session session, String absPath, long defaultValue) throws RepositoryException
Returns the long property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the long property value at
absPath
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getDoubleProperty
public static double getDoubleProperty(Session session, String absPath, double defaultValue) throws RepositoryException
Returns the double property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the double property value at
absPath
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getBooleanProperty
public static boolean getBooleanProperty(Session session, String absPath, boolean defaultValue) throws RepositoryException
Returns the boolean property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the boolean property value at
absPath
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getDateProperty
public static Calendar getDateProperty(Session session, String absPath, Calendar defaultValue) throws RepositoryException
Returns the date property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the date property value at
absPath
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getDecimalProperty
public static BigDecimal getDecimalProperty(Session session, String absPath, BigDecimal defaultValue) throws RepositoryException
Returns the decimal property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the decimal property value at
absPath
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
getBinaryProperty
public static Binary getBinaryProperty(Session session, String absPath, Binary defaultValue) throws RepositoryException
Returns the binary property value atabsPath
ordefaultValue
if no such property exists.- Parameters:
session
- to useabsPath
- absolute path to the property to getdefaultValue
- default value to return when the property does not exist- Returns:
- the binary property value at
absPath
ordefaultValue
if no such property exists - Throws:
RepositoryException
- in case of exception accessing the Repository
-
-