/** * Generates an XML document containing metadata information as Property elements. The root of the * document is the element Uploader. * * @return an XML document string containing Property elements. * @throws Exception */ public String generateXml() throws Exception { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.newDocument(); Element rootElem = document.createElement("Uploader"); document.appendChild(rootElem); rootElem.setAttribute("version", xmlVersionNumber); rootElem.setAttribute("uploadDate", ServiceUtils.formatIso8601Date(new Date())); // Add application properties (user inputs and application parameters) to XML document. for (Iterator iter = applicationProperties.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = (Map.Entry) iter.next(); String propertyName = (String) entry.getKey(); String propertyValue = (String) entry.getValue(); rootElem.appendChild( createPropertyElement(document, propertyName, propertyValue, "ApplicationProperty")); } // Add message properties (user inputs and application parameters) to XML document. for (Iterator iter = messageProperties.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = (Map.Entry) iter.next(); String propertyName = (String) entry.getKey(); String propertyValue = (String) entry.getValue(); rootElem.appendChild( createPropertyElement(document, propertyName, propertyValue, "MessageProperty")); } // Add Object request details to XML document. ObjectAndSignatureRequestDetails[] details = (ObjectAndSignatureRequestDetails[]) objectRequestList.toArray( new ObjectAndSignatureRequestDetails[objectRequestList.size()]); for (int i = 0; i < details.length; i++) { ObjectAndSignatureRequestDetails objectDetails = details[i]; rootElem.appendChild(createSignatureRequestElement(document, objectDetails)); } // Serialize XML document to String. StringWriter writer = new StringWriter(); StreamResult streamResult = new StreamResult(writer); DOMSource domSource = new DOMSource(document); TransformerFactory tf = TransformerFactory.newInstance(); Transformer serializer = tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.transform(domSource, streamResult); return writer.toString(); }