in vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/FileArtifactHandler.java [117:266]
public ImportInfoImpl accept(@NotNull ImportOptions options, boolean isStrictByDefault, WorkspaceFilter wspFilter, Node parent,
String name, ArtifactSetImpl artifacts)
throws RepositoryException, IOException {
// check if any file artifacts was removed
ImportInfoImpl info = null;
Collection<Artifact> removed = artifacts.removed();
for (Artifact a: removed) {
if (a.getType() == ArtifactType.FILE) {
if (parent.hasNode(a.getRelativePath())) {
Node file = parent.getNode(a.getRelativePath());
String path = file.getPath();
// check wsp filter, only remove if 'REPLACE'
if (info == null) {
info = new ImportInfoImpl();
}
if (wspFilter.getImportMode(path) == ImportMode.REPLACE) {
info.onDeleted(path);
file.remove();
} else {
info.onNop(path);
}
}
}
}
// need at least a file or binary artifact
if (artifacts.size(ArtifactType.FILE) > 0 || artifacts.size(ArtifactType.BINARY) > 0) {
// check if the generic handler can import something
Artifact primary = artifacts.getPrimaryData();
if (primary != null) {
if (info == null) {
info = new ImportInfoImpl();
}
// check import mode
ImportMode mode = ImportMode.REPLACE;
String path = PathUtil.getPath(parent, primary.getRelativePath());
if (primary.getRelativePath().length() == 0 || parent.hasNode(primary.getRelativePath())) {
mode = wspFilter.getImportMode(path);
}
// only update if not MERGE (i.e. is REPLACE or UPDATE)
// this is for maintaining backwards-compatibility the rest of the import modes are evaluated in DocViewSAXImporter
if (mode != ImportMode.MERGE) {
InputSource source = primary.getInputSource();
if (source != null) {
info.merge(importDocView(parent, source, artifacts, wspFilter, options));
}
} else {
info.onNop(path);
}
}
// handle files
for (Artifact file: artifacts.values(ArtifactType.FILE)) {
if (info == null) {
info = new ImportInfoImpl();
}
// check type of file artifact
if (file.getSerializationType() == SerializationType.GENERIC
|| file.getSerializationType() == SerializationType.XML_GENERIC) {
// case 1: new file
final String fileName = file.getRelativePath();
if (!parent.hasNode(fileName)) {
importFile(info, parent, file, fileName, false);
} else {
// case 2: same structure, new data
if (file instanceof ImportArtifact) {
Node fileNode = parent.getNode(fileName);
// check import mode, only replace if not MERGE
ImportMode mode = wspFilter.getImportMode(fileNode.getPath());
if (mode != ImportMode.MERGE && mode != ImportMode.MERGE_PROPERTIES) {
if (!fileNode.hasNode(Node.JCR_CONTENT)) {
// apparently no nt:file, recreate file node
fileNode.remove();
importFile(info, parent, file, fileName, parent.hasNode(fileName));
} else {
Node contentNode = fileNode.getNode(Node.JCR_CONTENT);
if (isModifiedNtResource(contentNode)) {
contentNode.remove();
contentNode = fileNode.addNode(Node.JCR_CONTENT, NodeType.NT_RESOURCE);
info.onReplaced(contentNode.getPath());
}
if (!importNtResource(info, contentNode, file)) {
info.onNop(fileNode.getPath());
}
}
} else {
info.onNop(fileNode.getPath());
}
} else {
// do nothing
}
}
} else if (file.getSerializationType() == SerializationType.XML_DOCVIEW) {
// special case for full coverage files below an intermediate node
// this is never used from {@link Importer} but only from {@link TransactionImpl}
String relPath = Text.getRelativeParent(file.getRelativePath(), 1);
String newName = Text.getName(file.getRelativePath());
Node newParent = parent;
if (relPath.length() > 0) {
if (parent.hasNode(relPath)) {
newParent = parent.getNode(relPath);
} else {
throw new IllegalArgumentException("Special docview file can't be imported. parent does not exist: " + parent.getPath() + "/" + relPath);
}
}
ArtifactSetImpl newSet = new ArtifactSetImpl();
newSet.setCoverage(ItemFilterSet.INCLUDE_ALL);
// check import mode
ImportMode mode = ImportMode.REPLACE;
String path = PathUtil.getPath(newParent, newName);
if (newName.length() == 0 || newParent.hasNode(newName)) {
mode = wspFilter.getImportMode(path);
}
if (mode != ImportMode.MERGE) {
info.merge(importDocView(file.getInputSource(), newParent, newName, newSet, wspFilter, options.getIdConflictPolicy()));
} else {
info.onNop(path);
}
} else {
throw new IllegalArgumentException("Files of type " + file.getSerializationType() + " can't be handled by this handler " + this);
}
}
ValueFactory factory = parent.getSession().getValueFactory();
for (Artifact binary: artifacts.values(ArtifactType.BINARY)) {
// get parent node
Node parentNode = parent;
String path = binary.getRelativePath();
int idx = path.lastIndexOf('/');
if (idx > 0) {
parentNode = parent.getNode(path.substring(0, idx));
path = path.substring(idx + 1);
}
// only update binary if import mode is not MERGE (because binaries have only mandatory properties)
ImportMode mode = wspFilter.getImportMode(parentNode.getPath());
if (mode != ImportMode.MERGE && mode != ImportMode.MERGE_PROPERTIES) {
Value value = factory.createValue(binary.getInputStream());
if (!parentNode.hasProperty(path)
|| !value.equals(parentNode.getProperty(path).getValue())) {
parent.setProperty(path, value);
if (info == null) {
info = new ImportInfoImpl();
}
info.onModified(path);
info.onModified(parentNode.getPath());
}
}
}
}
return info;
}