use of org.expath.pkg.repo.FileSystemStorage.FileSystemResolver in project exist by eXist-db.
the class ExistPkgExtension method setupPackage.
// TODO: Must not be here (in the parsing class). See the comment at the
// end of parseDescriptor().
private void setupPackage(Package pkg, ExistPkgInfo info) throws PackageException {
// TODO: FIXME: Bad, BAD design! But will be resolved naturally by moving the
// install code within the storage class (because we are writing on disk)...
final FileSystemResolver res = (FileSystemResolver) pkg.getResolver();
final Path classpath = res.resolveResourceAsFile(".exist/classpath.txt");
// create [pkg_dir]/.exist/classpath.txt if not already
final Path exist = classpath.getParent();
if (!Files.exists(exist)) {
try {
Files.createDirectories(exist);
} catch (final IOException e) {
throw new PackageException("Impossible to create directory: " + exist);
}
}
final Set<String> jars = info.getJars();
try (final Writer out = Files.newBufferedWriter(classpath)) {
for (final String jar : jars) {
StreamSource jar_src;
try {
jar_src = res.resolveComponent(jar);
} catch (final NotExistException ex) {
final String msg = "Inconsistent package descriptor, the JAR file is not in the package: ";
throw new PackageException(msg + jar, ex);
}
final URI uri = URI.create(jar_src.getSystemId());
final Path file = Paths.get(uri);
out.write(file.normalize().toString());
out.write("\n");
}
} catch (final IOException ex) {
throw new PackageException("Error writing the eXist classpath file: " + classpath, ex);
}
}
use of org.expath.pkg.repo.FileSystemStorage.FileSystemResolver in project exist by eXist-db.
the class ExistRepository method resolveXQueryModule.
/**
* Resolve an XQuery Module.
*
* @param namespace the namespace of the module
* @return the path to the module, or null
*
* @throws XPathException with:
* XQST0046 if the namespace URI is invalid
* XQST0059 if an error occurs loading the module
*/
public Path resolveXQueryModule(final String namespace) throws XPathException {
final URI uri;
try {
uri = new URI(namespace);
} catch (final URISyntaxException ex) {
throw new XPathException(ErrorCodes.XQST0046, "Invalid URI: " + namespace, ex);
}
for (final Packages pp : myParent.listPackages()) {
final Package pkg = pp.latest();
// FIXME: Rely on having a file system storage, that's probably a bad design!
final FileSystemResolver resolver = (FileSystemResolver) pkg.getResolver();
final ExistPkgInfo info = (ExistPkgInfo) pkg.getInfo("exist");
if (info != null) {
final String f = info.getXQuery(uri);
if (f != null) {
return resolver.resolveComponentAsFile(f);
}
}
// declared here to be used in catch
String sysid = null;
Source src = null;
try {
src = pkg.resolve(namespace, URISpace.XQUERY);
if (src != null) {
sysid = src.getSystemId();
return Paths.get(new URI(sysid));
}
} catch (final URISyntaxException ex) {
throw new XPathException(ErrorCodes.XQST0046, "Error parsing the URI of the query library: " + sysid, ex);
} catch (final PackageException ex) {
throw new XPathException(ErrorCodes.XQST0059, "Error resolving the query library: " + namespace, ex);
} finally {
if (src != null && src instanceof StreamSource) {
final StreamSource streamSource = ((StreamSource) src);
try {
if (streamSource.getInputStream() != null) {
streamSource.getInputStream().close();
} else if (streamSource.getReader() != null) {
streamSource.getReader().close();
}
} catch (final IOException e) {
LOG.warn("Unable to close pkg source: {}", e.getMessage(), e);
}
}
}
}
return null;
}
Aggregations