/** * writeLink Write both data link or group link depending on the given path. * * @param pnSrcPath path of node targeted by the link * @param prRelPath path of node wearing the link * @throws NexusException */ protected void writeLink(PathNexus pnSrcPath, PathNexus prRelPath) throws NexusException { PathData pdDestNode; // Check the source node is well designed if (pnSrcPath.isRelative()) throw new NexusException("Path is invalid: the targeted path must be absolute!"); // Ensure the wearing node is a DataItem if (prRelPath.getDataItemName() == null) { PathGroup pgDest = new PathGroup(prRelPath.clone()); pdDestNode = new PathData(pgDest, generateDataName((PathGroup) pgDest, DataItem_LINK)); } else pdDestNode = (PathData) prRelPath; // Check the link is valid // PathNexus pnTgtPath = checkRelativeLinkTarget(prRelPath, pdDestNode); // Open path to get the corresponding NXlink openPath(pnSrcPath); NXlink nlLink = getNXlink(); // Create the source path if needed and open it createPath(pdDestNode, true); // Write the link getNexusFile().makenamedlink(pdDestNode.getDataItemName(), nlLink); // Update node list buffer NexusNode nnNode = pdDestNode.getCurrentNode(); pushNodeInBuffer(nnNode.getNodeName(), nnNode.getClassName()); }
/** * checkLinkTarget open the target file and check if pointed data is a DataItem. Returns a string * array of two elements. The first is the attribute to distinguish if a DataItem or nxgroup is * pointed, the seconds is the full sibling path (completed by missing class or names). * * @param prTgtPath pointed node by the link * @param paSrcPath path of the starting node for the relative link * @return the corresponding absolute path if found, else return null */ protected PathNexus checkRelativeLinkTarget(PathNexus prTgtPath, PathData paSrcPath) { PathNexus pnTarget = null; if (paSrcPath.isRelative()) return null; // Construct an absolute path using the source and the target if (!prTgtPath.isRelative()) pnTarget = prTgtPath; // Try to open the requested absolute path try { if (pnTarget == null) { PathRelative prRelTgtPath = new PathRelative(prTgtPath); pnTarget = prRelTgtPath.generateAbsolutePath((PathNexus) paSrcPath); } openPath(pnTarget); pnTarget = getCurrentPath().clone(); closeAll(); return pnTarget; } catch (NexusException ne) { return null; } }