/**
  * Transform the DOM tree using the configuration.
  *
  * @param configuration the transformation configuration.
  * @param doc the DOM tree to be updated.
  */
 protected void applyTransformation(XmlConfiguration configuration, Document doc) {
   List<Parameter> parameters = configuration.getParameters();
   for (Parameter parameter : parameters) {
     displayMessageln("\t" + parameter.getKey() + " (mode:" + parameter.getMode() + ")");
     Node rootXpathNode = getMatchingNode(parameter.getKey(), doc);
     if (rootXpathNode != null) {
       for (Value value : parameter.getValues()) {
         switch (value.getMode()) {
           case XmlTreeHandler.MODE_INSERT:
             {
               createNewNode(doc, rootXpathNode, value);
             }
             break;
           case XmlTreeHandler.MODE_DELETE:
             {
               Node deletedNode = getMatchingNode(value.getLocation(), rootXpathNode);
               rootXpathNode.removeChild(deletedNode);
             }
             break;
           case XmlTreeHandler.MODE_UPDATE:
             {
               Node oldNode = getMatchingNode(value.getLocation(), rootXpathNode);
               if (oldNode == null) {
                 createNewNode(doc, rootXpathNode, value);
               } else {
                 if (rootXpathNode.equals(oldNode)) {
                   rootXpathNode = rootXpathNode.getParentNode();
                 }
                 Node newNode = oldNode.cloneNode(true);
                 if (oldNode instanceof Element) {
                   ((Element) newNode).setTextContent(value.getValue());
                   rootXpathNode.replaceChild(newNode, oldNode);
                 } else {
                   ((Attr) newNode).setValue(value.getValue());
                   rootXpathNode.getAttributes().setNamedItem(newNode);
                 }
               }
               break;
             }
         }
       }
     }
   }
 }
Exemple #2
0
 public static void traceParameter(Parameter parameter) {
   logger.info(String.valueOf(parameter.size()) + "=" + Arrays.toString(parameter.getValues()));
 }