Search in sources :

Example 86 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class MapTest method effectiveBooleanValue.

@Test
public void effectiveBooleanValue() {
    try {
        final XQueryService queryService = (XQueryService) server.getRoot().getService("XQueryService", "1.0");
        queryService.query("fn:boolean(map{})");
    } catch (final XMLDBException e) {
        final Throwable cause = e.getCause();
        if (cause instanceof XPathException) {
            final XPathException xpe = (XPathException) cause;
            assertEquals(ErrorCodes.FORG0006, xpe.getErrorCode());
            return;
        }
    }
    fail("effectiveBooleanValue of a map should cause the error FORG0006");
}
Also used : XPathException(org.exist.xquery.XPathException) XQueryService(org.xmldb.api.modules.XQueryService) XMLDBException(org.xmldb.api.base.XMLDBException) Test(org.junit.Test)

Example 87 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class NewResourceDialog method createResource.

private void createResource(final ResourceType resourceType, final String filename, final String moduleNamespace, final String moduleNamespacePrefix) {
    final StringBuilder resourceContentBuilder = new StringBuilder();
    try (final InputStream is = getClass().getResourceAsStream(resourceType.getTemplatePath());
        final Reader reader = new InputStreamReader(is)) {
        final char[] buf = new char[1024];
        int read = -1;
        while ((read = reader.read(buf)) > -1) {
            resourceContentBuilder.append(buf, 0, read);
        }
    } catch (final IOException ioe) {
        ClientFrame.showErrorMessage(ioe.getMessage(), ioe);
    }
    final String resourceContent;
    if (resourceType == ResourceType.XQUERY_LIBRARY) {
        resourceContent = resourceContentBuilder.toString().replaceAll("\\$NS", moduleNamespace).replaceAll("\\$PREFIX", moduleNamespacePrefix);
    } else {
        resourceContent = resourceContentBuilder.toString();
    }
    try {
        final String resName = URIUtils.urlEncodeUtf8((isNullOrEmpty(filename) ? DEFAULT_FILENAME : filename) + "." + resourceType.getFileExtension());
        final String resType = resourceType == ResourceType.XML_DOCUMENT ? XMLResource.RESOURCE_TYPE : BinaryResource.RESOURCE_TYPE;
        final Collection collection = client.current;
        final Resource resource = collection.createResource(resName, resType);
        resource.setContent(resourceContent);
        ((EXistResource) resource).setMimeType(resourceType.getMimeType());
        collection.storeResource(resource);
        collection.close();
        client.reloadCollection();
    } catch (final XMLDBException xmldbe) {
        ClientFrame.showErrorMessage(xmldbe.getMessage(), xmldbe);
    }
}
Also used : EXistResource(org.exist.xmldb.EXistResource) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) EXistResource(org.exist.xmldb.EXistResource) Resource(org.xmldb.api.base.Resource) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) IOException(java.io.IOException)

Example 88 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class ClientFrame method removeAction.

private void removeAction(final ActionEvent ev) {
    final ResourceDescriptor[] res = getSelectedResources();
    final Collection removeRootCollection = client.current;
    // String cmd;
    if (JOptionPane.showConfirmDialog(this, // $NON-NLS-1$ //$NON-NLS-2$
    Messages.getString("ClientFrame.104") + Messages.getString("ClientFrame.105"), Messages.getString("ClientFrame.106"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
        // $NON-NLS-1$
        final Runnable removeTask = () -> {
            // $NON-NLS-1$ //$NON-NLS-2$
            final ProgressMonitor monitor = new ProgressMonitor(ClientFrame.this, Messages.getString("ClientFrame.107"), Messages.getString("ClientFrame.108"), 1, res.length);
            monitor.setMillisToDecideToPopup(500);
            monitor.setMillisToPopup(500);
            for (int i = 0; i < res.length; i++) {
                final ResourceDescriptor resource = res[i];
                if (resource.isCollection()) {
                    try {
                        final EXistCollectionManagementService mgtService = (EXistCollectionManagementService) removeRootCollection.getService(// $NON-NLS-1$
                        "CollectionManagementService", // $NON-NLS-1$
                        "1.0");
                        mgtService.removeCollection(resource.getName());
                    } catch (final XMLDBException e) {
                        showErrorMessage(e.getMessage(), e);
                    }
                } else {
                    try {
                        final Resource res1 = removeRootCollection.getResource(resource.getName().toString());
                        removeRootCollection.removeResource(res1);
                    } catch (final XMLDBException e) {
                        showErrorMessage(e.getMessage(), e);
                    }
                }
                monitor.setProgress(i + 1);
                if (monitor.isCanceled()) {
                    return;
                }
            }
            try {
                removeRootCollection.close();
            } catch (final XMLDBException e) {
                showErrorMessage(e.getMessage(), e);
            }
            try {
                client.getResources();
            } catch (final XMLDBException e) {
                showErrorMessage(e.getMessage(), e);
            }
        };
        client.newClientThread("remove", removeTask).start();
    }
}
Also used : XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 89 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class ClientFrame method editUsersAction.

private void editUsersAction(final ActionEvent ev) {
    try {
        final UserManagementService userManagementService = getUserManagementService();
        final UserManagerDialog userManager = new UserManagerDialog(userManagementService, client.getProperties().getProperty(InteractiveClient.USER), this);
        userManager.setVisible(true);
    } catch (final XMLDBException e) {
        // $NON-NLS-1$
        showErrorMessage(Messages.getString("ClientFrame.185"), e);
        e.printStackTrace();
    }
}
Also used : UserManagerDialog(org.exist.client.security.UserManagerDialog) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 90 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class ClientFrame method setPermAction.

private void setPermAction(final ActionEvent ev) throws PermissionDeniedException {
    if (fileman.getSelectedRowCount() == 0) {
        return;
    }
    try {
        final Collection collection = client.getCollection();
        final UserManagementService service = getUserManagementService();
        String name = null;
        String created = null;
        String modified = null;
        String size = null;
        String messageDigestType = null;
        String messageDigestValue = null;
        String mimeType = null;
        String owner = null;
        String group = null;
        ModeDisplay mode = null;
        SimpleACLPermissionAider acl = null;
        final DateFormat dateTimeFormat = DateFormat.getDateTimeInstance();
        final List<ResourceDescriptor> selected = new ArrayList<>();
        boolean firstPerm = true;
        for (final int row : fileman.getSelectedRows()) {
            final ResourceDescriptor selectedRow = resources.getRow(row);
            selected.add(selectedRow);
            final XmldbURI thisName = selectedRow.getName();
            final String thisCreated;
            final String thisModified;
            final String thisMessageDigestType;
            final String thisMessageDigestValue;
            final String thisSize;
            final String thisMimeType;
            final Permission thisPerm;
            if (selectedRow.isCollection()) {
                final Collection coll = collection.getChildCollection(thisName.toString());
                thisCreated = dateTimeFormat.format(((EXistCollection) coll).getCreationTime());
                thisModified = NON_APPLICABLE;
                thisMimeType = COLLECTION_MIME_TYPE;
                thisMessageDigestType = NON_APPLICABLE;
                thisMessageDigestValue = NON_APPLICABLE;
                thisSize = NON_APPLICABLE;
                thisPerm = service.getPermissions(coll);
            } else {
                final Resource res = collection.getResource(thisName.toString());
                thisCreated = dateTimeFormat.format(((EXistResource) res).getCreationTime());
                thisModified = dateTimeFormat.format(((EXistResource) res).getLastModificationTime());
                thisMimeType = ((EXistResource) res).getMimeType();
                if (res instanceof EXistBinaryResource) {
                    final MessageDigest messageDigest = ((EXistBinaryResource) res).getContentDigest(DigestType.BLAKE_256);
                    thisMessageDigestType = messageDigest.getDigestType().getCommonNames()[0];
                    thisMessageDigestValue = messageDigest.toHexString();
                    thisSize = humanSize(((EXistBinaryResource) res).getContentLength());
                } else {
                    thisMessageDigestType = NON_APPLICABLE;
                    thisMessageDigestValue = NON_APPLICABLE;
                    thisSize = NON_APPLICABLE;
                }
                thisPerm = service.getPermissions(res);
            }
            name = getUpdated(name, () -> URIUtils.urlDecodeUtf8(thisName));
            created = getUpdated(created, thisCreated);
            modified = getUpdated(modified, thisModified);
            mimeType = getUpdated(mimeType, thisMimeType);
            messageDigestType = getUpdated(messageDigestType, thisMessageDigestType);
            messageDigestValue = getUpdated(messageDigestValue, thisMessageDigestValue);
            size = getUpdated(size, thisSize);
            owner = getUpdated(owner, () -> thisPerm.getOwner().getName());
            group = getUpdated(group, () -> thisPerm.getGroup().getName());
            mode = getUpdatedMode(mode, thisPerm);
            if (firstPerm) {
                if (thisPerm instanceof ACLPermission) {
                    final ACLPermission thisAcl = (ACLPermission) thisPerm;
                    acl = new SimpleACLPermissionAider();
                    for (int i = 0; i < thisAcl.getACECount(); i++) {
                        acl.addACE(thisAcl.getACEAccessType(i), thisAcl.getACETarget(i), thisAcl.getACEWho(i), thisAcl.getACEMode(i));
                    }
                } else {
                    acl = null;
                }
                firstPerm = false;
            } else {
                if (acl != null && thisPerm instanceof ACLPermission) {
                    final ACLPermission thisAcl = (ACLPermission) thisPerm;
                    if (!acl.aclEquals(thisAcl)) {
                        acl = null;
                    }
                }
            }
        }
        final EditPropertiesDialog editPropertiesDialog = new EditPropertiesDialog(service, client.getProperties().getProperty(InteractiveClient.USER), collection, name, mimeType, created, modified, size, messageDigestType, messageDigestValue, owner, group, mode, acl, selected);
        editPropertiesDialog.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosed(final WindowEvent e) {
                try {
                    client.reloadCollection();
                } catch (final XMLDBException xmldbe) {
                    // $NON-NLS-1$
                    showErrorMessage(Messages.getString("ClientFrame.197") + xmldbe.getMessage(), xmldbe);
                    xmldbe.printStackTrace();
                }
            }
        });
        editPropertiesDialog.setVisible(true);
    } catch (final XMLDBException e) {
        // $NON-NLS-1$
        showErrorMessage(Messages.getString("ClientFrame.197") + e.getMessage(), e);
        e.printStackTrace();
    }
}
Also used : SimpleACLPermissionAider(org.exist.security.internal.aider.SimpleACLPermissionAider) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) EditPropertiesDialog(org.exist.client.security.EditPropertiesDialog) XMLDBException(org.xmldb.api.base.XMLDBException) ModeDisplay(org.exist.client.security.ModeDisplay) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Collection(org.xmldb.api.base.Collection) MessageDigest(org.exist.util.crypto.digest.MessageDigest)

Aggregations

XMLDBException (org.xmldb.api.base.XMLDBException)174 Collection (org.xmldb.api.base.Collection)66 Resource (org.xmldb.api.base.Resource)34 URISyntaxException (java.net.URISyntaxException)30 XMLResource (org.xmldb.api.modules.XMLResource)30 ResourceSet (org.xmldb.api.base.ResourceSet)23 BuildException (org.apache.tools.ant.BuildException)21 IOException (java.io.IOException)19 XPathException (org.exist.xquery.XPathException)18 PermissionDeniedException (org.exist.security.PermissionDeniedException)16 SAXException (org.xml.sax.SAXException)16 EXistException (org.exist.EXistException)15 UserManagementService (org.exist.xmldb.UserManagementService)15 XPathQueryService (org.xmldb.api.modules.XPathQueryService)13 BinaryResource (org.xmldb.api.modules.BinaryResource)12 ArrayList (java.util.ArrayList)11 Account (org.exist.security.Account)11 EXistResource (org.exist.xmldb.EXistResource)10 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)10 Properties (java.util.Properties)9