Search in sources :

Example 11 with PackageException

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

the class GetResource method eval.

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    String pkgName = args[0].getStringValue();
    String path = args[1].getStringValue();
    Optional<ExistRepository> repo = context.getRepository();
    if (repo.isPresent()) {
        try {
            for (Packages pp : repo.get().getParentRepo().listPackages()) {
                final Package pkg = pp.latest();
                if (pkg.getName().equals(pkgName)) {
                    try {
                        // FileSystemResolver already returns an input stream
                        StreamSource source = (StreamSource) pkg.getResolver().resolveResource(path);
                        return Base64BinaryDocument.getInstance(context, source.getInputStream());
                    } catch (Storage.NotExistException e) {
                        throw new XPathException(ErrorCodes.FODC0002, "Resource " + path + " does not exist.", e);
                    }
                }
            }
        } catch (PackageException e) {
            throw new XPathException(this, ErrorCodes.FOER0000, "Caught package error while reading expath package");
        }
    } else {
        throw new XPathException("expath repository not available");
    }
    return Sequence.EMPTY_SEQUENCE;
}
Also used : Storage(org.expath.pkg.repo.Storage) XPathException(org.exist.xquery.XPathException) Packages(org.expath.pkg.repo.Packages) StreamSource(javax.xml.transform.stream.StreamSource) PackageException(org.expath.pkg.repo.PackageException) Package(org.expath.pkg.repo.Package) ExistRepository(org.exist.repo.ExistRepository)

Example 12 with PackageException

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

the class ExistPkgExtension method parseDescriptor.

@Override
protected void parseDescriptor(XMLStreamReader parser, Package pkg) throws PackageException {
    myXSHelper.ensureNextElement(parser, "package");
    final ExistPkgInfo info = new ExistPkgInfo(pkg);
    try {
        parser.next();
        while (parser.getEventType() == XMLStreamConstants.START_ELEMENT) {
            if (EXIST_PKG_NS.equals(parser.getNamespaceURI())) {
                handleElement(parser, pkg, info);
            } else {
                // TODO: FIXME: Actually ignore (pass it.)
                throw new PackageException("TODO: Ignore elements in other namespace");
            }
            parser.next();
        }
        // position to </package>
        parser.next();
    } catch (final XMLStreamException ex) {
        throw new PackageException("Error reading the exist descriptor", ex);
    }
    pkg.addInfo(getName(), info);
    // phase though (during the "xrepo install").
    if (!info.getJars().isEmpty()) {
        try {
            pkg.getResolver().resolveResource(".exist/classpath.txt");
        } catch (final NotExistException ex) {
            setupPackage(pkg, info);
        }
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) PackageException(org.expath.pkg.repo.PackageException) NotExistException(org.expath.pkg.repo.Storage.NotExistException)

Aggregations

PackageException (org.expath.pkg.repo.PackageException)12 IOException (java.io.IOException)6 URI (java.net.URI)3 Deployment (org.exist.repo.Deployment)3 ExistRepository (org.exist.repo.ExistRepository)3 URISyntaxException (java.net.URISyntaxException)2 Path (java.nio.file.Path)2 StreamSource (javax.xml.transform.stream.StreamSource)2 Txn (org.exist.storage.txn.Txn)2 XPathException (org.exist.xquery.XPathException)2 Package (org.expath.pkg.repo.Package)2 Packages (org.expath.pkg.repo.Packages)2 NotExistException (org.expath.pkg.repo.Storage.NotExistException)2 XarSource (org.expath.pkg.repo.XarSource)2 Writer (java.io.Writer)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1