Search in sources :

Example 1 with Repository

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

the class ListFunction method eval.

public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    ValueSequence result = new ValueSequence();
    Optional<ExistRepository> repo = getContext().getRepository();
    if (repo.isPresent()) {
        try {
            Repository parent_repo = repo.get().getParentRepo();
            for (Packages pkg : parent_repo.listPackages()) {
                String name = pkg.name();
                result.add(new StringValue(name));
            }
        } catch (Exception ex) {
            throw new XPathException("Problem listing packages in expath repository ", ex);
        }
        return result;
    } else {
        throw new XPathException("expath repository not available");
    }
}
Also used : Repository(org.expath.pkg.repo.Repository) ExistRepository(org.exist.repo.ExistRepository) XPathException(org.exist.xquery.XPathException) Packages(org.expath.pkg.repo.Packages) ValueSequence(org.exist.xquery.value.ValueSequence) StringValue(org.exist.xquery.value.StringValue) XPathException(org.exist.xquery.XPathException) ExistRepository(org.exist.repo.ExistRepository)

Example 2 with Repository

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

the class RemoveFunction method eval.

public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    Sequence removed = BooleanValue.TRUE;
    boolean force = false;
    UserInteractionStrategy interact = new BatchUserInteraction();
    String pkg = args[0].getStringValue();
    try {
        Optional<ExistRepository> repo = getContext().getRepository();
        if (repo.isPresent()) {
            Repository parent_repo = repo.get().getParentRepo();
            parent_repo.removePackage(pkg, force, interact);
            repo.get().reportAction(ExistRepository.Action.UNINSTALL, pkg);
            context.getBroker().getBrokerPool().getXQueryPool().clear();
        } else {
            throw new XPathException("expath repository not available");
        }
    } catch (PackageException | XPathException pe) {
        return BooleanValue.FALSE;
    // /TODO: _repo.removePackage seems to throw PackageException
    // throw new XPathException("Problem removing package " + pkg + " in expath repository, check that eXist-db has access permissions to expath repository file directory  ", pe);
    }
    return removed;
}
Also used : Repository(org.expath.pkg.repo.Repository) ExistRepository(org.exist.repo.ExistRepository) UserInteractionStrategy(org.expath.pkg.repo.UserInteractionStrategy) XPathException(org.exist.xquery.XPathException) PackageException(org.expath.pkg.repo.PackageException) BatchUserInteraction(org.expath.pkg.repo.tui.BatchUserInteraction) ExistRepository(org.exist.repo.ExistRepository)

Aggregations

ExistRepository (org.exist.repo.ExistRepository)2 XPathException (org.exist.xquery.XPathException)2 Repository (org.expath.pkg.repo.Repository)2 StringValue (org.exist.xquery.value.StringValue)1 ValueSequence (org.exist.xquery.value.ValueSequence)1 PackageException (org.expath.pkg.repo.PackageException)1 Packages (org.expath.pkg.repo.Packages)1 UserInteractionStrategy (org.expath.pkg.repo.UserInteractionStrategy)1 BatchUserInteraction (org.expath.pkg.repo.tui.BatchUserInteraction)1