Source:
private void performTransformations() throws Exception { if (this.transformations == null) { return; } unpackTransformedXARs(); SAXReader reader = new SAXReader(); for (Transformation transformation : this.transformations) { File file = new File(this.project.getBuild().getOutputDirectory(), transformation.getFile()); Document document = reader.read(file); Node node = document.selectSingleNode(transformation.getXpath()); if (node != null) { String value = transformation.getValue(); if (value != null) { String currentValue = node.getText(); node.setText(value.replace("$1", currentValue)); } else if (transformation.getAction() != null) { Document xmlDocument = null; Element xmlElement = null; File content = null; if (transformation.getXml() != null) { xmlDocument = reader.read(transformation.getXml()); xmlElement = xmlDocument.getRootElement(); } else if (transformation.getContent() != null) { content = transformation.getContent(); } switch (transformation.getAction()) { case INSERT_CHILD: ((Element) node).add(xmlElement); break; case REPLACE: Element parent = node.getParent(); if (parent == null) { document = xmlDocument; } else { List<Element> siblings = parent.elements(); siblings.set(parent.indexOf(node), xmlElement); } break; case INSERT_ATTACHMENT_CONTENT: if(content != null) { node.selectSingleNode("filesize").setText(Long.toString(content.length(),10)); node.selectSingleNode("content").setText( "\r\n" + new String( Base64.getMimeEncoder().encode(FileUtils.readFileToByteArray(content)), StandardCharsets.ISO_8859_1) + "\r\n"); } break; case INSERT_TEXT: if( content != null) { node.setText(FileUtils.readFileToString(content, "utf-8")); } break; case REMOVE: node.getParent().remove(node); break; default: break; } } XMLWriter writer = new XMLWriter(new FileOutputStream(file)); writer.write(document); writer.flush(); writer.close(); } else { getLog().warn("Can't find any node matching the xpath [" + transformation.getXpath() + "]"); } } }

Target:
private void performTransformations() throws Exception { if (this.transformations == null) { return; } unpackTransformedXARs(); SAXReader reader = new SAXReader(); for (Transformation transformation : this.transformations) { File file = new File(this.project.getBuild().getOutputDirectory(), transformation.getFile()); Document document = reader.read(file); Node node = document.selectSingleNode(transformation.getXpath()); if (node != null) { String value = transformation.getValue(); if (value != null) { String currentValue = node.getText(); node.setText(value.replace("$1", currentValue)); } else if (transformation.getAction() != null) { Document xmlDocument = null; Element xmlElement = null; File content = null; if (transformation.getXml() != null) { xmlDocument = reader.read(transformation.getXml()); xmlElement = xmlDocument.getRootElement(); } else if (transformation.getContent() != null) { content = transformation.getContent(); } switch (transformation.getAction()) { case INSERT_CHILD: ((Element) node).add(xmlElement); break; case REPLACE: Element parent = node.getParent(); if (parent == null) { document = xmlDocument; } else { List<Element> siblings = parent.elements(); siblings.set(parent.indexOf(node), xmlElement); } break; case INSERT_ATTACHMENT_CONTENT: if(content != null) { node.selectSingleNode("filesize").setText(Long.toString(content.length(),10)); node.selectSingleNode("content").setText( "\r\n" + new String( Base64.getMimeEncoder().encode(FileUtils.readFileToByteArray(content))) + "\r\n"); } break; case INSERT_TEXT: if( content != null) { node.setText(FileUtils.readFileToString(content, Charset.forName(transformation.getCharset()))); } break; case REMOVE: node.getParent().remove(node); break; default: break; } } XMLWriter writer = new XMLWriter(new FileOutputStream(file)); writer.write(document); writer.flush(); writer.close(); } else { getLog().warn("Can't find any node matching the xpath [" + transformation.getXpath() + "]"); } } }