use of com.enonic.xp.node.NodePath in project xp by enonic.
the class RestoreContentCommand method doExecute.
private RestoreContentsResult doExecute() {
final Node nodeToRestore = nodeService.getById(NodeId.from(params.getContentId()));
validateLocation(nodeToRestore);
final boolean isRootContent = nodeToRestore.path().asAbsolute().elementCount() == 2;
final NodePath parentPathToRestore = getParentPathToRestore(nodeToRestore, isRootContent);
final String originalSourceName = getOriginalSourceName(nodeToRestore, isRootContent);
final RestoreContentsResult.Builder result = RestoreContentsResult.create();
rename(nodeToRestore, parentPathToRestore, originalSourceName);
final MoveNodeParams.Builder builder = MoveNodeParams.create().nodeId(nodeToRestore.id()).parentNodePath(parentPathToRestore).moveListener(this);
stopInherit(builder);
final Node movedNode = move(builder.build(), originalSourceName);
updateProperties(movedNode, isRootContent);
commitNode(movedNode.id(), ContentConstants.RESTORE_COMMIT_PREFIX);
result.addRestored(ContentId.from(movedNode.id().toString())).parentPath(ContentNodeHelper.translateNodePathToContentPath(parentPathToRestore));
return result.build();
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class NodeImportPathResolver method resolveNodeImportPath.
public static NodePath resolveNodeImportPath(final VirtualFile parent, final VirtualFile exportRoot, final NodePath importRoot) {
final VirtualFilePath parentPath = parent.getPath();
final VirtualFilePath exportRootPath = exportRoot.getPath();
final VirtualFilePath relativePath = parentPath.subtractPath(exportRootPath);
final NodePath.Builder builder = NodePath.create(importRoot);
relativePath.getElements().forEach(builder::addElement);
return builder.build();
}
use of com.enonic.xp.node.NodePath 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.node.NodePath in project xp by enonic.
the class NodeImportPathResolverTest method resolve_child_into_folder.
@Test
public void resolve_child_into_folder() throws Exception {
final NodePath resolvedPath = NodeImportPathResolver.resolveNodeImportPath(//
VirtualFiles.from(Path.of("/var", "folder", "myExport", "mynode", "mychild")), //
VirtualFiles.from(Path.of("/var", "folder", "myExport")), NodePath.create(NodePath.ROOT, "myimport").build());
assertEquals("/myimport/mynode/mychild", resolvedPath.toString());
assertEquals("/myimport/mynode", resolvedPath.getParentPath().toString());
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class NodeImportPathResolverTest method resolve_into_folder.
@Test
public void resolve_into_folder() throws Exception {
final NodePath resolvedPath = //
NodeImportPathResolver.resolveNodeImportPath(//
VirtualFiles.from(Path.of("/var", "folder", "myExport", "mynode")), //
VirtualFiles.from(Path.of("/var", "folder", "myExport")), NodePath.create(NodePath.ROOT, "myimport").build());
assertEquals("/myimport/mynode", resolvedPath.toString());
}
Aggregations