Search in sources :

Example 1 with XarSource

use of org.expath.pkg.repo.XarSource in project exist by eXist-db.

the class Deploy method installAndDeploy.

private Optional<String> installAndDeploy(final Txn transaction, final String pkgName, final String version, final String repoURI) throws XPathException {
    try {
        final RepoPackageLoader loader = new RepoPackageLoader(repoURI);
        final Deployment deployment = new Deployment();
        final XarSource xar = loader.load(pkgName, new PackageLoader.Version(version, false));
        if (xar != null) {
            return deployment.installAndDeploy(context.getBroker(), transaction, xar, loader);
        }
        return Optional.empty();
    } catch (final MalformedURLException e) {
        throw new XPathException(this, EXPathErrorCode.EXPDY005, "Malformed URL: " + repoURI);
    } catch (final PackageException | IOException e) {
        LOG.error(e.getMessage(), e);
        throw new XPathException(this, EXPathErrorCode.EXPDY007, e.getMessage());
    }
}
Also used : PackageLoader(org.exist.repo.PackageLoader) XarSource(org.expath.pkg.repo.XarSource) Deployment(org.exist.repo.Deployment) PackageException(org.expath.pkg.repo.PackageException) IOException(java.io.IOException)

Example 2 with XarSource

use of org.expath.pkg.repo.XarSource in project exist by eXist-db.

the class Deploy method installAndDeployFromDb.

private Optional<String> installAndDeployFromDb(final Txn transaction, final String path, final String repoURI) throws XPathException {
    final XmldbURI docPath = XmldbURI.createInternal(path);
    try (final LockedDocument lockedDoc = context.getBroker().getXMLResource(docPath, LockMode.READ_LOCK)) {
        if (lockedDoc == null) {
            throw new XPathException(this, EXPathErrorCode.EXPDY001, path + " no such .xar", new StringValue(path));
        }
        final DocumentImpl doc = lockedDoc.getDocument();
        if (doc.getResourceType() != DocumentImpl.BINARY_FILE) {
            throw new XPathException(this, EXPathErrorCode.EXPDY001, path + " is not a valid .xar", new StringValue(path));
        }
        RepoPackageLoader loader = null;
        if (repoURI != null) {
            loader = new RepoPackageLoader(repoURI);
        }
        final XarSource xarSource = new BinaryDocumentXarSource(context.getBroker().getBrokerPool(), transaction, (BinaryDocument) doc);
        final Deployment deployment = new Deployment();
        return deployment.installAndDeploy(context.getBroker(), transaction, xarSource, loader);
    } catch (PackageException | IOException | PermissionDeniedException e) {
        LOG.error(e.getMessage(), e);
        throw new XPathException(this, EXPathErrorCode.EXPDY007, "Package installation failed: " + e.getMessage(), new StringValue(e.getMessage()));
    }
}
Also used : Deployment(org.exist.repo.Deployment) IOException(java.io.IOException) DocumentImpl(org.exist.dom.persistent.DocumentImpl) XarSource(org.expath.pkg.repo.XarSource) LockedDocument(org.exist.dom.persistent.LockedDocument) PackageException(org.expath.pkg.repo.PackageException) PermissionDeniedException(org.exist.security.PermissionDeniedException) XmldbURI(org.exist.xmldb.XmldbURI)

Aggregations

IOException (java.io.IOException)2 Deployment (org.exist.repo.Deployment)2 PackageException (org.expath.pkg.repo.PackageException)2 XarSource (org.expath.pkg.repo.XarSource)2 DocumentImpl (org.exist.dom.persistent.DocumentImpl)1 LockedDocument (org.exist.dom.persistent.LockedDocument)1 PackageLoader (org.exist.repo.PackageLoader)1 PermissionDeniedException (org.exist.security.PermissionDeniedException)1 XmldbURI (org.exist.xmldb.XmldbURI)1