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:com.evolveum.midpoint.prism.xml.XmlTypeConverter.java

/**
 * @param val/*ww w  .j a  va  2s .c o m*/
 * @param elementName
 * @param doc
 * @param recordType
 * @return created element
 * @throws JAXBException
 */
public static Object toXsdElement(Object val, QName elementName, Document doc, boolean recordType)
        throws SchemaException {
    if (val == null) {
        // if no value is specified, do not create element
        return null;
    }
    Class type = XsdTypeMapper.getTypeFromClass(val.getClass());
    if (type == null) {
        throw new IllegalArgumentException(
                "No type mapping for conversion: " + val.getClass() + "(element " + elementName + ")");
    }
    if (doc == null) {
        doc = DOMUtil.getDocument();
    }
    Element element = doc.createElementNS(elementName.getNamespaceURI(), elementName.getLocalPart());
    //TODO: switch to global namespace prefixes map
    //            element.setPrefix(MidPointNamespacePrefixMapper.getPreferredPrefix(elementName.getNamespaceURI()));
    toXsdElement(val, element, recordType);
    return element;
}

From source file:be.fedict.eid.dss.document.zip.ZIPSignatureService.java

@Override
protected Document getEnvelopingDocument() throws ParserConfigurationException, IOException, SAXException {
    FileInputStream fileInputStream = new FileInputStream(this.tmpFile);
    ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);
    ZipEntry zipEntry;//from  ww w .  j  av  a  2 s.  c  o m
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if (ODFUtil.isSignatureFile(zipEntry)) {
            Document documentSignaturesDocument = ODFUtil.loadDocument(zipInputStream);
            return documentSignaturesDocument;
        }
    }
    Document document = ODFUtil.getNewDocument();
    Element rootElement = document.createElementNS(ODFUtil.SIGNATURE_NS, ODFUtil.SIGNATURE_ELEMENT);
    rootElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", ODFUtil.SIGNATURE_NS);
    document.appendChild(rootElement);
    return document;
}

From source file:io.wcm.tooling.commons.contentpackagebuilder.XmlContentBuilder.java

private Element createJcrRoot(Document doc, String primaryType) {
    Element jcrRoot = doc.createElementNS(NS_JCR, "jcr:root");
    for (Map.Entry<String, String> namespace : xmlNamespaces.entrySet()) {
        jcrRoot.setAttribute("xmlns:" + namespace.getKey(), namespace.getValue());
    }/*from   w  ww.  j a v  a  2  s .c  om*/
    setAttributeNamespaceAware(jcrRoot, PN_PRIMARY_TYPE, primaryType);
    doc.appendChild(jcrRoot);
    return jcrRoot;
}

From source file:org.apache.cxf.cwiki.SiteExporter.java

private static synchronized void doLogin() throws Exception {
    if (loginToken == null) {
        Document doc = DOMUtils.createDocument();
        Element el = doc.createElementNS(SOAPNS, "ns1:login");
        Element el2 = doc.createElement("in0");

        if (userName == null) {
            System.out.println("Enter username: ");
            el2.setTextContent(System.console().readLine());
        } else {//ww  w .j  av  a  2  s.  c o m
            el2.setTextContent(userName);
        }
        el.appendChild(el2);
        el2 = doc.createElement("in1");
        el.appendChild(el2);
        if (password == null) {
            System.out.println("Enter password: ");
            el2.setTextContent(new String(System.console().readPassword()));
        } else {
            el2.setTextContent(password);
        }
        doc.appendChild(el);
        doc = getDispatch().invoke(doc);
        loginToken = doc.getDocumentElement().getFirstChild().getTextContent();
    }
}

From source file:org.apache.cxf.cwiki.SiteExporter.java

public static synchronized Space getSpace(String key) {
    Space space = spaces.get(key);//from w  w w . j  a v  a2s . c  o m
    if (space == null) {
        try {
            doLogin();

            Document doc = DOMUtils.newDocument();
            Element el = doc.createElementNS(SOAPNS, "ns1:getSpace");
            Element el2 = doc.createElement("in0");
            el.appendChild(el2);
            el2.setTextContent(loginToken);
            el2 = doc.createElement("in1");
            el.appendChild(el2);
            el2.setTextContent(key);
            doc.appendChild(el);

            Document out = getDispatch().invoke(doc);
            space = new Space(out);
            spaces.put(key, space);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return space;
}

From source file:com.sitewhere.configuration.ConfigurationMigrationSupport.java

/**
 * Perform the migration work./* w w  w .  j  av  a  2s.  c  o  m*/
 * 
 * @param document
 * @throws SiteWhereException
 */
protected static void migrateTenantConfiguration(Document document) throws SiteWhereException {
    Element beans = document.getDocumentElement();
    Element config = DomUtils.getChildElementByTagName(beans, "tenant-configuration");
    if (config == null) {
        throw new SiteWhereException("Tenant configuration element not found.");
    }
    Element dcomm = DomUtils.getChildElementByTagName(config, "device-communication");
    if (dcomm == null) {
        throw new SiteWhereException("Device communication element missing.");
    }
    Element asset = DomUtils.getChildElementByTagName(config, "asset-management");
    if (asset == null) {
        throw new SiteWhereException("Asset management element missing.");
    }
    Element eproc = DomUtils.getChildElementByTagName(config, "event-processing");
    if (eproc == null) {
        LOGGER.info("Event processing element missing. Migrating to new configuration format.");
        eproc = document.createElementNS(config.getNamespaceURI(), "event-processing");
        eproc.setPrefix(config.getPrefix());
        config.insertBefore(eproc, asset);

        moveEventProcessingElements(config, dcomm, eproc, document);
    }
    document.normalizeDocument();
}

From source file:io.wcm.tooling.commons.contentpackagebuilder.XmlContentBuilder.java

private Element createJcrContent(Document doc, Element jcrRoot, String primaryType) {
    Element jcrContent = doc.createElementNS(NS_JCR, "jcr:content");
    setAttributeNamespaceAware(jcrContent, PN_PRIMARY_TYPE, primaryType);
    jcrRoot.appendChild(jcrContent);/*from w w w  . j a v a 2 s.c  o  m*/
    return jcrContent;
}

From source file:be.fedict.eid.pkira.xkmsws.util.XMLMarshallingUtil.java

public void addSoapHeaders(Document document) {
    Element envelope = document.createElementNS(NAMESPACE_SOAP, "Envelope");
    Element body = document.createElementNS(NAMESPACE_SOAP, "Body");
    envelope.appendChild(body);/*w  w w.  j ava 2 s .c  om*/
    body.appendChild(document.getDocumentElement());
    document.appendChild(envelope);
}

From source file:it.pronetics.madstore.crawler.publisher.impl.AtomPublisherImpl.java

private Element createCollectionElement(String key, String href, String title) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);// w ww . j  av  a2  s .c  o m
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document collectionDocument = builder.newDocument();
    Element collectionelElement = collectionDocument.createElementNS(AtomConstants.APP_NS,
            AtomConstants.ATOM_COLLECTION);
    collectionelElement.setAttribute(AtomConstants.ATOM_KEY, key);
    collectionelElement.setAttribute(AtomConstants.ATOM_COLLECTION_HREF, href);
    Element acceptElement = collectionDocument.createElementNS(AtomConstants.APP_NS,
            AtomConstants.ATOM_COLLECTION_ACCEPT);
    Element titleElement = collectionDocument.createElementNS(AtomConstants.ATOM_NS,
            AtomConstants.ATOM_COLLECTION_TITLE);
    titleElement.setTextContent(title);
    collectionelElement.appendChild(acceptElement);
    collectionelElement.appendChild(titleElement);
    collectionDocument.appendChild(collectionelElement);
    return collectionelElement;
}

From source file:ddf.catalog.services.xsltlistener.XsltResponseQueueTransformer.java

private Element createElement(Document parentDoc, String namespace, String tagName, String elementValue) {
    Element element = parentDoc.createElementNS(namespace, tagName);
    element.setTextContent(elementValue);
    return element;
}