예제 #1
0
  private Node processNodeSource(
      final VirtualFile nodeFolder, final ProcessNodeSettings.Builder processNodeSettings) {
    final VirtualFile nodeSource = this.exportReader.getNodeSource(nodeFolder);

    final Node.Builder newNodeBuilder = Node.create();
    try {
      final XmlNodeParser parser = new XmlNodeParser();
      parser.builder(newNodeBuilder);
      parser.source(nodeSource.getCharSource());
      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 boolean isNodeExisting = this.nodeService.getByPath(importNodePath) != null;
    final Node importedNode = importNode(nodeFolder, processNodeSettings, newNode, importNodePath);

    if (isNodeExisting) {
      result.updated(importedNode.path());
    } else {
      result.added(importedNode.path());
    }

    return importedNode;
  }
예제 #2
0
  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);
    }
  }
예제 #3
0
  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) {
        processNodeFolder(child, processNodeSettings);
      }

      currentManualOrderValue -= IMPORT_NODE_ORDER_SPACE;
    }
  }
예제 #4
0
  private void processNodeFolder(
      final VirtualFile nodeFolder, final ProcessNodeSettings.Builder processNodeSettings) {
    try {
      final Node node = processNodeSource(nodeFolder, processNodeSettings);

      try {
        if (!node.getChildOrder().isManualOrder()) {
          importFromDirectoryLayout(nodeFolder);
        } else {
          importFromManualOrder(nodeFolder);
        }
      } catch (Exception e) {
        result.addError("Error when parsing children of " + node.path(), e);
      }

    } catch (Exception e) {
      result.addError(
          "Could not import node in folder ["
              + nodeFolder.getPath().getPath()
              + "]: "
              + e.getMessage(),
          e);
    }
  }