if (path != null && path.length() > 0) {
runQuery(null, packageDir, path, true);
return null;
} else {
// otherwise copy all child directories to the target collection
XmldbURI targetCollection = null;
if (userTarget != null) {
try {
targetCollection = XmldbURI.create(userTarget);
} catch (final Exception e) {
throw new PackageException("Bad collection URI: " + userTarget, e);
}
} else {
final ElementImpl target = findElement(repoXML, TARGET_COLL_ELEMENT);
if (target != null) {
final String targetPath = target.getStringValue();
if (targetPath.length() > 0) {
// determine target collection
try {
targetCollection = XmldbURI.create(getTargetCollection(targetPath));
} catch (final Exception e) {
throw new PackageException("Bad collection URI for <target> element: " + target.getStringValue(), e);
}
}
}
}
if (targetCollection == null) {
// no target means: package does not need to be deployed into database
// however, we need to preserve a copy for backup purposes
final Package pkg = getPackage(pkgName, repo);
final String pkgColl = pkg.getAbbrev() + "-" + pkg.getVersion();
targetCollection = XmldbURI.SYSTEM.append("repo/" + pkgColl);
}
final ElementImpl permissions = findElement(repoXML, PERMISSIONS_ELEMENT);
if (permissions != null) {
// get user, group and default permissions
user = permissions.getAttribute("user");
group = permissions.getAttribute("group");
password = permissions.getAttribute("password");
String mode = permissions.getAttribute("mode");
try {
perms = Integer.parseInt(mode, 8);
} catch (final NumberFormatException e) {
permsStr = mode;
if (!permsStr.matches("^[rwx-]{9}"))
{throw new PackageException("Bad format for mode attribute in <permissions>: " + mode);}
}
}
// run the pre-setup query if present
final ElementImpl preSetup = findElement(repoXML, PRE_SETUP_ELEMENT);
if (preSetup != null) {
path = preSetup.getStringValue();
if (path.length() > 0)
{runQuery(targetCollection, packageDir, path, true);}
}
// any required users and group should have been created by the pre-setup query.
// check for invalid users now.
checkUserSettings();
// install
scanDirectory(packageDir, targetCollection, true);
// run the post-setup query if present
final ElementImpl postSetup = findElement(repoXML, POST_SETUP_ELEMENT);
if (postSetup != null) {
path = postSetup.getStringValue();
if (path.length() > 0)
{runQuery(targetCollection, packageDir, path, false);}
}
storeRepoXML(repoXML, targetCollection);
// TODO: it should be save to clean up the file system after a package
// has been deployed. Might be enabled after 2.0
//cleanup(pkgName, repo);
return targetCollection.getCollectionPath();
}
} catch (final XPathException e) {
throw new PackageException("Error found while processing repo.xml: " + e.getMessage(), e);
}
}