Search in sources :

Example 1 with JcrClient

use of org.apache.jackrabbit.standalone.cli.JcrClient 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);
            }
        }
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) WebAppContext(org.mortbay.jetty.webapp.WebAppContext) Context(org.apache.commons.chain.Context) Repository(javax.jcr.Repository) RepositoryException(javax.jcr.RepositoryException) CommandException(org.apache.jackrabbit.standalone.cli.CommandException) File(java.io.File) URL(java.net.URL) JcrClient(org.apache.jackrabbit.standalone.cli.JcrClient) ContextBase(org.apache.commons.chain.impl.ContextBase) Session(javax.jcr.Session)

Aggregations

File (java.io.File)1 URL (java.net.URL)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 Context (org.apache.commons.chain.Context)1 ContextBase (org.apache.commons.chain.impl.ContextBase)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 CommandException (org.apache.jackrabbit.standalone.cli.CommandException)1 JcrClient (org.apache.jackrabbit.standalone.cli.JcrClient)1 WebAppContext (org.mortbay.jetty.webapp.WebAppContext)1