Ejemplo n.º 1
0
 /**
  * copyAttr Copy the named attribute of the current source node into the current node
  *
  * @param sAttrName name of the attribute to be copied
  * @param nfrSource handler on the opened source file
  */
 protected void copyAttr(String sAttrName, NexusFileReader nfrSource) throws NexusException {
   PathNexus pnSrcPath = nfrSource.getCurrentRealPath().clone();
   PathNexus pnTgtPath = getCurrentRealPath().clone();
   writeAttr(sAttrName, nfrSource.readAttr(sAttrName, pnSrcPath), getCurrentRealPath());
   openPath(pnTgtPath);
   nfrSource.openPath(pnSrcPath);
 }
Ejemplo n.º 2
0
  /**
   * CopyNode make a full copy of the current source node (itself and its descendants) into the
   * currently opened destination path. The copy cares of all nodes' attributes.
   *
   * @param nfrSource handler on the opened source file
   */
  protected void copyNode(NexusFileReader nfrSource) throws NexusException {
    // Keep in buffer current path (used for recursion process)
    PathNexus pnSrcPath = nfrSource.getCurrentRealPath().clone();
    PathNexus pnTgtPath = getCurrentRealPath().clone();
    NexusNode nnCurNode = pnSrcPath.getCurrentNode();

    if (getCurrentRealPath().getCurrentNode() != null
        && !getCurrentRealPath().getCurrentNode().isRealGroup())
      throw new NexusException(
          "Invalid destination path: only a group can contain nodes!\n" + getCurrentRealPath());

    // Check the kind of the node
    if (nnCurNode == null
        || nnCurNode.isGroup()
        || "NXtechnical_data".equals(nnCurNode.getClassName())) {
      // Copy the current group
      PathNexus pnPath = pnTgtPath.clone();
      if (nnCurNode != null) pnPath.pushNode(nnCurNode);
      createPath(pnPath, true);
      copyAllAttr(nfrSource);

      // Copy all its descendants
      ArrayList<NexusNode> nodes = nfrSource.listChildren();
      for (NexusNode node : nodes) {
        nfrSource.openNode(node);
        copyNode(nfrSource);
      }
    } else {
      // Copy the current DataItem
      PathData pdDstPath = new PathData(pnTgtPath.getNodes(), nnCurNode.getNodeName());
      DataItem dsData = nfrSource.getDataItem();
      writeData(dsData, pdDstPath);
    }

    // Return back to the original position in both source and destination files
    closeAll();
    openPath(pnTgtPath);
    nfrSource.closeAll();
    nfrSource.openPath(pnSrcPath.getParentPath());
  }