Search in sources :

Example 21 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class XMLDBMoveTask method execute.

@Override
public void execute() throws BuildException {
    if (uri == null) {
        throw (new BuildException("You have to specify an XMLDB collection URI"));
    }
    if ((resource == null) && (collection == null)) {
        throw (new BuildException("Missing parameter: either resource or collection should be specified"));
    }
    registerDatabase();
    try {
        log("Get base collection: " + uri, Project.MSG_DEBUG);
        final Collection base = DatabaseManager.getCollection(uri, user, password);
        if (base == null) {
            final String msg = "Collection " + uri + " could not be found.";
            if (failonerror) {
                throw (new BuildException(msg));
            } else {
                log(msg, Project.MSG_ERR);
            }
        }
        log("Create collection management service for collection " + base.getName(), Project.MSG_DEBUG);
        final EXistCollectionManagementService service = (EXistCollectionManagementService) base.getService("CollectionManagementService", "1.0");
        if (resource != null) {
            log("Moving resource: " + resource, Project.MSG_INFO);
            final Resource res = base.getResource(resource);
            if (res == null) {
                final String msg = "Resource " + resource + " not found.";
                if (failonerror) {
                    throw (new BuildException(msg));
                } else {
                    log(msg, Project.MSG_ERR);
                }
            } else {
                service.moveResource(XmldbURI.xmldbUriFor(resource), XmldbURI.xmldbUriFor(destination), XmldbURI.xmldbUriFor(name));
            }
        } else {
            log("Moving collection: " + collection, Project.MSG_INFO);
            service.move(XmldbURI.xmldbUriFor(collection), XmldbURI.xmldbUriFor(destination), XmldbURI.xmldbUriFor(name));
        }
    } catch (final XMLDBException e) {
        final String msg = "XMLDB exception during move: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    } catch (final URISyntaxException e) {
        final String msg = "URI syntax exception: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    }
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException) URISyntaxException(java.net.URISyntaxException)

Example 22 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class InteractiveClient method mkcol.

private void mkcol(final XmldbURI collPath) throws XMLDBException {
    messageln("creating '" + collPath + "'");
    final XmldbURI[] segments = collPath.getPathSegments();
    XmldbURI p = XmldbURI.ROOT_COLLECTION_URI;
    for (int i = 1; i < segments.length; i++) {
        p = p.append(segments[i]);
        final Collection c = DatabaseManager.getCollection(properties.getProperty(URI) + p, properties.getProperty(USER), properties.getProperty(PASSWORD));
        if (c == null) {
            final EXistCollectionManagementService mgtService = (EXistCollectionManagementService) current.getService("CollectionManagementService", "1.0");
            current = mgtService.createCollection(segments[i]);
        } else {
            current = c;
        }
    }
    path = p;
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) Collection(org.xmldb.api.base.Collection) XmldbURI(org.exist.xmldb.XmldbURI)

Example 23 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class InteractiveClient method findRecursive.

private synchronized boolean findRecursive(final Collection collection, final Path dir, final XmldbURI base) throws XMLDBException {
    Collection c;
    Resource document;
    EXistCollectionManagementService mgtService;
    // The XmldbURIs here aren't really used...
    XmldbURI next;
    MimeType mimeType;
    try {
        final List<Path> files = FileUtils.list(dir);
        int i = 0;
        for (final Path file : files) {
            next = base.append(FileUtils.fileName(file));
            try {
                if (Files.isDirectory(file)) {
                    messageln("entering directory " + file.toAbsolutePath());
                    c = collection.getChildCollection(FileUtils.fileName(file));
                    if (c == null) {
                        mgtService = (EXistCollectionManagementService) collection.getService("CollectionManagementService", "1.0");
                        c = mgtService.createCollection(XmldbURI.xmldbUriFor(FileUtils.fileName(file)));
                    }
                    if (c instanceof Observable && options.verbose) {
                        final ProgressObserver observer = new ProgressObserver();
                        ((Observable) c).addObserver(observer);
                    }
                    findRecursive(c, file, next);
                } else {
                    final long start1 = System.currentTimeMillis();
                    mimeType = MimeTable.getInstance().getContentTypeFor(FileUtils.fileName(file));
                    if (mimeType == null) {
                        messageln("File " + FileUtils.fileName(file) + " has an unknown suffix. Cannot determine file type.");
                        mimeType = MimeType.BINARY_TYPE;
                    }
                    message("storing document " + FileUtils.fileName(file) + " (" + i + " of " + files.size() + ") " + "...");
                    document = collection.createResource(FileUtils.fileName(file), mimeType.getXMLDBType());
                    document.setContent(file);
                    ((EXistResource) document).setMimeType(mimeType.getName());
                    collection.storeResource(document);
                    ++filesCount;
                    messageln(" " + FileUtils.sizeQuietly(file) + " bytes in " + (System.currentTimeMillis() - start1) + "ms.");
                }
            } catch (final URISyntaxException e) {
                errorln("uri syntax exception parsing " + file.toAbsolutePath() + ": " + e.getMessage());
            }
            i++;
        }
        return true;
    } catch (final IOException e) {
        throw new XMLDBException(ErrorCodes.UNKNOWN_ERROR, e);
    }
}
Also used : Path(java.nio.file.Path) EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) ExtendedResource(org.exist.xmldb.ExtendedResource) BinaryResource(org.xmldb.api.modules.BinaryResource) EXistResource(org.exist.xmldb.EXistResource) URISyntaxException(java.net.URISyntaxException) EXistResource(org.exist.xmldb.EXistResource) Collection(org.xmldb.api.base.Collection) XmldbURI(org.exist.xmldb.XmldbURI)

Example 24 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class InteractiveClient method process.

/**
 * In interactive mode, process a line entered by the user.
 *
 * @param line the line entered
 * @return true if command != quit
 */
protected boolean process(final String line) {
    if (options.startGUI) {
        frame.setPath(path);
    }
    final String[] args;
    if (line.startsWith("find")) {
        args = new String[2];
        args[0] = "find";
        args[1] = line.substring(5);
    } else {
        final StreamTokenizer tok = new StreamTokenizer(new StringReader(line));
        tok.resetSyntax();
        tok.wordChars(0x21, 0x7FFF);
        tok.quoteChar('"');
        tok.whitespaceChars(0x20, 0x20);
        final List<String> argList = new ArrayList<>(3);
        // int i = 0;
        int token;
        try {
            while ((token = tok.nextToken()) != StreamTokenizer.TT_EOF) {
                if (token == StreamTokenizer.TT_WORD || token == '"') {
                    argList.add(tok.sval);
                }
            }
        } catch (final IOException e) {
            System.err.println("Could not parse command line.");
            return true;
        }
        args = new String[argList.size()];
        argList.toArray(args);
    }
    if (args.length == 0) {
        return true;
    }
    try {
        XmldbURI newPath = path;
        final XmldbURI currUri = XmldbURI.xmldbUriFor(properties.getProperty(URI)).resolveCollectionPath(path);
        if (args[0].equalsIgnoreCase("ls")) {
            // list collection contents
            getResources();
            if ("true".equals(properties.getProperty(PERMISSIONS))) {
                for (String resource : resources) {
                    messageln(resource);
                }
            } else {
                for (int i = 0; i < resources.length; i++) {
                    final StringBuilder buf = new StringBuilder();
                    int k = 0;
                    for (int j = 0; i < resources.length && j < 5; i++, j++) {
                        buf.append(resources[i]);
                        buf.append('\t');
                        k = j;
                    }
                    if (k == 4 && i < resources.length) {
                        i--;
                    }
                    messageln(buf.toString());
                }
            }
        } else if (args[0].equalsIgnoreCase("cd")) {
            // change current collection
            completitions.clear();
            Collection temp;
            XmldbURI collectionPath;
            if (args.length < 2 || args[1] == null) {
                collectionPath = XmldbURI.ROOT_COLLECTION_URI;
            } else {
                collectionPath = XmldbURI.xmldbUriFor(args[1]);
            }
            collectionPath = currUri.resolveCollectionPath(collectionPath);
            if (collectionPath.numSegments() == 0) {
                collectionPath = currUri.resolveCollectionPath(XmldbURI.ROOT_COLLECTION_URI);
                messageln("cannot go above " + XmldbURI.ROOT_COLLECTION_URI.toString());
            }
            temp = DatabaseManager.getCollection(collectionPath.toString(), properties.getProperty(USER), properties.getProperty(PASSWORD));
            if (temp != null) {
                current.close();
                current = temp;
                newPath = collectionPath.toCollectionPathURI();
                if (options.startGUI) {
                    frame.setPath(collectionPath.toCollectionPathURI());
                }
            } else {
                messageln("no such collection.");
            }
            getResources();
        } else if (args[0].equalsIgnoreCase("cp")) {
            if (args.length != 3) {
                messageln("cp requires two arguments.");
                return true;
            }
            final XmldbURI src;
            final XmldbURI dest;
            try {
                src = XmldbURI.xmldbUriFor(args[1]);
                dest = XmldbURI.xmldbUriFor(args[2]);
            } catch (final URISyntaxException e) {
                errorln("could not parse collection name into a valid URI: " + e.getMessage());
                return false;
            }
            copy(src, dest);
            getResources();
        } else if (args[0].equalsIgnoreCase("edit")) {
            if (args.length == 2) {
                final XmldbURI resource;
                try {
                    resource = XmldbURI.xmldbUriFor(args[1]);
                } catch (final URISyntaxException e) {
                    errorln("could not parse resource name into a valid URI: " + e.getMessage());
                    return false;
                }
                editResource(resource);
            } else {
                messageln("Please specify a resource.");
            }
        } else if (args[0].equalsIgnoreCase("get")) {
            if (args.length < 2) {
                System.err.println("wrong number of arguments.");
                return true;
            }
            final XmldbURI resource;
            try {
                resource = XmldbURI.xmldbUriFor(args[1]);
            } catch (final URISyntaxException e) {
                errorln("could not parse resource name into a valid URI: " + e.getMessage());
                return false;
            }
            final Resource res = retrieve(resource);
            // display document
            if (res != null) {
                final String data;
                if ("XMLResource".equals(res.getResourceType())) {
                    data = (String) res.getContent();
                } else {
                    data = new String((byte[]) res.getContent());
                }
                if (options.startGUI) {
                    frame.setEditable(false);
                    frame.display(data);
                    frame.setEditable(true);
                } else {
                    final String content = data;
                    more(content);
                }
            }
            return true;
        } else if (args[0].equalsIgnoreCase("find")) {
            // search
            if (args.length < 2) {
                messageln("no query argument found.");
                return true;
            }
            messageln(args[1]);
            final long start = System.currentTimeMillis();
            result = find(args[1]);
            if (result == null) {
                messageln("nothing found");
            } else {
                messageln("found " + result.getSize() + " hits in " + (System.currentTimeMillis() - start) + "ms.");
            }
            nextInSet = 1;
        } else if (args[0].equalsIgnoreCase("run")) {
            if (args.length < 2) {
                messageln("please specify a query file.");
                return true;
            }
            try (final BufferedReader reader = Files.newBufferedReader(Paths.get(args[1]))) {
                final StringBuilder buf = new StringBuilder();
                String nextLine;
                while ((nextLine = reader.readLine()) != null) {
                    buf.append(nextLine);
                    buf.append(EOL);
                }
                args[1] = buf.toString();
                final long start = System.currentTimeMillis();
                result = find(args[1]);
                if (result == null) {
                    messageln("nothing found");
                } else {
                    messageln("found " + result.getSize() + " hits in " + (System.currentTimeMillis() - start) + "ms.");
                }
                nextInSet = 1;
            } catch (final Exception e) {
                errorln("An error occurred: " + e.getMessage());
            }
        } else if (args[0].equalsIgnoreCase("show")) {
            // show search results
            if (result == null) {
                messageln("no result set.");
                return true;
            }
            try {
                int start = nextInSet;
                int count = 1;
                if (args.length > 1) {
                    start = Integer.parseInt(args[1]);
                }
                if (args.length > 2) {
                    count = Integer.parseInt(args[2]);
                }
                final int s = (int) result.getSize();
                if (start < 1 || start > s) {
                    messageln("start offset out of range");
                    return true;
                }
                --start;
                if (start + count > s) {
                    count = s - start;
                }
                nextInSet = start + count + 1;
                for (int i = start; i < start + count; i++) {
                    final Resource r = result.getResource(i);
                    if (options.startGUI) {
                        frame.display((String) r.getContent());
                    } else {
                        more((String) r.getContent());
                    }
                }
                messageln("displayed items " + (start + 1) + " to " + (start + count) + " of " + result.getSize());
            } catch (final NumberFormatException nfe) {
                errorln("wrong argument");
                return true;
            }
        } else if (args[0].equalsIgnoreCase("mkcol")) {
            // create collection
            if (args.length < 2) {
                messageln("missing argument.");
                return true;
            }
            final XmldbURI collUri;
            try {
                collUri = XmldbURI.xmldbUriFor(args[1]);
            } catch (final URISyntaxException e) {
                errorln("could not parse collection name into a valid URI: " + e.getMessage());
                return false;
            }
            final EXistCollectionManagementService mgtService = (EXistCollectionManagementService) current.getService("CollectionManagementService", "1.0");
            final Collection newCollection = mgtService.createCollection(collUri);
            if (newCollection == null) {
                messageln("could not create collection.");
            } else {
                messageln("created collection.");
            }
            // re-read current collection
            current = DatabaseManager.getCollection(properties.getProperty(URI) + path, properties.getProperty(USER), properties.getProperty("password"));
            getResources();
        } else if (args[0].equalsIgnoreCase("put")) {
            // put a document or directory into the database
            if (args.length < 2) {
                messageln("missing argument.");
                return true;
            }
            final boolean r = parse(Paths.get(args[1]));
            getResources();
            return r;
        } else if (args[0].equalsIgnoreCase("putzip")) {
            // put the contents of a zip archive into the database
            if (args.length < 2) {
                messageln("missing argument.");
                return true;
            }
            final boolean r = parseZip(Paths.get(args[1]));
            getResources();
            return r;
        } else if (args[0].equalsIgnoreCase("putgz")) {
            // put the contents of a zip archive into the database
            if (args.length < 2) {
                messageln("missing argument.");
                return true;
            }
            final boolean r = parseGZip(args[1]);
            getResources();
            return r;
        } else if (args[0].equalsIgnoreCase("blob")) {
            // put a document or directory into the database
            if (args.length < 2) {
                messageln("missing argument.");
                return true;
            }
            storeBinary(args[1]);
            getResources();
        } else if (args[0].equalsIgnoreCase("rm")) {
            // remove document
            if (args.length < 2) {
                messageln("missing argument.");
                return true;
            }
            remove(args[1]);
            // re-read current collection
            current = DatabaseManager.getCollection(properties.getProperty("uri") + path, properties.getProperty(USER), properties.getProperty("password"));
            getResources();
        } else if (args[0].equalsIgnoreCase("rmcol")) {
            // remove collection
            if (args.length < 2) {
                messageln("wrong argument count.");
                return true;
            }
            final XmldbURI collUri;
            try {
                collUri = XmldbURI.xmldbUriFor(args[1]);
            } catch (final URISyntaxException e) {
                errorln("could not parse collection name into a valid URI: " + e.getMessage());
                return false;
            }
            rmcol(collUri);
            // re-read current collection
            current = DatabaseManager.getCollection(properties.getProperty(URI) + path, properties.getProperty(USER), properties.getProperty(PASSWORD));
            getResources();
        } else if (args[0].equalsIgnoreCase("adduser")) {
            if (args.length < 2) {
                System.err.println("Usage: adduser name");
                return true;
            }
            if (options.startGUI) {
                messageln("command not supported in GUI mode. Please use the \"Edit users\" menu option.");
                return true;
            }
            try {
                final UserManagementService mgtService = (UserManagementService) current.getService("UserManagementService", "1.0");
                String p1;
                String p2;
                while (true) {
                    p1 = console.readLine("password: ", '*');
                    p2 = console.readLine("re-enter password: ", '*');
                    if (p1.equals(p2)) {
                        break;
                    }
                    messageln("Entered passwords differ. Try again...");
                }
                final UserAider user = new UserAider(args[1]);
                user.setPassword(p1);
                final String groups = console.readLine("enter groups: ");
                final StringTokenizer tok = new StringTokenizer(groups, " ,");
                while (tok.hasMoreTokens()) {
                    final String group = tok.nextToken();
                    if (group.length() > 0) {
                        user.addGroup(group);
                    }
                }
                if (user.getGroups().length == 0) {
                    messageln("No groups specified, will be a member of the '" + SecurityManager.GUEST_GROUP + "' group!");
                    user.addGroup(SecurityManager.GUEST_GROUP);
                }
                mgtService.addAccount(user);
                messageln("User '" + user.getName() + "' created.");
            } catch (final Exception e) {
                errorln("ERROR: " + e.getMessage());
                e.printStackTrace();
            }
        } else if (args[0].equalsIgnoreCase("users")) {
            final UserManagementService mgtService = (UserManagementService) current.getService("UserManagementService", "1.0");
            final Account[] users = mgtService.getAccounts();
            messageln("User\t\tGroups");
            messageln("-----------------------------------------");
            for (Account user : users) {
                System.out.print(user.getName() + "\t\t");
                final String[] groups = user.getGroups();
                for (int j = 0; j < groups.length; j++) {
                    System.out.print(groups[j]);
                    if (j + 1 < groups.length) {
                        System.out.print(", ");
                    }
                }
                System.out.println();
            }
        } else if (args[0].equalsIgnoreCase("passwd")) {
            if (options.startGUI) {
                messageln("command not supported in GUI mode. Please use the \"Edit users\" menu option.");
                return true;
            }
            if (args.length < 2) {
                messageln("Usage: passwd username");
                return true;
            }
            try {
                final UserManagementService mgtService = (UserManagementService) current.getService("UserManagementService", "1.0");
                final Account user = mgtService.getAccount(args[1]);
                if (user == null) {
                    messageln("no such user.");
                    return true;
                }
                String p1;
                String p2;
                while (true) {
                    p1 = console.readLine("password: ", '*');
                    p2 = console.readLine("re-enter password: ", '*');
                    if (p1.equals(p2)) {
                        break;
                    }
                    System.out.println(EOL + "entered passwords differ. Try again...");
                }
                user.setPassword(p1);
                mgtService.updateAccount(user);
                properties.setProperty(PASSWORD, p1);
            } catch (final Exception e) {
                errorln("ERROR: " + e.getMessage());
                e.printStackTrace();
            }
        } else if (args[0].equalsIgnoreCase("chmod")) {
            if (args.length < 2) {
                System.out.println("Usage: chmod [resource] mode");
                return true;
            }
            final Collection temp;
            if (args.length == 3) {
                System.out.println("trying collection: " + args[1]);
                temp = current.getChildCollection(args[1]);
                if (temp == null) {
                    System.out.println(EOL + "trying resource: " + args[1]);
                    final Resource r = current.getResource(args[1]);
                    if (r != null) {
                        final UserManagementService mgtService = (UserManagementService) current.getService("UserManagementService", "1.0");
                        mgtService.chmod(r, args[2]);
                    } else {
                        System.err.println("Resource " + args[1] + " not found.");
                    }
                } else {
                    final UserManagementService mgtService = (UserManagementService) temp.getService("UserManagementService", "1.0");
                    mgtService.chmod(args[2]);
                }
            } else {
                final UserManagementService mgtService = (UserManagementService) current.getService("UserManagementService", "1.0");
                mgtService.chmod(args[1]);
            }
            // re-read current collection
            current = DatabaseManager.getCollection(properties.getProperty(URI) + path, properties.getProperty(USER), properties.getProperty(PASSWORD));
            getResources();
        } else if (args[0].equalsIgnoreCase("chown")) {
            if (args.length < 3) {
                System.out.println("Usage: chown username group [resource]");
                return true;
            }
            final Collection temp;
            if (args.length == 4) {
                temp = current.getChildCollection(args[3]);
            } else {
                temp = current;
            }
            if (temp != null) {
                final UserManagementService mgtService = (UserManagementService) temp.getService("UserManagementService", "1.0");
                final Account u = mgtService.getAccount(args[1]);
                if (u == null) {
                    System.out.println("unknown user");
                    return true;
                }
                mgtService.chown(u, args[2]);
                System.out.println("owner changed.");
                getResources();
                return true;
            }
            final Resource res = current.getResource(args[3]);
            if (res != null) {
                final UserManagementService mgtService = (UserManagementService) current.getService("UserManagementService", "1.0");
                final Account u = mgtService.getAccount(args[1]);
                if (u == null) {
                    System.out.println("unknown user");
                    return true;
                }
                mgtService.chown(res, u, args[2]);
                getResources();
                return true;
            }
            System.err.println("Resource " + args[3] + " not found.");
        } else if (args[0].equalsIgnoreCase("lock") || args[0].equalsIgnoreCase("unlock")) {
            if (args.length < 2) {
                messageln("Usage: lock resource");
                return true;
            }
            final Resource res = current.getResource(args[1]);
            if (res != null) {
                final UserManagementService mgtService = (UserManagementService) current.getService("UserManagementService", "1.0");
                final Account user = mgtService.getAccount(properties.getProperty(USER, "guest"));
                if (args[0].equalsIgnoreCase("lock")) {
                    mgtService.lockResource(res, user);
                } else {
                    mgtService.unlockResource(res);
                }
            }
        } else if (args[0].equalsIgnoreCase("elements")) {
            System.out.println("Element occurrences in collection " + current.getName());
            System.out.println("--------------------------------------------" + "-----------");
            final IndexQueryService service = (IndexQueryService) current.getService("IndexQueryService", "1.0");
            final Occurrences[] elements = service.getIndexedElements(true);
            for (Occurrences element : elements) {
                System.out.println(formatString(element.getTerm().toString(), Integer.toString(element.getOccurrences()), 50));
            }
            return true;
        } else if (args[0].equalsIgnoreCase("xupdate")) {
            if (options.startGUI) {
                messageln("command not supported in GUI mode.");
                return true;
            }
            final StringBuilder command = new StringBuilder();
            try {
                while (true) {
                    final String lastLine = console.readLine("| ");
                    if (lastLine == null || lastLine.length() == 0) {
                        break;
                    }
                    command.append(lastLine);
                }
            } catch (final UserInterruptException e) {
            // TODO report error?
            }
            final String xupdate = "<xu:modifications version=\"1.0\" " + "xmlns:xu=\"http://www.xmldb.org/xupdate\">" + command.toString() + "</xu:modifications>";
            final XUpdateQueryService service = (XUpdateQueryService) current.getService("XUpdateQueryService", "1.0");
            final long mods = service.update(xupdate);
            System.out.println(mods + " modifications processed.");
        } else if (args[0].equalsIgnoreCase("map")) {
            final StringTokenizer tok = new StringTokenizer(args[1], "= ");
            final String prefix;
            if (args[1].startsWith("=")) {
                prefix = "";
            } else {
                if (tok.countTokens() < 2) {
                    messageln("please specify a namespace/prefix mapping as: prefix=namespaceURI");
                    return true;
                }
                prefix = tok.nextToken();
            }
            final String uri = tok.nextToken();
            namespaceMappings.put(prefix, uri);
        } else if (args[0].equalsIgnoreCase("set")) {
            if (args.length == 1) {
                properties.list(System.out);
            } else {
                try {
                    final StringTokenizer tok = new StringTokenizer(args[1], "= ");
                    if (tok.countTokens() < 2) {
                        System.err.println("please specify a key=value pair");
                        return true;
                    }
                    final String key = tok.nextToken();
                    final String val = tok.nextToken();
                    properties.setProperty(key, val);
                    current.setProperty(key, val);
                    getResources();
                } catch (final Exception e) {
                    System.err.println("Exception: " + e.getMessage());
                }
            }
        } else if (args[0].equalsIgnoreCase("shutdown")) {
            final DatabaseInstanceManager mgr = (DatabaseInstanceManager) current.getService("DatabaseInstanceManager", "1.0");
            if (mgr == null) {
                messageln("Service is not available");
                return true;
            }
            mgr.shutdown();
            return true;
        } else if (args[0].equalsIgnoreCase("help") || "?".equals(args[0])) {
            displayHelp();
        } else if (args[0].equalsIgnoreCase("quit")) {
            return false;
        // XXX:make it pluggable
        } else if (havePluggableCommands) {
            final EXistCollectionManagementService mgtService = (EXistCollectionManagementService) current.getService("CollectionManagementService", "1.0");
            try {
                mgtService.runCommand(args);
            } catch (final XMLDBException e) {
                if (e.getCause() != null && e.getCause().getClass().getName().equals("org.exist.plugin.command.CommandNotFoundException")) {
                    messageln("unknown command: '" + args[0] + "'");
                    return true;
                } else {
                    throw e;
                }
            }
        // ****************************************************************
        } else {
            messageln("unknown command: '" + args[0] + "'");
            return true;
        }
        path = newPath;
        return true;
    } catch (final Throwable e) {
        if (options.startGUI) {
            ClientFrame.showErrorMessage(getExceptionMessage(e), e);
        } else {
            errorln(getExceptionMessage(e));
            e.printStackTrace();
        }
        return true;
    }
}
Also used : Account(org.exist.security.Account) EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) IndexQueryService(org.exist.xmldb.IndexQueryService) URISyntaxException(java.net.URISyntaxException) XUpdateQueryService(org.xmldb.api.modules.XUpdateQueryService) XmldbURI(org.exist.xmldb.XmldbURI) ExtendedResource(org.exist.xmldb.ExtendedResource) BinaryResource(org.xmldb.api.modules.BinaryResource) EXistResource(org.exist.xmldb.EXistResource) UserManagementService(org.exist.xmldb.UserManagementService) URISyntaxException(java.net.URISyntaxException) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) SAXException(org.xml.sax.SAXException) ArgumentException(se.softhouse.jargo.ArgumentException) StartException(org.exist.start.StartException) DatabaseInstanceManager(org.exist.xmldb.DatabaseInstanceManager) Collection(org.xmldb.api.base.Collection) UserAider(org.exist.security.internal.aider.UserAider)

Example 25 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class InteractiveClient method copy.

private void copy(final XmldbURI source, XmldbURI destination) throws XMLDBException {
    try {
        final EXistCollectionManagementService mgtService = (EXistCollectionManagementService) current.getService("CollectionManagementService", "1.0");
        final XmldbURI destName = destination.lastSegment();
        final Collection destCol = resolveCollection(destination);
        if (destCol == null) {
            if (destination.numSegments() == 1) {
                destination = XmldbURI.xmldbUriFor(current.getName());
            } else {
                destination = destination.removeLastSegment();
            }
        }
        final Resource srcDoc = resolveResource(source);
        if (srcDoc != null) {
            final XmldbURI resourcePath = XmldbURI.xmldbUriFor(srcDoc.getParentCollection().getName()).append(srcDoc.getId());
            messageln("Copying resource '" + resourcePath + "' to '" + destination + "'");
            mgtService.copyResource(resourcePath, destination, destName);
        } else {
            messageln("Copying collection '" + source + "' to '" + destination + "'");
            mgtService.copy(source, destination, destName);
        }
    } catch (final URISyntaxException e) {
        errorln("could not parse name into a valid URI: " + e.getMessage());
    }
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) ExtendedResource(org.exist.xmldb.ExtendedResource) BinaryResource(org.xmldb.api.modules.BinaryResource) EXistResource(org.exist.xmldb.EXistResource) Collection(org.xmldb.api.base.Collection) URISyntaxException(java.net.URISyntaxException) XmldbURI(org.exist.xmldb.XmldbURI)

Aggregations

EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)42 Collection (org.xmldb.api.base.Collection)31 Resource (org.xmldb.api.base.Resource)25 BinaryResource (org.xmldb.api.modules.BinaryResource)19 Test (org.junit.Test)18 UserManagementService (org.exist.xmldb.UserManagementService)16 XMLResource (org.xmldb.api.modules.XMLResource)13 XmldbURI (org.exist.xmldb.XmldbURI)12 URISyntaxException (java.net.URISyntaxException)11 Database (org.xmldb.api.base.Database)7 EXistResource (org.exist.xmldb.EXistResource)6 ExtendedResource (org.exist.xmldb.ExtendedResource)6 XMLDBException (org.xmldb.api.base.XMLDBException)5 Path (java.nio.file.Path)3 IndexQueryService (org.exist.xmldb.IndexQueryService)3 XPathException (org.exist.xquery.XPathException)3 InputStream (java.io.InputStream)2 BuildException (org.apache.tools.ant.BuildException)2 AnyURIValue (org.exist.xquery.value.AnyURIValue)2 ResourceSet (org.xmldb.api.base.ResourceSet)2