Search in sources :

Example 1 with VirtualFile

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);
    }
}
Also used : VirtualFile(com.enonic.xp.vfs.VirtualFile) BinaryReference(com.enonic.xp.util.BinaryReference) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) ImportNodeException(com.enonic.xp.export.ImportNodeException) XmlException(com.enonic.xp.xml.XmlException)

Example 2 with VirtualFile

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();
}
Also used : VirtualFile(com.enonic.xp.vfs.VirtualFile) CharSource(com.google.common.io.CharSource) ImportNodeException(com.enonic.xp.export.ImportNodeException) XmlException(com.enonic.xp.xml.XmlException) Node(com.enonic.xp.node.Node) ImportNodeResult(com.enonic.xp.node.ImportNodeResult) XmlNodeParser(com.enonic.xp.core.impl.export.xml.XmlNodeParser) ImportNodeException(com.enonic.xp.export.ImportNodeException) XmlException(com.enonic.xp.xml.XmlException) NodePath(com.enonic.xp.node.NodePath)

Example 3 with VirtualFile

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;
}
Also used : VirtualFile(com.enonic.xp.vfs.VirtualFile) VirtualFilePath(com.enonic.xp.vfs.VirtualFilePath) ImportNodeException(com.enonic.xp.export.ImportNodeException)

Example 4 with VirtualFile

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;
}
Also used : VirtualFile(com.enonic.xp.vfs.VirtualFile) VirtualFilePath(com.enonic.xp.vfs.VirtualFilePath) ImportNodeException(com.enonic.xp.export.ImportNodeException)

Example 5 with VirtualFile

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;
    }
}
Also used : VirtualFile(com.enonic.xp.vfs.VirtualFile) ImportNodeException(com.enonic.xp.export.ImportNodeException) XmlException(com.enonic.xp.xml.XmlException)

Aggregations

ImportNodeException (com.enonic.xp.export.ImportNodeException)6 VirtualFile (com.enonic.xp.vfs.VirtualFile)6 VirtualFilePath (com.enonic.xp.vfs.VirtualFilePath)3 XmlException (com.enonic.xp.xml.XmlException)3 XmlNodeParser (com.enonic.xp.core.impl.export.xml.XmlNodeParser)1 BinaryAttachment (com.enonic.xp.node.BinaryAttachment)1 ImportNodeResult (com.enonic.xp.node.ImportNodeResult)1 Node (com.enonic.xp.node.Node)1 NodePath (com.enonic.xp.node.NodePath)1 BinaryReference (com.enonic.xp.util.BinaryReference)1 CharSource (com.google.common.io.CharSource)1