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();
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations