Example usage for org.w3c.dom Document createElementNS

List of usage examples for org.w3c.dom Document createElementNS

Introduction

In this page you can find the example usage for org.w3c.dom Document createElementNS.

Prototype

public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException;

Source Link

Document

Creates an element of the given qualified name and namespace URI.

Usage

From source file:cz.incad.kramerius.service.replication.ExternalReferencesFormat.java

private void changeDatastreamVersion(Document document, Element datastream, Element version, URL url)
        throws IOException {
    InputStream is = null;//from w  w  w.  j  a  v  a  2s. com
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        URLConnection urlConnection = url.openConnection();
        is = urlConnection.getInputStream();
        IOUtils.copyStreams(is, bos);
        version.setAttribute("SIZE", "" + bos.size());
        version.removeChild(XMLUtils.findElement(version, "contentLocation", version.getNamespaceURI()));
        Element binaryContent = document.createElementNS(version.getNamespaceURI(), "binaryContent");
        document.adoptNode(binaryContent);
        binaryContent.setTextContent(new String(Base64.encodeBase64(bos.toByteArray())));
        version.appendChild(binaryContent);

        datastream.setAttribute("CONTROL_GROUP", "M");

    } finally {
        IOUtils.tryClose(is);
    }
}

From source file:de.xplib.xdbm.util.Config.java

/**
 * // w ww .j  a va  2  s  . c o  m
 */
public void save() {

    Document doc = null;
    try {
        doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

        Element config = (Element) doc.appendChild(doc.createElementNS(CONFIG_NS, "config"));
        config.setAttribute("xmlns", CONFIG_NS);

        Element ui = (Element) config.appendChild(doc.createElementNS(CONFIG_NS, "ui-settings"));

        Node lang = ui.appendChild(doc.createElementNS(CONFIG_NS, "language"));
        lang.appendChild(doc.createTextNode(this.locale.getLanguage()));

        Element drivers = (Element) config.appendChild(doc.createElementNS(CONFIG_NS, "drivers"));
        Iterator dIt = this.dbDrivers.keySet().iterator();
        while (dIt.hasNext()) {

            String jar = (String) dIt.next();

            Element driver = (Element) drivers.appendChild(doc.createElementNS(CONFIG_NS, "driver"));

            driver.setAttribute("jar", jar);
            driver.setAttribute("class", (String) this.dbDrivers.get(jar));

            if (!this.dbUris.containsKey(jar)) {
                continue;
            }

            String value = "";

            ArrayList uris = (ArrayList) this.dbUris.get(jar);
            for (int i = 0, l = uris.size(); i < l; i++) {
                value += uris.get(i) + "||";
            }
            value = value.substring(0, value.length() - 2);

            driver.setAttribute("uris", value);
        }

        Element conns = (Element) config.appendChild(doc.createElementNS(CONFIG_NS, "connections"));

        for (int i = 0, s = this.connections.size(); i < s; i++) {

            Connection conn = (Connection) this.connections.get(i);

            Element conne = (Element) conns.appendChild(doc.createElementNS(CONFIG_NS, "connection"));
            conne.setAttribute("jar", conn.getJarFile());
            conne.setAttribute("class", conn.getClassName());
            conne.setAttribute("uri", conn.getUri());
        }

        Element panels = (Element) config.appendChild(doc.createElementNS(CONFIG_NS, "plugins"));

        Iterator it = this.plugins.keySet().iterator();
        while (it.hasNext()) {

            PluginFile pluginFile = (PluginFile) this.plugins.get(it.next());

            Element elem = (Element) panels.appendChild(doc.createElementNS(CONFIG_NS, "plugin"));
            elem.setAttribute("jar", pluginFile.getJarFile());
            elem.setAttribute("class", pluginFile.getClassName());
            elem.setAttribute("id", pluginFile.getId());
            elem.setAttribute("position", pluginFile.getPosition());
        }
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }

    if (doc != null) {

        OutputFormat of = new OutputFormat(doc);
        of.setIndenting(true);
        of.setIndent(1);
        of.setStandalone(true);

        StringWriter sw = new StringWriter();
        XMLSerializer xs = new XMLSerializer(sw, of);
        xs.setOutputCharStream(sw);

        try {
            xs.serialize(doc);

            sw.flush();

            System.out.println(sw.toString());

            sw.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        try {
            FileWriter fw = new FileWriter(this.cfgFile);
            fw.write(sw.toString());
            fw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:de.betterform.xml.xforms.ui.Repeat.java

/**
 * Initializes this repeat.//w  w  w  . j av  a  2s. c  o  m
 * <p/>
 * The repeat prototype is cloned and removed from the document. The data
 * element is initialized with the prototype data.
 */
protected void initializePrototype() throws XFormsException {
    // create prototype element
    Document document = this.element.getOwnerDocument();
    this.prototype = document.createElementNS(NamespaceConstants.XFORMS_NS,
            (this.xformsPrefix != null ? this.xformsPrefix : NamespaceConstants.XFORMS_PREFIX) + ":" + GROUP);
    this.prototype.setAttributeNS(null, "id", this.container.generateId());
    this.prototype.setAttributeNS(null, APPEARANCE_ATTRIBUTE, "repeated");

    // clone repeat prototype
    NodeList children = this.element.getChildNodes();
    for (int index = 0; index < children.getLength(); index++) {
        initializePrototype(this.prototype, children.item(index));
    }

    // remove repeat prototype
    DOMUtil.removeAllChildren(this.element);
}

From source file:com.microsoft.windowsazure.management.scheduler.CloudServiceManagementClientImpl.java

/**
* EntitleResource is used only for 3rd party Store providers. Each
* subscription must be entitled for the resource before creating that
* particular type of resource.//from w ww  .j  a  va 2 s. c  o  m
*
* @param parameters Required. Parameters provided to the EntitleResource
* method.
* @throws ParserConfigurationException Thrown if there was an error
* configuring the parser for the response body.
* @throws SAXException Thrown if there was an error parsing the response
* body.
* @throws TransformerException Thrown if there was an error creating the
* DOM transformer.
* @throws IOException Signals that an I/O exception of some sort has
* occurred. This class is the general class of exceptions produced by
* failed or interrupted I/O operations.
* @throws ServiceException Thrown if an unexpected response is found.
* @return A standard service response including an HTTP status code and
* request ID.
*/
@Override
public OperationResponse entitleResource(EntitleResourceParameters parameters)
        throws ParserConfigurationException, SAXException, TransformerException, IOException, ServiceException {
    // Validate
    if (parameters == null) {
        throw new NullPointerException("parameters");
    }
    if (parameters.getResourceNamespace() == null) {
        throw new NullPointerException("parameters.ResourceNamespace");
    }
    if (parameters.getResourceType() == null) {
        throw new NullPointerException("parameters.ResourceType");
    }

    // Tracing
    boolean shouldTrace = CloudTracing.getIsEnabled();
    String invocationId = null;
    if (shouldTrace) {
        invocationId = Long.toString(CloudTracing.getNextInvocationId());
        HashMap<String, Object> tracingParameters = new HashMap<String, Object>();
        tracingParameters.put("parameters", parameters);
        CloudTracing.enter(invocationId, this, "entitleResourceAsync", tracingParameters);
    }

    // Construct URL
    String url = "";
    if (this.getCredentials().getSubscriptionId() != null) {
        url = url + URLEncoder.encode(this.getCredentials().getSubscriptionId(), "UTF-8");
    }
    url = url + "/EntitleResource";
    String baseUrl = this.getBaseUri().toString();
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl.charAt(baseUrl.length() - 1) == '/') {
        baseUrl = baseUrl.substring(0, (baseUrl.length() - 1) + 0);
    }
    if (url.charAt(0) == '/') {
        url = url.substring(1);
    }
    url = baseUrl + "/" + url;
    url = url.replace(" ", "%20");

    // Create HTTP transport objects
    HttpPost httpRequest = new HttpPost(url);

    // Set Headers
    httpRequest.setHeader("Content-Type", "application/xml");
    httpRequest.setHeader("x-ms-version", "2013-03-01");

    // Serialize Request
    String requestContent = null;
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document requestDoc = documentBuilder.newDocument();

    Element entitleResourceElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "EntitleResource");
    requestDoc.appendChild(entitleResourceElement);

    Element resourceProviderNameSpaceElement = requestDoc
            .createElementNS("http://schemas.microsoft.com/windowsazure", "ResourceProviderNameSpace");
    resourceProviderNameSpaceElement.appendChild(requestDoc.createTextNode(parameters.getResourceNamespace()));
    entitleResourceElement.appendChild(resourceProviderNameSpaceElement);

    Element typeElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure", "Type");
    typeElement.appendChild(requestDoc.createTextNode(parameters.getResourceType()));
    entitleResourceElement.appendChild(typeElement);

    Element registrationDateElement = requestDoc.createElementNS("http://schemas.microsoft.com/windowsazure",
            "RegistrationDate");
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSS'Z'");
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    registrationDateElement.appendChild(
            requestDoc.createTextNode(simpleDateFormat.format(parameters.getRegistrationDate().getTime())));
    entitleResourceElement.appendChild(registrationDateElement);

    DOMSource domSource = new DOMSource(requestDoc);
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(domSource, streamResult);
    requestContent = stringWriter.toString();
    StringEntity entity = new StringEntity(requestContent);
    httpRequest.setEntity(entity);
    httpRequest.setHeader("Content-Type", "application/xml");

    // Send Request
    HttpResponse httpResponse = null;
    try {
        if (shouldTrace) {
            CloudTracing.sendRequest(invocationId, httpRequest);
        }
        httpResponse = this.getHttpClient().execute(httpRequest);
        if (shouldTrace) {
            CloudTracing.receiveResponse(invocationId, httpResponse);
        }
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode != HttpStatus.SC_ACCEPTED) {
            ServiceException ex = ServiceException.createFromXml(httpRequest, requestContent, httpResponse,
                    httpResponse.getEntity());
            if (shouldTrace) {
                CloudTracing.error(invocationId, ex);
            }
            throw ex;
        }

        // Create Result
        OperationResponse result = null;
        // Deserialize Response
        result = new OperationResponse();
        result.setStatusCode(statusCode);
        if (httpResponse.getHeaders("x-ms-request-id").length > 0) {
            result.setRequestId(httpResponse.getFirstHeader("x-ms-request-id").getValue());
        }

        if (shouldTrace) {
            CloudTracing.exit(invocationId, result);
        }
        return result;
    } finally {
        if (httpResponse != null && httpResponse.getEntity() != null) {
            httpResponse.getEntity().getContent().close();
        }
    }
}

From source file:com.idega.slide.util.WebdavLocalResource.java

@SuppressWarnings("deprecation")
private Enumeration<LocalResponse> propfindMethod(NodeRevisionDescriptor descriptor)
        throws HttpException, IOException {
    if (descriptor == null) {
        return null;
    }// w  ww. j  av  a 2s  .  c o m

    if (properties != null) {
        return properties;
    }

    try {
        Vector<LocalResponse> responses = new Vector<LocalResponse>();
        LocalResponse response = new LocalResponse();
        response.setHref(getPath());
        responses.add(response);

        @SuppressWarnings("unchecked")
        List<NodeProperty> nodeProperties = Collections.list(descriptor.enumerateProperties());
        List<Property> properties = new ArrayList<Property>();
        for (NodeProperty p : nodeProperties) {
            String localName = p.getPropertyName().getName();
            Property property = null;

            if (localName.equals(RESOURCETYPE)) {
                Object oValue = p.getValue();
                String value = oValue == null ? null : oValue.toString();

                Element element = null;
                if ("<collection/>".equals(value)) {
                    element = getCollectionElement();
                } else if (CoreConstants.EMPTY.equals(value)) {
                    element = getEmptyElement();
                } else {
                    Document doc = XmlUtil.getDocumentBuilder().newDocument();
                    String namespace = p.getNamespace();
                    String tagName = p.getName();
                    element = doc.createElementNS(namespace, tagName);
                    element.appendChild(doc.createTextNode(value));
                }

                property = new ResourceTypeProperty(response, element);
            } else if (localName.equals(LOCKDISCOVERY)) {
                /*DocumentBuilderFactory factory =
                 DocumentBuilderFactory.newInstance();
                 factory.setNamespaceAware(true);
                 DocumentBuilder builder = factory.newDocumentBuilder();
                 Document doc = builder.newDocument();
                 Element element = doc.createElement("collection");
                 property = new LockDiscoveryProperty(response,element);*/
                throw new RuntimeException("LockDiscoveryProperty not yet implemented for: " + getPath());
            } else if (CREATIONDATE.equals(localName)) {
                setCreationDate((String) p.getValue());
            } else if (GETLASTMODIFIED.equals(localName)) {
                setGetLastModified((String) p.getValue());
            } else {
                LocalProperty lProperty = new LocalProperty(response);
                property = lProperty;
                lProperty.setName(p.getName());
                lProperty.setNamespaceURI(p.getNamespace());
                lProperty.setLocalName(p.getName());
                Object oValue = p.getValue();
                String value = oValue == null ? null : oValue.toString();
                lProperty.setPropertyAsString(value);
            }

            if (property != null) {
                properties.add(property);
            }
        }

        if (!ListUtil.isEmpty(properties)) {
            response.setProperties(new Vector<Property>(properties));
        }

        this.properties = responses.elements();
        if (this.properties != null) {
            setProperties(3, 0); //   Need to set basic properties
        }

        return this.properties;
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error getting properties for: " + getPath() + ": " + e.getMessage(), e);

        if (e instanceof ObjectNotFoundException) {
            getSlideAPI().deletetDefinitionFile(((ObjectNotFoundException) e).getObjectUri());

            HttpException he = new HttpException("Resource on path: " + getPath() + " not found");
            he.setReasonCode(WebdavStatus.SC_NOT_FOUND);
            throw he;
        } else if (e instanceof RevisionDescriptorNotFoundException) {
            getSlideAPI().deletetDefinitionFile(((RevisionDescriptorNotFoundException) e).getObjectUri());
        }

        return null;
    }
}

From source file:com.amalto.core.history.accessor.ManyFieldAccessor.java

public void create() {
    parent.create();/*w w  w .j  a  v  a 2s.c om*/

    // TODO Refactor this
    Document domDocument = document.asDOM();
    Node node = getCollectionItemNode();
    if (node == null) {
        Element parentNode = (Element) parent.getNode();
        NodeList children = parentNode.getElementsByTagName(fieldName);
        int currentCollectionSize = children.getLength();
        if (currentCollectionSize > 0) {
            Node refNode = children.item(currentCollectionSize - 1).getNextSibling();
            while (currentCollectionSize <= index) {
                node = domDocument.createElementNS(domDocument.getNamespaceURI(), fieldName);
                parentNode.insertBefore(node, refNode);
                currentCollectionSize++;
            }
        } else {
            // Collection is not present at all, append at the end of parent element.
            Node lastAccessedNode = document.getLastAccessedNode();
            if (lastAccessedNode != null) {
                Node refNode = lastAccessedNode.getNextSibling();
                while (refNode != null && !(refNode instanceof Element)) {
                    refNode = refNode.getNextSibling();
                }
                while (currentCollectionSize <= index) {
                    node = domDocument.createElementNS(domDocument.getNamespaceURI(), fieldName);
                    if (lastAccessedNode == parentNode) {
                        if (lastAccessedNode == document.asDOM().getDocumentElement()
                                && lastAccessedNode.getChildNodes().getLength() > 0)
                            parentNode.insertBefore(node, parentNode.getFirstChild());
                        else
                            parentNode.appendChild(node);
                    } else if (refNode != null && refNode.getParentNode() == parentNode) {
                        parentNode.insertBefore(node, refNode);
                    } else {
                        parentNode.appendChild(node);
                    }
                    currentCollectionSize++;
                }
            } else {
                while (currentCollectionSize <= index) {
                    node = domDocument.createElementNS(domDocument.getNamespaceURI(), fieldName);
                    parentNode.appendChild(node);
                    currentCollectionSize++;
                }
            }
        }
        document.setLastAccessedNode(node);
    } else if (node.getChildNodes().getLength() == 0) {
        // This accessor creates (n-1) empty elements when accessing first collection element at index n.
        // This setLastAccessedNode call allows all (n-1) elements to find their parent.
        if (!(node.getLocalName().equals(document.getLastAccessedNode().getLocalName())
                && document.getLastAccessedNode().getParentNode() == node.getParentNode())) {
            // if last accessed node is parallel with this node, can't modify last accessed node. eg, last accessed
            // node=/feature/vendor[2], this node=/feature/vendor[1], the last accessed is still /feature/vendor[2]
            document.setLastAccessedNode(node);
        }
    }
}

From source file:com.verisign.epp.codec.gen.EPPUtil.java

/**
 * DOCUMENT ME!/*from w w  w.j a va 2s. c  om*/
 * 
 * @param aDocument
 *            DOCUMENT ME!
 * @param aRoot
 *            DOCUMENT ME!
 * @param aNS
 *            DOCUMENT ME!
 * @param aTagName
 *            DOCUMENT ME!
 * @throws EPPEncodeException
 *             DOCUMENT ME!
 */
public static void encodeNill(Document aDocument, Element aRoot, String aNS, String aTagName)
        throws EPPEncodeException {
    Element localElement = aDocument.createElementNS(aNS, aTagName);

    localElement.setAttribute("xsi:nil", "true");
    aRoot.appendChild(localElement);
}

From source file:org.openremote.beehive.configuration.www.UsersAPI.java

private File createControllerXmlFile(java.nio.file.Path temporaryFolder, Account account) {
    File controllerXmlFile = new File(temporaryFolder.toFile(), "controller.xml");

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

    try {/*ww  w  . j av  a 2s.  c  o m*/
        documentBuilderFactory.setNamespaceAware(true);
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        DOMImplementation domImplementation = documentBuilder.getDOMImplementation();
        Document document = domImplementation.createDocument(OPENREMOTE_NAMESPACE, "openremote", null);
        document.getDocumentElement().setAttributeNS("http://www.w3.org/2001/XMLSchema-instance",
                "xsi:schemaLocation",
                "http://www.openremote.org http://www.openremote.org/schemas/controller.xsd");

        Element componentsElement = document.createElementNS(OPENREMOTE_NAMESPACE, "components");
        document.getDocumentElement().appendChild(componentsElement);
        writeSensors(document, document.getDocumentElement(), account, findHighestCommandId(account));
        writeCommands(document, document.getDocumentElement(), account);
        writeConfig(document, document.getDocumentElement(), account);

        // Document is fully built, validate against schema before writing to file
        URL xsdResource = UsersAPI.class.getResource(CONTROLLER_XSD_PATH);
        if (xsdResource == null) {
            log.error("Cannot find XSD schema ''{0}''. Disabling validation...", CONTROLLER_XSD_PATH);
        } else {
            String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
            SchemaFactory factory = SchemaFactory.newInstance(language);
            Schema schema = factory.newSchema(xsdResource);
            Validator validator = schema.newValidator();
            validator.validate(new DOMSource(document));
        }

        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        Result output = new StreamResult(controllerXmlFile);
        Source input = new DOMSource(document);
        transformer.transform(input, output);
    } catch (ParserConfigurationException e) {
        log.error("Error generating controller.xml file", e);
        throw new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (TransformerConfigurationException e) {
        log.error("Error generating controller.xml file", e);
        throw new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (TransformerException e) {
        log.error("Error generating controller.xml file", e);
        throw new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (SAXException e) {
        log.error("Error generating controller.xml file", e);
        throw new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR);
    } catch (IOException e) {
        log.error("Error generating controller.xml file", e);
        throw new ServerErrorException(Response.Status.INTERNAL_SERVER_ERROR);
    }

    return controllerXmlFile;
}

From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLSignatureFacet.java

private void addSignatureTime(XMLSignatureFactory signatureFactory, Document document, String signatureId,
        List<XMLStructure> objectContent) {
    /*/*from  w  w  w  .j a  va 2s  .c om*/
     * SignatureTime
     */
    Element signatureTimeElement = document.createElementNS(OOXML_DIGSIG_NS, "mdssi:SignatureTime");
    signatureTimeElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:mdssi", OOXML_DIGSIG_NS);
    Element formatElement = document.createElementNS(OOXML_DIGSIG_NS, "mdssi:Format");
    formatElement.setTextContent("YYYY-MM-DDThh:mm:ssTZD");
    signatureTimeElement.appendChild(formatElement);
    Element valueElement = document.createElementNS(OOXML_DIGSIG_NS, "mdssi:Value");
    Date now = this.clock.getTime();
    DateTime dateTime = new DateTime(now.getTime(), DateTimeZone.UTC);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
    String nowStr = fmt.print(dateTime);
    LOG.debug("now: " + nowStr);
    valueElement.setTextContent(nowStr);
    signatureTimeElement.appendChild(valueElement);

    List<XMLStructure> signatureTimeContent = new LinkedList<XMLStructure>();
    signatureTimeContent.add(new DOMStructure(signatureTimeElement));
    SignatureProperty signatureTimeSignatureProperty = signatureFactory
            .newSignatureProperty(signatureTimeContent, "#" + signatureId, "idSignatureTime");
    List<SignatureProperty> signaturePropertyContent = new LinkedList<SignatureProperty>();
    signaturePropertyContent.add(signatureTimeSignatureProperty);
    SignatureProperties signatureProperties = signatureFactory.newSignatureProperties(signaturePropertyContent,
            "id-signature-time-" + UUID.randomUUID().toString());
    objectContent.add(signatureProperties);
}

From source file:eu.europa.esig.dss.asic.signature.ASiCService.java

private void buildAsicManifest(final ASiCSignatureParameters underlyingParameters,
        final DSSDocument detachedDocument, final OutputStream outputStream) {

    ASiCParameters asicParameters = underlyingParameters.aSiC();

    final Document documentDom = DSSXMLUtils.buildDOM();
    final Element asicManifestDom = documentDom.createElementNS(ASiCNamespaces.ASiC, "asic:ASiCManifest");
    documentDom.appendChild(asicManifestDom);

    final Element sigReferenceDom = DSSXMLUtils.addElement(documentDom, asicManifestDom, ASiCNamespaces.ASiC,
            "asic:SigReference");
    final String signatureName = getSignatureFileName(asicParameters);
    sigReferenceDom.setAttribute("URI", signatureName);
    sigReferenceDom.setAttribute("MimeType", MimeType.PKCS7.getMimeTypeString()); // only CAdES form

    DSSDocument currentDetachedDocument = detachedDocument;
    do {/* www  .j  av a  2s.c  o m*/

        final String detachedDocumentName = currentDetachedDocument.getName();
        final Element dataObjectReferenceDom = DSSXMLUtils.addElement(documentDom, sigReferenceDom,
                ASiCNamespaces.ASiC, "asic:DataObjectReference");
        dataObjectReferenceDom.setAttribute("URI", detachedDocumentName);

        final Element digestMethodDom = DSSXMLUtils.addElement(documentDom, dataObjectReferenceDom,
                XMLSignature.XMLNS, "DigestMethod");
        final DigestAlgorithm digestAlgorithm = underlyingParameters.getDigestAlgorithm();
        digestMethodDom.setAttribute("Algorithm", digestAlgorithm.getXmlId());

        final Element digestValueDom = DSSXMLUtils.addElement(documentDom, dataObjectReferenceDom,
                XMLSignature.XMLNS, "DigestValue");
        final byte[] digest = DSSUtils.digest(digestAlgorithm, currentDetachedDocument.getBytes());
        final String base64Encoded = Base64.encodeBase64String(digest);
        final Text textNode = documentDom.createTextNode(base64Encoded);
        digestValueDom.appendChild(textNode);

        currentDetachedDocument = currentDetachedDocument.getNextDocument();
    } while (currentDetachedDocument != null);

    storeXmlDom(outputStream, documentDom);
}