in vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/Importer.java [801:966]
private void prepare(Archive.Entry directory, TxInfo parentInfo, NamespaceResolver resolver)
throws IOException, RepositoryException {
Collection<? extends Archive.Entry> files = directory.getChildren();
// first process the directories
for (Archive.Entry file: files) {
if (file.isDirectory()) {
String fileName = file.getName();
if (isExcluded(fileName)) {
continue;
}
String repoName = PlatformNameFormat.getRepositoryName(fileName);
String repoPath = parentInfo.path + "/" + repoName;
if (repoName.endsWith(".dir")) {
// fix repo path
repoName = repoName.substring(0, repoName.length() - 4);
repoPath = parentInfo.path + "/" + repoName;
}
TxInfo info = parentInfo.addChild(new TxInfo(parentInfo, repoPath));
log.trace("Creating directory artifact for {}", repoName);
Artifact parent = new DirectoryArtifact(repoName);
info.artifacts.add(parent);
Archive.Entry contentXml = file.getChild(Constants.DOT_CONTENT_XML);
if (contentXml != null) {
if (contentXml.isDirectory()) {
throw new IllegalArgumentException(Constants.DOT_CONTENT_XML + " is not a file");
}
// in this case, create a new info
info.artifacts.add(new InputSourceArtifact(
parent,
Constants.DOT_CONTENT_XML,
"",
ArtifactType.PRIMARY,
archive.getInputSource(contentXml),
SerializationType.XML_DOCVIEW
));
} else {
// this is an empty directory and potential intermediate
info.isIntermediate = 1;
intermediates.put(repoPath, info);
log.trace("Detecting intermediate directory {}", repoName);
}
prepare(file, info, resolver);
}
}
// second the files
for (Archive.Entry file: files) {
if (!file.isDirectory()) {
String fileName = file.getName();
if (isExcluded(fileName)) {
continue;
}
String repoName = PlatformNameFormat.getRepositoryName(fileName);
String repoPath = parentInfo.path + "/" + repoName;
if (file.getName().equals(Constants.DOT_CONTENT_XML)) {
continue;
}
if (opts.getPatchDirectory() != null && repoPath.startsWith(opts.getPatchParentPath())) {
patches.add(file);
if (!opts.isPatchKeepInRepo()) {
continue;
}
}
// todo: find better way to detect sub-packages
if (repoPath.startsWith(JcrPackageRegistry.DEFAULT_PACKAGE_ROOT_PATH_PREFIX) && (repoPath.endsWith(".jar") || repoPath.endsWith(".zip"))) {
subPackages.add(repoPath);
}
String repoBase = repoName;
String ext = "";
int idx = repoName.lastIndexOf('.');
if (idx > 0) {
repoBase = repoName.substring(0, idx);
ext = repoName.substring(idx);
}
SerializationType serType = SerializationType.GENERIC;
ArtifactType type = ArtifactType.PRIMARY;
VaultInputSource is = archive.getInputSource(file);
if (".xml".equals(ext)) {
// this can either be an generic exported docview or a 'user-xml' that is imported as file
// btw: this only works for input sources that can refetch their input stream
if (DocViewParser.isDocView(is)) {
// in this case, the extension was added by the exporter.
repoName = repoBase;
serType = SerializationType.XML_DOCVIEW;
} else {
ext = "";
serType = SerializationType.GENERIC;
type = ArtifactType.FILE;
}
} else if (".cnd".equals(ext)) {
if (opts.getCndPattern().matcher(repoPath).matches()) {
InputStream in = is.getByteStream();
try (Reader r = new InputStreamReader(in, "utf8")) {
CNDReader reader = ServiceProviderFactory.getProvider().getCNDReader();
// provide session namespaces
reader.read(r, is.getSystemId(), new NamespaceMapping(resolver));
nodeTypes.add(reader);
log.debug("Loaded nodetypes from {}.", repoPath);
} catch (IOException e1) {
log.error("Error while reading CND.", e1);
}
}
ext = "";
type = ArtifactType.FILE;
} else if (".binary".equals(ext)) {
serType = SerializationType.GENERIC;
type = ArtifactType.BINARY;
repoName = repoBase;
} else {
ext = "";
type = ArtifactType.FILE;
}
if (type != ArtifactType.PRIMARY) {
// check if info already exists (in case of .dir artifacts)
TxInfo parent = parentInfo.children().get(repoName);
if (parent == null) {
if (type == ArtifactType.BINARY) {
// search next parent for binary artifacts
parent = parentInfo;
while (parent != null && parent.isIntermediate > 0) {
parent = parent.parent;
}
if (parent == null) {
log.warn("No parent info found {}. using direct.");
parent = parentInfo;
}
} else {
// "normal" file
TxInfo tx = new TxInfo(parentInfo, parentInfo.path + "/" + repoName);
log.trace("Creating file artifact for {}", repoName);
tx.artifacts.add(new InputSourceArtifact(null,
repoName, ext, type, is, serType
));
parentInfo.addChild(tx);
}
}
if (parent != null) {
String path = parentInfo.path + "/" + repoName;
String relPath = parent.name + path.substring(parent.path.length());
log.trace("Attaching {} artifact {}", type, path);
parent.artifacts.add(new InputSourceArtifact(null,
relPath, ext, type, is, serType
));
}
}
if (type == ArtifactType.PRIMARY) {
// if primary artifact, add new tx info
TxInfo tx = new TxInfo(parentInfo, parentInfo.path + "/" + repoName);
log.trace("Creating primary artifact for {}", repoName);
tx.artifacts.add(new InputSourceArtifact(null,
repoName, ext, type, is, serType
));
parentInfo.addChild(tx);
}
}
}
// sort the child infos according to the workspace filter rules if possible
Tree.Node<PathFilterSet> filterNode = filterTree.getNode(parentInfo.path);
if (filterNode != null) {
parentInfo.sort(filterNode.getChildren().keySet());
}
}