Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ModeShape Distribution 3.0.0.Beta3
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.modeshape.jcr.api
Class JcrTools

    java.lang.Object
      org.modeshape.jcr.api.JcrTools

    public class JcrTools

extends Object

Utility methods for working with JCR nodes.

Nested Class Summary
`static class` | `JcrTools.BasicOperation`
`static class` | `JcrTools.BrowseContent`
`static class` | `JcrTools.CountNodes`
`static interface` | `JcrTools.Operation`
`static class` | `JcrTools.PrintNodes`
`static class` | `JcrTools.Variable`

Constructor Summary
`JcrTools()`
`JcrTools(boolean debug)`

Method Summary
`Node` | `findOrCreateChild(Node parent, String name)` Get or create a node with the specified node under the specified parent node.
`Node` | `findOrCreateChild(Node parent, String name, String nodeType)` Get or create a node with the specified node and node type under the specified parent node.
`Node` | `findOrCreateNode(Node parentNode, String path, String defaultNodeType, String finalNodeType)` Get or create a node at the specified path.
`Node` | `findOrCreateNode(Session session, String path)` Get or create a node at the specified path.
`Node` | `findOrCreateNode(Session session, String path, String nodeType)` Get or create a node at the specified path and node type.
`Node` | `findOrCreateNode(Session session, String path, String defaultNodeType, String finalNodeType)` Get or create a node at the specified path.
`Node` | `getNode(Node node, String relativePath, boolean required)` Get the node under a specified node at a location defined by the specified relative path.
`String` | `getReadable(Node node)` Get the readable string form for a specified node.
`protected String` | `getStringValue(Value value, int type)`
`static void` | `importContent(Session session, Class<?> testClass, String pathToResourceFile)`
`static void` | `importContent(Session session, Class<?> testClass, String pathToResourceFile, String jcrPathToImportUnder)`
`static void` | `importContent(Session session, Class<?> testClass, String pathToResourceFile, String jcrPathToImportUnder, int importBehavior)`
`void` | `importContent(Session session, String pathToResourceFile)`
`void` | `importContent(Session session, String pathToResourceFile, int importBehavior)`
`void` | `importContent(Session session, String pathToResourceFile, String jcrPathToImportUnder)`
`void` | `importContent(Session session, String pathToResourceFile, String jcrPathToImportUnder, int importBehavior)`
`boolean` | `isDebug()`
`void` | `print(Object msg)`
`void` | `printNode(Node node)` Print this node and its properties to System.out if printing is enabled.
`QueryResult` | `printQuery(Session session, String jcrSql2)` Execute the supplied JCR-SQL2 query and, if printing is enabled, print out the results.
`QueryResult` | `printQuery(Session session, String jcrSql2, long expectedNumberOfResults, JcrTools.Variable... variables)` Execute the supplied JCR-SQL2 query and, if printing is enabled, print out the results.
`QueryResult` | `printQuery(Session session, String jcrSql2, long expectedNumberOfResults, Map<String,String> variables)` Execute the supplied JCR-SQL2 query and, if printing is enabled, print out the results.
`QueryResult` | `printQuery(Session session, String queryExpression, String queryLanguage, long expectedNumberOfResults, Map<String,String> variables)`
`void` | `printSubgraph(Node node)` Load the subgraph below this node, and print it to System.out if printing is enabled.
`void` | `printSubgraph(Node node, int maxDepth)` Load the subgraph below this node, and print it to System.out if printing is enabled.
`void` | `printSubgraph(Node node, String lead, int depthOfSubgraph, int maxDepthOfSubgraph)` Load the subgraph below this node, and print it to System.out if printing is enabled.
`void` | `registerNodeTypes(Session session, String pathToCndResourceFile)`
`int` | `removeAllChildren(Node node)` Remove all children from the specified node
`int` | `removeAllChildren(Session session, String absPath)`
`void` | `repeatedlyWithSession(Repository repository, int times, JcrTools.Operation operation)`
`protected URL` | `resourceUrl(String name)`
`Node` | `uploadFile(Session session, String path, File file)` Upload the content in the supplied file into the repository at the defined path, using the given session.
`Node` | `uploadFile(Session session, String path, InputStream stream)` Upload the content in the supplied stream into the repository at the defined path, using the given session.
`Node` | `uploadFile(Session session, String path, URL contentUrl)` Upload the content at the supplied URL into the repository at the defined path, using the given session.
`void` | `uploadFileAndBlock(Session session, String resourceFilePath, String parentPath)`
`void` | `uploadFileAndBlock(Session session, String folder, String fileName, String parentPath)`
`void` | `uploadFileAndBlock(Session session, URL url, String parentPath)`
`void` | `uploadFilesAndBlock(String destinationPath, String... resourcePaths)`
`JcrTools.Variable` | `var(String key, String value)`
`Map<String,String>` | `vars(String... keyValuePairs)`
`double` | `withSession(Repository repository, JcrTools.Operation operation)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### JcrTools

    public JcrTools()

### JcrTools

    public JcrTools(boolean debug)

Method Detail

### removeAllChildren

    public int removeAllChildren(Node node)
                          throws RepositoryException

  Remove all children from the specified node

  Parameters:
    `node` -
  Returns:
    the number of children removed.
  Throws:
    `RepositoryException`
    `IllegalArgumentException` - if the node argument is null

### removeAllChildren

    public int removeAllChildren(Session session,
                                 String absPath)
                          throws RepositoryException

  Throws:
    `RepositoryException`

### getNode

    public Node getNode(Node node,
                        String relativePath,
                        boolean required)
                 throws RepositoryException

  Get the node under a specified node at a location defined by the specified relative path. If node is required, then a problem is created and added to the Problems list.

  Parameters:
    `node` - a parent node from which to obtain a node relative to. may not be null
    `relativePath` - the path of the desired node. may not be null
    `required` - true if node is required to exist under the given node.
  Returns:
    the node located relative the the input node
  Throws:
    `RepositoryException`
    `IllegalArgumentException` - if the node, relativePath or problems argument is null

### getReadable

    public String getReadable(Node node)

  Get the readable string form for a specified node.

  Parameters:
    `node` - the node to obtain the readable string form. may be null
  Returns:
    the readable string form for a specified node.

### uploadFile

    public Node uploadFile(Session session,
                           String path,
                           InputStream stream)
                    throws RepositoryException,
                           IOException

  Upload the content in the supplied stream into the repository at the defined path, using the given session. This method will create a 'nt:file' node at the supplied path, and any non-existant ancestors with nodes of type 'nt:folder'. As defined by the JCR specification, the binary content (and other properties) will be placed on a child of the 'nt:file' node named 'jcr:content' with a node type of 'nt:resource'.

  This method always closes the supplied stream.

  Parameters:
    `session` - the JCR session
    `path` - the path to the file
    `stream` - the stream containing the content to be uploaded
  Returns:
    the newly created 'nt:file' node
  Throws:
    `RepositoryException` - if there is a problem uploading the file
    `IOException` - if there is a problem using the stream
    `IllegalArgumentException` - is any of the parameters are null

### uploadFile

    public Node uploadFile(Session session,
                           String path,
                           URL contentUrl)
                    throws RepositoryException,
                           IOException

  Upload the content at the supplied URL into the repository at the defined path, using the given session. This method will create a 'nt:file' node at the supplied path, and any non-existant ancestors with nodes of type 'nt:folder'. As defined by the JCR specification, the binary content (and other properties) will be placed on a child of the 'nt:file' node named 'jcr:content' with a node type of 'nt:resource'.

  Parameters:
    `session` - the JCR session
    `path` - the path to the file
    `contentUrl` - the URL where the content can be found
  Returns:
    the newly created 'nt:file' node
  Throws:
    `RepositoryException` - if there is a problem uploading the file
    `IOException` - if there is a problem using the stream
    `IllegalArgumentException` - is any of the parameters are null

### uploadFile

    public Node uploadFile(Session session,
                           String path,
                           File file)
                    throws RepositoryException,
                           IOException

  Upload the content in the supplied file into the repository at the defined path, using the given session. This method will create a 'nt:file' node at the supplied path, and any non-existant ancestors with nodes of type 'nt:folder'. As defined by the JCR specification, the binary content (and other properties) will be placed on a child of the 'nt:file' node named 'jcr:content' with a node type of 'nt:resource'.

  Parameters:
    `session` - the JCR session
    `path` - the path to the file
    `file` - the existing and readable file to be uploaded
  Returns:
    the newly created 'nt:file' node
  Throws:
    `RepositoryException` - if there is a problem uploading the file
    `IOException` - if there is a problem using the stream
    `IllegalArgumentException` - if the file does not exist or is not readable
    `IllegalArgumentException` - is any of the parameters are null

### uploadFileAndBlock

    public void uploadFileAndBlock(Session session,
                                   String resourceFilePath,
                                   String parentPath)
                            throws RepositoryException,
                                   IOException

  Throws:
    `RepositoryException`
    `IOException`

### uploadFileAndBlock

    public void uploadFileAndBlock(Session session,
                                   String folder,
                                   String fileName,
                                   String parentPath)
                            throws RepositoryException,
                                   IOException

  Throws:
    `RepositoryException`
    `IOException`

### uploadFileAndBlock

    public void uploadFileAndBlock(Session session,
                                   URL url,
                                   String parentPath)
                            throws RepositoryException,
                                   IOException

  Throws:
    `RepositoryException`
    `IOException`

### uploadFilesAndBlock

    public void uploadFilesAndBlock(String destinationPath,
                                    String... resourcePaths)
                             throws Exception

  Throws:
    `Exception`

### findOrCreateNode

    public Node findOrCreateNode(Session session,
                                 String path)
                          throws RepositoryException

  Get or create a node at the specified path.

  Parameters:
    `session` - the JCR session. may not be null
    `path` - the path of the desired node to be found or created. may not be null
  Returns:
    the existing or newly created node
  Throws:
    `RepositoryException`
    `IllegalArgumentException` - if either the session or path argument is null

### findOrCreateNode

    public Node findOrCreateNode(Session session,
                                 String path,
                                 String nodeType)
                          throws RepositoryException

  Get or create a node at the specified path and node type.

  Parameters:
    `session` - the JCR session. may not be null
    `path` - the path of the desired node to be found or created. may not be null
    `nodeType` - the node type. may be null
  Returns:
    the existing or newly created node
  Throws:
    `RepositoryException`
    `IllegalArgumentException` - if either the session or path argument is null

### findOrCreateNode

    public Node findOrCreateNode(Session session,
                                 String path,
                                 String defaultNodeType,
                                 String finalNodeType)
                          throws RepositoryException

  Get or create a node at the specified path.

  Parameters:
    `session` - the JCR session. may not be null
    `path` - the path of the desired node to be found or created. may not be null
    `defaultNodeType` - the default node type. may be null
    `finalNodeType` - the optional final node type. may be null
  Returns:
    the existing or newly created node
  Throws:
    `RepositoryException`
    `IllegalArgumentException` - if either the session or path argument is null

### findOrCreateNode

    public Node findOrCreateNode(Node parentNode,
                                 String path,
                                 String defaultNodeType,
                                 String finalNodeType)
                          throws RepositoryException

  Get or create a node at the specified path.

  Parameters:
    `parentNode` - the parent node. may not be null
    `path` - the path of the desired child node. may not be null
    `defaultNodeType` - the default node type. may be null
    `finalNodeType` - the optional final node type. may be null
  Returns:
    the existing or newly created node
  Throws:
    `RepositoryException`
    `IllegalArgumentException` - if either the parentNode or path argument is null

### findOrCreateChild

    public Node findOrCreateChild(Node parent,
                                  String name)
                           throws RepositoryException

  Get or create a node with the specified node under the specified parent node.

  Parameters:
    `parent` - the parent node. may not be null
    `name` - the name of the child node. may not be null
  Returns:
    the existing or newly created child node
  Throws:
    `RepositoryException`
    `IllegalArgumentException` - if either the parent or name argument is null

### findOrCreateChild

    public Node findOrCreateChild(Node parent,
                                  String name,
                                  String nodeType)
                           throws RepositoryException

  Get or create a node with the specified node and node type under the specified parent node.

  Parameters:
    `parent` - the parent node. may not be null
    `name` - the name of the child node. may not be null
    `nodeType` - the node type. may be null
  Returns:
    the existing or newly created child node
  Throws:
    `RepositoryException`

### isDebug

    public boolean isDebug()

### print

    public void print(Object msg)

### printSubgraph

    public void printSubgraph(Node node)
                       throws RepositoryException

  Load the subgraph below this node, and print it to System.out if printing is enabled.

  Parameters:
    `node` - the root of the subgraph
  Throws:
    `RepositoryException`

### printSubgraph

    public void printSubgraph(Node node,
                              int maxDepth)
                       throws RepositoryException

  Load the subgraph below this node, and print it to System.out if printing is enabled.

  Parameters:
    `node` - the root of the subgraph
    `maxDepth` - the maximum depth of the subgraph that should be printed
  Throws:
    `RepositoryException`

### printNode

    public void printNode(Node node)
                   throws RepositoryException

  Print this node and its properties to System.out if printing is enabled.

  Parameters:
    `node` - the node to be printed
  Throws:
    `RepositoryException`

### printSubgraph

    public void printSubgraph(Node node,
                              String lead,
                              int depthOfSubgraph,
                              int maxDepthOfSubgraph)
                       throws RepositoryException

  Load the subgraph below this node, and print it to System.out if printing is enabled.

  Parameters:
    `node` - the root of the subgraph
    `lead` - the string that each line should begin with; may be null if there is no such string
    `depthOfSubgraph` - the depth of this subgraph's root node
    `maxDepthOfSubgraph` - the maximum depth of the subgraph that should be printed
  Throws:
    `RepositoryException`

### printQuery

    public QueryResult printQuery(Session session,
                                  String jcrSql2)
                           throws RepositoryException

  Execute the supplied JCR-SQL2 query and, if printing is enabled, print out the results.

  Parameters:
    `session` - the session
    `jcrSql2` - the JCR-SQL2 query
  Returns:
    the results
  Throws:
    `RepositoryException`

### printQuery

    public QueryResult printQuery(Session session,
                                  String jcrSql2,
                                  long expectedNumberOfResults,
                                  JcrTools.Variable... variables)
                           throws RepositoryException

  Execute the supplied JCR-SQL2 query and, if printing is enabled, print out the results.

  Parameters:
    `session` - the session
    `jcrSql2` - the JCR-SQL2 query
    `expectedNumberOfResults` - the expected number of rows in the results, or -1 if this is not to be checked
    `variables` - the variables for the query
  Returns:
    the results
  Throws:
    `RepositoryException`

### printQuery

    public QueryResult printQuery(Session session,
                                  String jcrSql2,
                                  long expectedNumberOfResults,
                                  Map<String,String> variables)
                           throws RepositoryException

  Execute the supplied JCR-SQL2 query and, if printing is enabled, print out the results.

  Parameters:
    `session` - the session
    `jcrSql2` - the JCR-SQL2 query
    `expectedNumberOfResults` - the expected number of rows in the results, or -1 if this is not to be checked
    `variables` - the array of variable maps for the query; all maps will be combined into a single map
  Returns:
    the results
  Throws:
    `RepositoryException`

### printQuery

    public QueryResult printQuery(Session session,
                                  String queryExpression,
                                  String queryLanguage,
                                  long expectedNumberOfResults,
                                  Map<String,String> variables)
                           throws RepositoryException

  Throws:
    `RepositoryException`

### var

    public JcrTools.Variable var(String key,
                                 String value)

### vars

    public Map<String,String> vars(String... keyValuePairs)

### getStringValue

    protected String getStringValue(Value value,
                                    int type)
                             throws RepositoryException

  Throws:
    `RepositoryException`

### registerNodeTypes

    public void registerNodeTypes(Session session,
                                  String pathToCndResourceFile)

### importContent

    public void importContent(Session session,
                              String pathToResourceFile)
                       throws Exception

  Throws:
    `Exception`

### importContent

    public void importContent(Session session,
                              String pathToResourceFile,
                              int importBehavior)
                       throws Exception

  Throws:
    `Exception`

### importContent

    public void importContent(Session session,
                              String pathToResourceFile,
                              String jcrPathToImportUnder)
                       throws Exception

  Throws:
    `Exception`

### importContent

    public void importContent(Session session,
                              String pathToResourceFile,
                              String jcrPathToImportUnder,
                              int importBehavior)
                       throws Exception

  Throws:
    `Exception`

### importContent

    public static void importContent(Session session,
                                     Class<?> testClass,
                                     String pathToResourceFile)
                              throws Exception

  Throws:
    `Exception`

### importContent

    public static void importContent(Session session,
                                     Class<?> testClass,
                                     String pathToResourceFile,
                                     String jcrPathToImportUnder)
                              throws Exception

  Throws:
    `Exception`

### importContent

    public static void importContent(Session session,
                                     Class<?> testClass,
                                     String pathToResourceFile,
                                     String jcrPathToImportUnder,
                                     int importBehavior)
                              throws Exception

  Throws:
    `Exception`

### resourceUrl

    protected URL resourceUrl(String name)

### repeatedlyWithSession

    public void repeatedlyWithSession(Repository repository,
                                      int times,
                                      JcrTools.Operation operation)
                               throws Exception

  Throws:
    `Exception`

### withSession

    public double withSession(Repository repository,
                              JcrTools.Operation operation)
                       throws Exception

  Throws:
    `Exception`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ModeShape Distribution 3.0.0.Beta3
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2008-2012 JBoss, a division of Red Hat. All Rights Reserved.