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 original(Document document, Element element)
        throws DOMException, MalformedURLException, URISyntaxException {
    Element original = document.createElementNS(FedoraNamespaces.KRAMERIUS_URI, "replicatedFrom");
    document.adoptNode(original);//  w  ww.j av a2 s .  com
    original.setTextContent(makeHANDLE(document).toURI().toString());

    List<Element> rdfversions = XMLUtils.getElementsRecursive(element, new XMLUtils.ElementsFilter() {

        @Override
        public boolean acceptElement(Element el) {
            String localName = el.getLocalName();
            String namespace = el.getNamespaceURI();
            if (namespace.equals(FedoraNamespaces.RDF_NAMESPACE_URI)) {
                return localName.equals("Description");
            }
            return false;
        }
    });

    for (Element desc : rdfversions) {
        desc.appendChild(original);
    }
}

From source file:de.betterform.connector.ant.AntSubmissionHandler.java

public Map submit(Submission submission, Node instance) throws XFormsException {
    LOGGER.debug("AntSubmissionHandler.submit()");
    ByteArrayOutputStream stream = new ByteArrayOutputStream();

    if (submission.getMethod().equals("get")) {
        try {/*from  w  w w .ja  v a2 s .  c  om*/
            String uri = getURI();
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            ByteArrayOutputStream errorStream = new ByteArrayOutputStream();

            String buildFilePath = (new URI(uri)).getSchemeSpecificPart()
                    .substring((new URI(uri)).getSchemeSpecificPart().indexOf(':') + 1);
            if (!"".equals(buildFilePath)) {
                File buildFile = new File(buildFilePath);
                String target = null;
                if (uri.contains("#")) {
                    //got Traget from uri
                    target = uri.substring(uri.indexOf('#') + 1);
                } else if (((Document) instance).getElementsByTagName("target").item(0) != null) {
                    //got target from xform
                    target = ((Document) instance).getElementsByTagName("target").item(0).getTextContent();
                } else {
                    // use default target
                    target = "default";
                }

                LOGGER.debug("AntSubmissionHandler.runTarget() BuildFile: " + buildFile.getAbsolutePath()
                        + " with Target:" + target);
                runTarget(buildFile, target, outputStream, errorStream);

                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                factory.setNamespaceAware(true);
                factory.setValidating(false);
                Document document = factory.newDocumentBuilder().newDocument();
                document.appendChild(document.createElementNS(null, "ant"));

                Element rootElement = document.getDocumentElement();
                Attr filename = document.createAttribute("fileName");
                filename.setValue(buildFile.getName());
                rootElement.setAttributeNode(filename);
                Element element = document.createElement("buildFile");
                DOMUtil.setElementValue(element, buildFile.getAbsolutePath());
                rootElement.appendChild(element);

                element = document.createElement("target");
                DOMUtil.setElementValue(element, target);
                rootElement.appendChild(element);

                element = document.createElement("output-stream");
                DOMUtil.setElementValue(element, outputStream.toString());
                rootElement.appendChild(element);

                element = document.createElement("error-stream");
                DOMUtil.setElementValue(element, errorStream.toString());
                rootElement.appendChild(element);
                DOMUtil.prettyPrintDOM(document, stream);
            } else {
                throw new XFormsException("submission method '" + submission.getMethod() + "' at: "
                        + DOMUtil.getCanonicalPath(submission.getElement()) + " not supported");
            }
        } catch (Exception e) {
            throw new XFormsException(e);
        }
    } else {
        throw new XFormsException("submission method '" + submission.getMethod() + "' at: "
                + DOMUtil.getCanonicalPath(submission.getElement()) + " not supported");
    }

    Map response = new HashMap();
    response.put(XFormsProcessor.SUBMISSION_RESPONSE_STREAM, new ByteArrayInputStream(stream.toByteArray()));
    return response;
}

From source file:no.difi.sdp.client.asice.signature.CreateSignature.java

private void wrapSignatureInXADeSEnvelope(final Document document) {
    Node signatureElement = document.removeChild(document.getDocumentElement());
    Element xadesElement = document.createElementNS(asicNamespace, "XAdESSignatures");
    xadesElement.appendChild(signatureElement);
    document.appendChild(xadesElement);//from  w  ww .  j  a  v a 2s  . c  om
}

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

private Element internalCreate() {
    parent.create();/*from   ww w. j  a v a  2s.  com*/
    Document domDocument = document.asDOM();
    Element element = getElement();
    if (element == null) {
        Element newElement = domDocument.createElementNS(domDocument.getNamespaceURI(), fieldName);
        Node parentNode = parent.getNode();
        Node lastAccessedNode = document.getLastAccessedNode();
        if (parentNode == lastAccessedNode) {
            parentNode.insertBefore(newElement, parentNode.getFirstChild());
        } else if (lastAccessedNode != null && lastAccessedNode.getParentNode() == parentNode) {
            parentNode.insertBefore(newElement, lastAccessedNode.getNextSibling());
        } else {
            parentNode.appendChild(newElement);
        }
        element = newElement;
        document.setLastAccessedNode(element);
    }
    return element;
}

From source file:com.dhenton9000.batik.sandbox.BatikExplorer.java

public Document createDocument() {

    // Create a new document.
    DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document document = impl.createDocument(svgNS, "svg", null);
    Element root = document.getDocumentElement();
    root.setAttributeNS(null, "width", "450");
    root.setAttributeNS(null, "height", "500");

    // Add some content to the document.
    Element e;/*  ww  w  .j a v  a2  s. com*/
    e = document.createElementNS(svgNS, "rect");
    e.setAttributeNS(null, "x", "10");
    e.setAttributeNS(null, "y", "10");
    e.setAttributeNS(null, "width", "200");
    e.setAttributeNS(null, "height", "300");
    e.setAttributeNS(null, "style", "fill:red;stroke:black;stroke-width:4");
    root.appendChild(e);

    e = document.createElementNS(svgNS, "circle");
    e.setAttributeNS(null, "cx", "225");
    e.setAttributeNS(null, "cy", "250");
    e.setAttributeNS(null, "r", "100");
    e.setAttributeNS(null, "style", "fill:green;fill-opacity:.5");
    root.appendChild(e);

    return document;
}

From source file:be.fedict.eid.applet.service.signer.odf.AbstractODFSignatureService.java

@Override
protected final Document getEnvelopingDocument()
        throws ParserConfigurationException, IOException, SAXException {
    Document document = getODFSignatureDocument();
    if (null != document) {
        return document;
    }//from  ww w .j a  v  a  2  s. co m
    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:com.legstar.cob2xsd.XsdAnnotationEmitter.java

/**
 * Create an XML Schema annotation with markup corresponding to the original
 * COBOL/* ww  w.j  ava  2 s  .c  o m*/
 * data item attributes.
 * 
 * @param xsdDataItem COBOL data item decorated with XSD attributes
 * @return an XML schema annotation
 */
public XmlSchemaAnnotation createLegStarAnnotation(final XsdDataItem xsdDataItem) {

    Document doc = _docBuilder.newDocument();
    Element el = doc.createElementNS(getCOXBNamespace(), getCOXBElements());
    Element elc = doc.createElementNS(getCOXBNamespace(), getCOXBElement());

    elc.setAttribute(CobolMarkup.LEVEL_NUMBER, Integer.toString(xsdDataItem.getLevelNumber()));
    elc.setAttribute(CobolMarkup.COBOL_NAME, xsdDataItem.getCobolName());
    elc.setAttribute(CobolMarkup.TYPE, xsdDataItem.getCobolType().toString());

    if (xsdDataItem.getCobolType() != CobolType.GROUP_ITEM) {
        if (xsdDataItem.getPicture() != null) {
            elc.setAttribute(CobolMarkup.PICTURE, xsdDataItem.getPicture());
        }
        if (xsdDataItem.getUsage() != null) {
            elc.setAttribute(CobolMarkup.USAGE, xsdDataItem.getUsageForCobol());
        }
        if (xsdDataItem.isJustifiedRight()) {
            elc.setAttribute(CobolMarkup.IS_JUSTIFIED_RIGHT, "true");
        }
        if (xsdDataItem.getTotalDigits() > 0) {
            elc.setAttribute(CobolMarkup.IS_SIGNED, (xsdDataItem.isSigned()) ? "true" : "false");
            elc.setAttribute(CobolMarkup.TOTAL_DIGITS, Integer.toString(xsdDataItem.getTotalDigits()));
            if (xsdDataItem.getFractionDigits() > 0) {
                elc.setAttribute(CobolMarkup.FRACTION_DIGITS,
                        Integer.toString(xsdDataItem.getFractionDigits()));
            }
            if (xsdDataItem.isSignLeading()) {
                elc.setAttribute(CobolMarkup.IS_SIGN_LEADING, "true");
            }
            if (xsdDataItem.isSignSeparate()) {
                elc.setAttribute(CobolMarkup.IS_SIGN_SEPARATE, "true");
            }
        }
    }

    /*
     * Annotations transfer the COBOL occurs semantic (as opposed to
     * the XSD semantic). No depending on => fixed size array
     */
    if (xsdDataItem.getCobolMaxOccurs() > 0) {
        elc.setAttribute(CobolMarkup.MAX_OCCURS, Integer.toString(xsdDataItem.getCobolMaxOccurs()));
        if (xsdDataItem.getDependingOn() == null) {
            elc.setAttribute(CobolMarkup.MIN_OCCURS, Integer.toString(xsdDataItem.getCobolMaxOccurs()));
        } else {
            elc.setAttribute(CobolMarkup.DEPENDING_ON, xsdDataItem.getDependingOn());
            elc.setAttribute(CobolMarkup.MIN_OCCURS, Integer.toString(xsdDataItem.getCobolMinOccurs()));
        }
    }

    if (xsdDataItem.isODOObject()) {
        elc.setAttribute(CobolMarkup.IS_ODO_OBJECT, "true");
    }
    if (xsdDataItem.getRedefines() != null) {
        elc.setAttribute(CobolMarkup.REDEFINES, xsdDataItem.getRedefines());
    }
    if (xsdDataItem.isRedefined()) {
        elc.setAttribute(CobolMarkup.IS_REDEFINED, "true");
        elc.setAttribute(CobolMarkup.UNMARSHAL_CHOICE_STRATEGY, "");
    }

    if (xsdDataItem.getValue() != null && xsdDataItem.getValue().length() > 0) {
        elc.setAttribute(CobolMarkup.VALUE, ValueUtil.resolveFigurative(xsdDataItem.getValue(),
                xsdDataItem.getMaxStorageLength(), getModel().quoteIsQuote()));
    }

    if (xsdDataItem.getSrceLine() > 0) {
        elc.setAttribute(CobolMarkup.SRCE_LINE, Integer.toString(xsdDataItem.getSrceLine()));
    }

    el.appendChild(elc);

    XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
    appInfo.setMarkup(el.getChildNodes());

    /* Create annotation */
    XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
    annotation.getItems().add(appInfo);
    return annotation;
}

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

/**
 * Initializes the prototype of this itemset.
 * <p/>/*from   w ww  . j a v  a2 s . com*/
 * The itemset prototype is cloned and removed from the document.
 */
protected void initializePrototype() {
    // create prototype element
    Document document = this.element.getOwnerDocument();
    this.prototype = document.createElementNS(NamespaceConstants.XFORMS_NS,
            (this.xformsPrefix != null ? this.xformsPrefix : NamespaceConstants.XFORMS_PREFIX) + ":"
                    + XFormsConstants.ITEM);
    this.prototype.setAttributeNS(null, "id", this.container.generateId());

    // clone itemset prototype
    NodeList children = this.element.getChildNodes();
    for (int index = 0; index < children.getLength(); index++) {
        this.prototype.appendChild(children.item(index).cloneNode(true));
    }

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

From source file:it.unibas.spicy.persistence.xml.operators.ExportXSD.java

private void processRoot(INode root, Document document) {
    Element schema = document.createElementNS(XSD_NS, PREFIX + "schema");
    document.appendChild(schema);//from w w w. j  a  v  a  2s.  c  o m
    Attr elementFormDefault = document.createAttribute("elementFormDefault");
    elementFormDefault.setValue("qualified");
    schema.setAttributeNode(elementFormDefault);
}

From source file:de.ingrid.interfaces.csw.server.cswt.impl.GenericServerCSWT.java

private Document createErrorResponse(CSWTransactionResult result) throws ParserConfigurationException {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    docFactory.setNamespaceAware(true);// ww w  . j ava  2s .  co m
    DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    DOMImplementation domImpl = docBuilder.getDOMImplementation();
    Document doc = domImpl.createDocument(RESPONSE_NAMESPACE, "ows:ExceptionReport", null);

    // create summary
    Element exception = doc.createElementNS(RESPONSE_NAMESPACE, "ows:Exception");
    exception.setAttribute("exceptionCode", "NoApplicableCode");
    doc.getDocumentElement().appendChild(exception);

    exception.appendChild(doc.createElementNS(RESPONSE_NAMESPACE, "ows:ExceptionText"))
            .appendChild(doc.createTextNode("Cannot process transaction: " + result.getErrorMessage()));

    return doc;

}