use of org.apache.jackrabbit.standalone.cli.CommandException in project jackrabbit by apache.
the class Info method execute.
public boolean execute(Context ctx) throws Exception {
PrintWriter out = CommandHelper.getOutput(ctx);
out.println();
try {
CommandHelper.getRepository(ctx);
} catch (CommandException e) {
out.println("No connection to a repository.");
return false;
}
out.println("Repository: " + CommandHelper.getRepositoryAddress(ctx));
Session session;
String currentPath;
try {
session = CommandHelper.getSession(ctx);
currentPath = CommandHelper.getCurrentNode(ctx).getPath();
} catch (CommandException e) {
out.println("Not logged in / no session.");
return false;
}
out.println("User : " + session.getUserID());
out.println("Workspace : " + session.getWorkspace().getName());
out.println("Node : " + currentPath);
out.println();
if (session.isLive()) {
out.println("Session is live.");
} else {
out.println("Session is not live.");
}
if (session.hasPendingChanges()) {
out.println("Session has pending changes.");
} else {
out.println("Session has no changes.");
}
return false;
}
use of org.apache.jackrabbit.standalone.cli.CommandException in project jackrabbit by apache.
the class ExportPropertyToFile method exportValue.
/**
* Export th given value to a File
* @param ctx
* the <code>Context</code>
* @param value
* the <code>Value</code>
* @param to
* the target file system path
* @throws CommandException
* if the <code>File</code> already exists
* @throws IOException
* if an <code>IOException</code> occurs
* @throws RepositoryException
* if the current working <code>Repository</code> throws an
* <code>Exception</code>
*/
private void exportValue(Context ctx, Value value, String to) throws CommandException, IOException, RepositoryException {
boolean overwrite = Boolean.valueOf((String) ctx.get(this.overwriteKey)).booleanValue();
File file = new File(to);
// Check if there's a file at the given target path
if (file.exists() && !overwrite) {
throw new CommandException("exception.file.exists", new String[] { to });
}
// If it doesn't exists create the file
if (!file.exists()) {
file.createNewFile();
}
if (value.getType() == PropertyType.BINARY) {
InputStream in = value.getStream();
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
in.close();
out.flush();
out.close();
} else {
Reader in = new StringReader(value.getString());
BufferedWriter out = new BufferedWriter(new FileWriter(file));
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
in.close();
out.flush();
out.close();
}
}
use of org.apache.jackrabbit.standalone.cli.CommandException in project jackrabbit by apache.
the class ExportFileSystem method execute.
/**
* {@inheritDoc}
*/
public boolean execute(Context ctx) throws Exception {
String from = (String) ctx.get(this.srcJcrPathKey);
String to = (String) ctx.get(this.destFsPathKey);
boolean overwrite = Boolean.valueOf((String) ctx.get(this.overwriteKey)).booleanValue();
if (log.isDebugEnabled()) {
log.debug("exporting node at " + from + " to the filesystem (" + to + ") overwrite=" + overwrite);
}
Node node = CommandHelper.getNode(ctx, from);
File f = new File(to);
// check if the file exists
if (f.exists() && !overwrite) {
throw new CommandException("exception.file.exists", new String[] { to });
}
// export either a file or a folder
if (node.isNodeType("nt:file")) {
this.createFile(node, f);
} else if (node.isNodeType("nt:folder")) {
this.addFolder(node, f);
} else {
throw new CommandException("exception.not.file.or.folder", new String[] { node.getPrimaryNodeType().getName() });
}
return false;
}
use of org.apache.jackrabbit.standalone.cli.CommandException in project jackrabbit by apache.
the class ExportFileSystem method createFile.
/**
* Exports an nt:file to the file system
* @param node
* the <code>Node</code>
* @param file
* the <code>File</code>
* @throws IOException
* if an IOException occurs
* @throws CommandException
* if the <code>File</code> can't be created
* @throws ValueFormatException
* if a <code>Value</code> can't be retrieved
* @throws PathNotFoundException
* if the <code>Node</code> can't be found
* @throws RepositoryException
* if the current working <code>Repository</code> throws an
* <code>Exception</code>
*/
private void createFile(Node node, File file) throws IOException, CommandException, ValueFormatException, PathNotFoundException, RepositoryException {
boolean created = file.createNewFile();
if (!created) {
throw new CommandException("exception.file.not.created", new String[] { file.getPath() });
}
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
InputStream in = node.getNode("jcr:content").getProperty("jcr:data").getStream();
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
in.close();
out.flush();
out.close();
}
use of org.apache.jackrabbit.standalone.cli.CommandException in project jackrabbit by apache.
the class ExportFileSystem method addFolder.
/**
* Exports a nt:folder and all its children to the file system
* @param node
* the <code>Node</code>
* @param file
* <code>File</code>
* @throws CommandException
* if the <code>File</code> can't be created
* @throws RepositoryException
* if the current working <code>Repository</code> throws an
* <code>Exception</code>
* @throws IOException
* if an IOException occurs
*/
private void addFolder(Node node, File file) throws CommandException, RepositoryException, IOException {
boolean created = file.mkdir();
if (!created) {
throw new CommandException("exception.folder.not.created", new String[] { file.getPath() });
}
NodeIterator iter = node.getNodes();
while (iter.hasNext()) {
Node child = iter.nextNode();
// File
if (child.isNodeType("nt:file")) {
File childFile = new File(file, child.getName());
createFile(child, childFile);
} else if (child.isNodeType("nt:folder")) {
File childFolder = new File(file, child.getName());
addFolder(child, childFolder);
}
}
}
Aggregations