Esempio n. 1
0
 private void removeNodes(NodeList nl) {
   int count = nl.getLength();
   for (int i = 0; i < count; i++) {
     Node node = nl.item(i);
     Node parent = node.getParentNode();
     if (parent == null) continue;
     parent.removeChild(node);
   }
 }
Esempio n. 2
0
 private void appendXmlEntry(Document doc, Node opAppend) {
   NodeList targetNodes = findNodes(doc, opAppend);
   NodeList valueNodes = getValueNodes(opAppend);
   if (targetNodes == null) {
     return;
   }
   int targetNodesCount = targetNodes.getLength();
   for (int i = 0; i < targetNodesCount; i++) {
     Node target = targetNodes.item(i);
     appendNodes(doc, target, valueNodes);
   }
 }
Esempio n. 3
0
 private void setXmlEntry(Document doc, Node opSet) {
   NodeList targetNodes = findNodes(doc, opSet);
   NodeList valueNodes = getValueNodes(opSet);
   if (targetNodes == null) {
     return;
   }
   int targetNodesCount = targetNodes.getLength();
   for (int i = 0; i < targetNodesCount; i++) {
     Node target = targetNodes.item(i);
     for (Node child; (child = target.getFirstChild()) != null; target.removeChild(child)) ;
     appendNodes(doc, target, valueNodes);
   }
 }
Esempio n. 4
0
 private void replaceXmlEntry(Document doc, Node opReplace) {
   NodeList targetNodes = findNodes(doc, opReplace);
   NodeList valueNodes = getValueNodes(opReplace);
   if (targetNodes == null) {
     return;
   }
   int targetNodesCount = targetNodes.getLength();
   for (int i = 0; i < targetNodesCount; i++) {
     Node target = targetNodes.item(i);
     Node parent = target.getParentNode();
     if (parent == null) continue;
     parent.removeChild(target);
     appendNodes(doc, parent, valueNodes);
   }
 }
Esempio n. 5
0
 public void apply(String path, NodeList[] operations)
     throws ParserConfigurationException, TransformerConfigurationException {
   File target = new File(path);
   if (target.isDirectory()) {
     String callerDir = this.targetDir;
     this.targetDir = path;
     for (NodeList ops : operations) {
       for (int i = 0; i < ops.getLength(); i++) call(ops.item(i));
     }
     this.targetDir = callerDir;
   } else {
     String tmpDir = inflate(path);
     if (tmpDir == null) return;
     apply(tmpDir, operations);
     deflate(tmpDir, path);
   }
 }
Esempio n. 6
0
  private void call(String script)
      throws ParserConfigurationException, TransformerConfigurationException {
    File callerScript = this.currentScript;
    Document doc = null;
    try {
      this.currentScript = new File(script);
      DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      doc = db.parse(this.currentScript);
    } catch (Exception ex) {
      this.currentScript = callerScript;
      Utils.onError(new Error.FileParse(script));
      return;
    }

    NodeList operations = doc.getDocumentElement().getChildNodes();
    for (int i = 0; i < operations.getLength(); i++) {
      Node operation = operations.item(i);
      if (operation.getNodeType() != Node.ELEMENT_NODE) continue;
      call(operation);
    }
    this.currentScript = callerScript;
  }
Esempio n. 7
0
 private void appendNodes(Document doc, Node target, NodeList nodes) {
   for (int i = 0; i < nodes.getLength(); i++) {
     Node node = nodes.item(i);
     target.appendChild(doc.importNode(node, true));
   }
 }