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 AbstractExportViewToFile method getOutputStream.
/**
* @return the OutputStream for the given file
* @throws CommandException
* @throws IOException
*/
protected OutputStream getOutputStream(Context ctx) throws CommandException, IOException {
String to = (String) ctx.get(this.desFsPathKey);
boolean overwrite = Boolean.valueOf((String) ctx.get(this.overwriteKey)).booleanValue();
File f = new File(to);
if (f.exists() && !overwrite) {
throw new CommandException("exception.file.exists", new String[] { to });
}
if (!f.exists()) {
f.createNewFile();
}
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
return out;
}
use of org.apache.jackrabbit.standalone.cli.CommandException in project jackrabbit by apache.
the class ImportFileSystem method execute.
/**
* {@inheritDoc}
*/
public boolean execute(Context ctx) throws Exception {
String file = (String) ctx.get(this.srcFsPathKey);
Node parent = CommandHelper.getCurrentNode(ctx);
if (log.isDebugEnabled()) {
log.debug("importing filesystem from " + file + " to node " + parent);
}
if (file == null) {
throw new CommandException("exception.fspath.is.null");
}
File f = new File(file);
if (!f.exists()) {
throw new CommandException("exception.file.not.found", new String[] { file });
}
if (f.isFile()) {
this.importFile(parent, f);
} else {
Node folder = parent.addNode(f.getName(), "nt:folder");
this.importFolder(folder, f);
}
return false;
}
use of org.apache.jackrabbit.standalone.cli.CommandException in project jackrabbit by apache.
the class JcrClient method getPrompt.
/**
* Prompt message
* @return prompt the prompt message
* @throws RepositoryException
* if the current <code>Repository</code> throws a
* <code>RepositoryException</code>
*/
private String getPrompt() throws RepositoryException {
try {
CommandHelper.getRepository(ctx);
} catch (CommandException e) {
return bundle.getString("phrase.not.connected");
}
boolean unsaved = false;
try {
unsaved = CommandHelper.getSession(ctx).hasPendingChanges();
} catch (CommandException e) {
return bundle.getString("phrase.not.logged.in");
}
try {
Node n = CommandHelper.getCurrentNode(ctx);
// the current node might be Invalid
String path;
try {
path = n.getPath();
} catch (InvalidItemStateException e) {
CommandHelper.setCurrentNode(ctx, CommandHelper.getSession(ctx).getRootNode());
path = CommandHelper.getCurrentNode(ctx).getPath();
}
if (unsaved) {
return path + "*";
} else {
return path;
}
} catch (CommandException e) {
return bundle.getString("phrase.not.logged.in");
}
}
use of org.apache.jackrabbit.standalone.cli.CommandException in project jackrabbit by apache.
the class Main method run.
public void run() throws Exception {
String defaultFile = "jackrabbit-standalone.jar";
URL location = Main.class.getProtectionDomain().getCodeSource().getLocation();
if (location != null && "file".equals(location.getProtocol())) {
File file = new File(location.getPath());
if (file.isFile()) {
defaultFile = location.getPath();
}
}
File file = new File(command.getOptionValue("file", defaultFile));
if (command.hasOption("help")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java -jar " + file.getName(), options, true);
} else if (command.hasOption("notice")) {
copyToOutput("/META-INF/NOTICE.txt");
} else if (command.hasOption("license")) {
copyToOutput("/META-INF/LICENSE.txt");
} else if (command.hasOption("cli")) {
System.setProperty("logback.configurationFile", "logback-cli.xml");
String uri = command.getOptionValue("cli");
Repository repository = JcrUtils.getRepository(uri);
Context context = new ContextBase();
CommandHelper.setRepository(context, repository, uri);
try {
Session session = repository.login();
CommandHelper.setSession(context, session);
CommandHelper.setCurrentNode(context, session.getRootNode());
} catch (RepositoryException ignore) {
// anonymous login not possible
}
new JcrClient(context).runInteractive();
try {
CommandHelper.getSession(context).logout();
} catch (CommandException ignore) {
// already logged out
}
} else {
message("Welcome to Apache Jackrabbit!");
message("-------------------------------");
File repository = new File(command.getOptionValue("repo", "jackrabbit"));
message("Using repository directory " + repository);
repository.mkdirs();
File tmp = new File(repository, "tmp");
tmp.mkdir();
File log = new File(repository, "log");
log.mkdir();
message("Writing log messages to " + log);
prepareServerLog(log);
if (command.hasOption("backup")) {
backup(repository);
} else {
message("Starting the server...");
prepareWebapp(file, repository, tmp);
accessLog.setHandler(webapp);
prepareAccessLog(log);
server.setHandler(accessLog);
prepareConnector();
server.addConnector(connector);
prepareShutdown();
try {
server.start();
String host = connector.getHost();
if (host == null) {
host = "localhost";
}
message("Apache Jackrabbit is now running at " + "http://" + host + ":" + connector.getPort() + "/");
} catch (Throwable t) {
System.err.println("Unable to start the server: " + t.getMessage());
System.exit(1);
}
}
}
}
Aggregations