use of com.enonic.xp.vfs.VirtualFile in project xp by enonic.
the class NodeImporter method addBinary.
private void addBinary(final VirtualFile nodeFile, final BinaryAttachments.Builder builder, final Property binaryRefProperty) {
final BinaryReference binaryReference = binaryRefProperty.getBinaryReference();
try {
final VirtualFile binary = exportReader.getBinarySource(nodeFile, binaryReference.toString());
builder.add(new BinaryAttachment(binaryReference, binary.getByteSource()));
result.addBinary(binary.getPath().getPath(), binaryReference);
} catch (Exception e) {
result.addError("Error processing binary, skip", e);
}
}
use of com.enonic.xp.vfs.VirtualFile in project xp by enonic.
the class NodeImporter method processNodeSource.
private Node processNodeSource(final VirtualFile nodeFolder, final ProcessNodeSettings.Builder processNodeSettings) {
final VirtualFile nodeSource = this.exportReader.getNodeSource(nodeFolder);
final CharSource nodeCharSource;
try {
nodeCharSource = transformer == null ? nodeSource.getCharSource() : CharSource.wrap(this.transformer.transform(nodeSource.getCharSource()));
} catch (Exception e) {
throw new ImportNodeException("Error during XSLT pre-processing for node in '" + nodeSource.getUrl() + "'", e);
}
final Node.Builder newNodeBuilder = Node.create();
try {
final XmlNodeParser parser = new XmlNodeParser();
parser.builder(newNodeBuilder);
parser.source(nodeCharSource);
parser.parse();
} catch (final Exception e) {
throw new XmlException(e, "Could not load source node [" + nodeSource.getUrl() + "]: ", e);
}
final Node newNode = newNodeBuilder.build();
final NodePath importNodePath = NodeImportPathResolver.resolveNodeImportPath(nodeFolder, this.exportRoot, this.importRoot);
final ImportNodeResult importNodeResult = importNode(nodeFolder, processNodeSettings, newNode, importNodePath);
if (nodeImportListener != null) {
nodeImportListener.nodeImported(1L);
}
if (importNodeResult.isPreExisting()) {
result.updated(importNodeResult.getNode().path());
} else {
result.added(importNodeResult.getNode().path());
}
return importNodeResult.getNode();
}
use of com.enonic.xp.vfs.VirtualFile in project xp by enonic.
the class ExportReader method getOrderSource.
public VirtualFile getOrderSource(final VirtualFile nodeFolder) {
final VirtualFilePath orderSourcePath = nodeFolder.getPath().join(SYSTEM_FOLDER_NAME, ORDER_EXPORT_NAME);
final VirtualFile orderFile = nodeFolder.resolve(orderSourcePath);
if (!orderFile.exists()) {
throw new ImportNodeException("Parent has manual ordering of children, expected at:" + orderFile.getPath());
}
return orderFile;
}
use of com.enonic.xp.vfs.VirtualFile in project xp by enonic.
the class ExportReader method getBinarySource.
public VirtualFile getBinarySource(final VirtualFile nodeFolder, final String binaryReferenceString) {
final VirtualFilePath binaryFilePath = nodeFolder.getPath().join(SYSTEM_FOLDER_NAME, BINARY_FOLDER, binaryReferenceString);
final VirtualFile binaryFile = nodeFolder.resolve(binaryFilePath);
if (!binaryFile.exists()) {
throw new ImportNodeException("Missing binary source, expected at: " + binaryFile.getPath());
}
return binaryFile;
}
use of com.enonic.xp.vfs.VirtualFile in project xp by enonic.
the class NodeImporter method importFromManualOrder.
private void importFromManualOrder(final VirtualFile nodeFolder) {
final List<String> childNames;
try {
final List<String> relativeChildNames = processBinarySource(nodeFolder);
childNames = getChildrenAbsolutePaths(nodeFolder, relativeChildNames);
} catch (Exception e) {
result.addError("Not able to import nodes by manual order, using default ordering", e);
importFromDirectoryLayout(nodeFolder);
return;
}
long currentManualOrderValue = IMPORT_NODE_ORDER_START_VALUE;
for (final String childName : childNames) {
final VirtualFile child = nodeFolder.resolve(VirtualFilePaths.from(childName, "/"));
final ProcessNodeSettings.Builder processNodeSettings = ProcessNodeSettings.create().insertManualStrategy(InsertManualStrategy.MANUAL).manualOrderValue(currentManualOrderValue);
if (child != null && child.exists()) {
processNodeFolder(child, processNodeSettings);
}
currentManualOrderValue -= IMPORT_NODE_ORDER_SPACE;
}
}
Aggregations