Search in sources :

Example 1 with ImportNodeException

use of com.enonic.xp.export.ImportNodeException 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 2 with ImportNodeException

use of com.enonic.xp.export.ImportNodeException 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 3 with ImportNodeException

use of com.enonic.xp.export.ImportNodeException 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 4 with ImportNodeException

use of com.enonic.xp.export.ImportNodeException in project xp by enonic.

the class ExportReader method getNodeSource.

public VirtualFile getNodeSource(final VirtualFile nodeFolder) {
    final VirtualFilePath nodeSourcePath = nodeFolder.getPath().join(SYSTEM_FOLDER_NAME, NODE_XML_EXPORT_NAME);
    final VirtualFile nodeVF = nodeFolder.resolve(nodeSourcePath);
    if (!nodeVF.exists()) {
        throw new ImportNodeException("Missing node source, expected at: " + nodeVF.getPath());
    }
    return nodeVF;
}
Also used : VirtualFile(com.enonic.xp.vfs.VirtualFile) VirtualFilePath(com.enonic.xp.vfs.VirtualFilePath) ImportNodeException(com.enonic.xp.export.ImportNodeException)

Example 5 with ImportNodeException

use of com.enonic.xp.export.ImportNodeException in project xp by enonic.

the class XsltTransformer method create.

public static XsltTransformer create(final ByteSource script, final Map<String, Object> params) {
    final TransformerFactory tf = TransformerFactory.newInstance();
    tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
    tf.setAttribute(XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "");
    try {
        tf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
    } catch (TransformerConfigurationException e) {
        throw new IllegalStateException(e);
    }
    try (InputStream inputStream = script.openStream()) {
        final Transformer transformer = tf.newTransformer(new StreamSource(inputStream));
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        if (params != null) {
            params.forEach(transformer::setParameter);
        }
        return new XsltTransformer(transformer);
    } catch (Exception e) {
        throw new ImportNodeException("Failed to create transformer from path '" + script + "'", e);
    }
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ImportNodeException(com.enonic.xp.export.ImportNodeException) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ImportNodeException(com.enonic.xp.export.ImportNodeException)

Aggregations

ImportNodeException (com.enonic.xp.export.ImportNodeException)5 VirtualFile (com.enonic.xp.vfs.VirtualFile)4 VirtualFilePath (com.enonic.xp.vfs.VirtualFilePath)3 XmlNodeParser (com.enonic.xp.core.impl.export.xml.XmlNodeParser)1 ImportNodeResult (com.enonic.xp.node.ImportNodeResult)1 Node (com.enonic.xp.node.Node)1 NodePath (com.enonic.xp.node.NodePath)1 XmlException (com.enonic.xp.xml.XmlException)1 CharSource (com.google.common.io.CharSource)1 InputStream (java.io.InputStream)1 Transformer (javax.xml.transform.Transformer)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 StreamSource (javax.xml.transform.stream.StreamSource)1