|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.modeshape.jcr.JcrTools
public class JcrTools
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 | |
---|---|
void |
browseTo(Repository repository,
String path)
|
String |
detectMimeType(Session session,
File file,
boolean useContent)
Detect the MIME type for the named filename. |
String |
detectMimeType(Session session,
String fileName)
Detect the MIME type for the named filename. |
String |
detectMimeType(Session session,
URL url,
boolean useContent)
Detect the MIME type for the named filename. |
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()
|
MimeTypeDetector |
mimeTypeDetector(Session session)
|
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 |
---|
public JcrTools()
public JcrTools(boolean debug)
Method Detail |
---|
public int removeAllChildren(Node node) throws RepositoryException
node
-
RepositoryException
IllegalArgumentException
- if the node argument is nullpublic int removeAllChildren(Session session, String absPath) throws RepositoryException
RepositoryException
public Node getNode(Node node, String relativePath, boolean required) throws RepositoryException
node
- a parent node from which to obtain a node relative to. may not be nullrelativePath
- the path of the desired node. may not be nullrequired
- true if node is required to exist under the given node.
RepositoryException
IllegalArgumentException
- if the node, relativePath or problems argument is nullpublic String getReadable(Node node)
node
- the node to obtain the readable string form. may be null
public MimeTypeDetector mimeTypeDetector(Session session)
public String detectMimeType(Session session, String fileName)
session
- the JCR sessionfileName
- the file name
public String detectMimeType(Session session, File file, boolean useContent) throws IOException
session
- the JCR sessionfile
- the fileuseContent
- true if the content of the file at the URL should also be used to determine the MIME type, or false if
only the URL itself should be used
IOException
- if there is an error reading the filepublic String detectMimeType(Session session, URL url, boolean useContent) throws IOException
session
- the JCR sessionurl
- the URLuseContent
- true if the content of the file at the URL should also be used to determine the MIME type, or false if
only the URL itself should be used
IOException
- if there is an error reading the filepublic Node uploadFile(Session session, String path, InputStream stream) throws RepositoryException, IOException
This method always closes the supplied stream.
session
- the JCR sessionpath
- the path to the filestream
- the stream containing the content to be uploaded
RepositoryException
- if there is a problem uploading the file
IOException
- if there is a problem using the streampublic Node uploadFile(Session session, String path, URL contentUrl) throws RepositoryException, IOException
session
- the JCR sessionpath
- the path to the filecontentUrl
- the URL where the content can be found
RepositoryException
- if there is a problem uploading the file
IOException
- if there is a problem using the streampublic Node uploadFile(Session session, String path, File file) throws RepositoryException, IOException
session
- the JCR sessionpath
- the path to the filefile
- the existing and readable file to be uploaded
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 readablepublic void uploadFileAndBlock(Session session, String resourceFilePath, String parentPath) throws RepositoryException, IOException
RepositoryException
IOException
public void uploadFileAndBlock(Session session, String folder, String fileName, String parentPath) throws RepositoryException, IOException
RepositoryException
IOException
public void uploadFileAndBlock(Session session, URL url, String parentPath) throws RepositoryException, IOException
RepositoryException
IOException
public void uploadFilesAndBlock(String destinationPath, String... resourcePaths) throws Exception
Exception
public Node findOrCreateNode(Session session, String path) throws RepositoryException
session
- the JCR session. may not be nullpath
- the path of the desired node to be found or created. may not be null
RepositoryException
IllegalArgumentException
- if either the session or path argument is nullpublic Node findOrCreateNode(Session session, String path, String nodeType) throws RepositoryException
session
- the JCR session. may not be nullpath
- the path of the desired node to be found or created. may not be nullnodeType
- the node type. may be null
RepositoryException
IllegalArgumentException
- if either the session or path argument is nullpublic Node findOrCreateNode(Session session, String path, String defaultNodeType, String finalNodeType) throws RepositoryException
session
- the JCR session. may not be nullpath
- the path of the desired node to be found or created. may not be nulldefaultNodeType
- the default node type. may be nullfinalNodeType
- the optional final node type. may be null
RepositoryException
IllegalArgumentException
- if either the session or path argument is nullpublic Node findOrCreateNode(Node parentNode, String path, String defaultNodeType, String finalNodeType) throws RepositoryException
parentNode
- the parent node. may not be nullpath
- the path of the desired child node. may not be nulldefaultNodeType
- the default node type. may be nullfinalNodeType
- the optional final node type. may be null
RepositoryException
IllegalArgumentException
- if either the parentNode or path argument is nullpublic Node findOrCreateChild(Node parent, String name) throws RepositoryException
parent
- the parent node. may not be nullname
- the name of the child node. may not be null
RepositoryException
IllegalArgumentException
- if either the parent or name argument is nullpublic Node findOrCreateChild(Node parent, String name, String nodeType) throws RepositoryException
parent
- the parent node. may not be nullname
- the name of the child node. may not be nullnodeType
- the node type. may be null
RepositoryException
public boolean isDebug()
public void print(Object msg)
public void printSubgraph(Node node) throws RepositoryException
node
- the root of the subgraph
RepositoryException
public void printSubgraph(Node node, int maxDepth) throws RepositoryException
node
- the root of the subgraphmaxDepth
- the maximum depth of the subgraph that should be printed
RepositoryException
public void printNode(Node node) throws RepositoryException
node
- the node to be printed
RepositoryException
public void printSubgraph(Node node, String lead, int depthOfSubgraph, int maxDepthOfSubgraph) throws RepositoryException
node
- the root of the subgraphlead
- the string that each line should begin with; may be null if there is no such stringdepthOfSubgraph
- the depth of this subgraph's root nodemaxDepthOfSubgraph
- the maximum depth of the subgraph that should be printed
RepositoryException
public QueryResult printQuery(Session session, String jcrSql2) throws RepositoryException
session
- the sessionjcrSql2
- the JCR-SQL2 query
RepositoryException
public QueryResult printQuery(Session session, String jcrSql2, long expectedNumberOfResults, JcrTools.Variable... variables) throws RepositoryException
session
- the sessionjcrSql2
- the JCR-SQL2 queryexpectedNumberOfResults
- the expected number of rows in the results, or -1 if this is not to be checkedvariables
- the variables for the query
RepositoryException
public QueryResult printQuery(Session session, String jcrSql2, long expectedNumberOfResults, Map<String,String> variables) throws RepositoryException
session
- the sessionjcrSql2
- the JCR-SQL2 queryexpectedNumberOfResults
- the expected number of rows in the results, or -1 if this is not to be checkedvariables
- the array of variable maps for the query; all maps will be combined into a single map
RepositoryException
public QueryResult printQuery(Session session, String queryExpression, String queryLanguage, long expectedNumberOfResults, Map<String,String> variables) throws RepositoryException
RepositoryException
public JcrTools.Variable var(String key, String value)
public Map<String,String> vars(String... keyValuePairs)
protected String getStringValue(Value value, int type) throws RepositoryException
RepositoryException
public void registerNodeTypes(Session session, String pathToCndResourceFile)
public void importContent(Session session, String pathToResourceFile) throws Exception
Exception
public void importContent(Session session, String pathToResourceFile, int importBehavior) throws Exception
Exception
public void importContent(Session session, String pathToResourceFile, String jcrPathToImportUnder) throws Exception
Exception
public void importContent(Session session, String pathToResourceFile, String jcrPathToImportUnder, int importBehavior) throws Exception
Exception
public static void importContent(Session session, Class<?> testClass, String pathToResourceFile) throws Exception
Exception
public static void importContent(Session session, Class<?> testClass, String pathToResourceFile, String jcrPathToImportUnder) throws Exception
Exception
public static void importContent(Session session, Class<?> testClass, String pathToResourceFile, String jcrPathToImportUnder, int importBehavior) throws Exception
Exception
protected URL resourceUrl(String name)
public void repeatedlyWithSession(Repository repository, int times, JcrTools.Operation operation) throws Exception
Exception
public void browseTo(Repository repository, String path) throws Exception
Exception
public double withSession(Repository repository, JcrTools.Operation operation) throws Exception
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |