Example usage for org.w3c.dom Element getOwnerDocument

List of usage examples for org.w3c.dom Element getOwnerDocument

Introduction

In this page you can find the example usage for org.w3c.dom Element getOwnerDocument.

Prototype

public Document getOwnerDocument();

Source Link

Document

The Document object associated with this node.

Usage

From source file:org.apache.empire.db.DBRecord.java

/**
 * Returns a XML document with the field description an values of this record.
 * /*  www.  ja v  a2s  .  co m*/
 * @return the new XML Document object
 */
@Override
public Document getXmlDocument() {
    if (!isValid())
        throw new ObjectNotValidException(this);
    // Create Document
    DBXmlDictionary xmlDic = getXmlDictionary();
    Element root = XMLUtil.createDocument(xmlDic.getRowSetElementName());
    if (rowset.getName() != null)
        root.setAttribute("name", rowset.getName());
    // Add Field Description
    if (addColumnDesc(root) > 0) { // Add row Values
        addRowValues(XMLUtil.addElement(root, xmlDic.getRowElementName()));
    }
    // return Document
    return root.getOwnerDocument();
}

From source file:org.apache.fop.fonts.apps.TTFReader.java

private void generateDOM4MultiByteExtras(Element parent, TTFFile ttf, boolean isCid) {
    Element el;//from   ww w  . j  ava2s. com
    Document doc = parent.getOwnerDocument();

    Element mel = doc.createElement("multibyte-extras");
    parent.appendChild(mel);

    el = doc.createElement("cid-type");
    mel.appendChild(el);
    el.appendChild(doc.createTextNode("CIDFontType2"));

    el = doc.createElement("default-width");
    mel.appendChild(el);
    el.appendChild(doc.createTextNode("0"));

    el = doc.createElement("bfranges");
    mel.appendChild(el);
    for (CMapSegment ce : ttf.getCMaps()) {
        Element el2 = doc.createElement("bf");
        el.appendChild(el2);
        el2.setAttribute("us", String.valueOf(ce.getUnicodeStart()));
        el2.setAttribute("ue", String.valueOf(ce.getUnicodeEnd()));
        el2.setAttribute("gi", String.valueOf(ce.getGlyphStartIndex()));
    }

    el = doc.createElement("cid-widths");
    el.setAttribute("start-index", "0");
    mel.appendChild(el);

    int[] wx = ttf.getWidths();
    for (int i = 0; i < wx.length; i++) {
        Element wxel = doc.createElement("wx");
        wxel.setAttribute("w", String.valueOf(wx[i]));
        el.appendChild(wxel);
    }
}

From source file:org.apache.fop.fonts.apps.TTFReader.java

private void generateDOM4SingleByteExtras(Element parent, TTFFile ttf, boolean isCid) {
    Element el;//  w  ww  .j a  va  2 s . c o m
    Document doc = parent.getOwnerDocument();

    Element sel = doc.createElement("singlebyte-extras");
    parent.appendChild(sel);

    el = doc.createElement("encoding");
    sel.appendChild(el);
    el.appendChild(doc.createTextNode(ttf.getCharSetName()));

    el = doc.createElement("first-char");
    sel.appendChild(el);
    el.appendChild(doc.createTextNode(String.valueOf(ttf.getFirstChar())));

    el = doc.createElement("last-char");
    sel.appendChild(el);
    el.appendChild(doc.createTextNode(String.valueOf(ttf.getLastChar())));

    Element widths = doc.createElement("widths");
    sel.appendChild(widths);

    for (short i = ttf.getFirstChar(); i <= ttf.getLastChar(); i++) {
        el = doc.createElement("char");
        widths.appendChild(el);
        el.setAttribute("idx", String.valueOf(i));
        el.setAttribute("wdt", String.valueOf(ttf.getCharWidth(i)));
    }
}

From source file:org.apache.fop.fonts.apps.TTFReader.java

private void generateDOM4Kerning(Element parent, TTFFile ttf, boolean isCid) {
    Element el;//from   w ww .j a va 2  s.  c  o  m
    Document doc = parent.getOwnerDocument();

    // Get kerning
    Set<Integer> kerningKeys;
    if (isCid) {
        kerningKeys = ttf.getKerning().keySet();
    } else {
        kerningKeys = ttf.getAnsiKerning().keySet();
    }

    for (Integer kpx1 : kerningKeys) {

        el = doc.createElement("kerning");
        el.setAttribute("kpx1", kpx1.toString());
        parent.appendChild(el);
        Element el2 = null;

        Map<Integer, Integer> h2;
        if (isCid) {
            h2 = ttf.getKerning().get(kpx1);
        } else {
            h2 = ttf.getAnsiKerning().get(kpx1);
        }

        for (Integer kpx2 : h2.keySet()) {
            if (isCid || kpx2.intValue() < 256) {
                el2 = doc.createElement("pair");
                el2.setAttribute("kpx2", kpx2.toString());
                Integer val = (Integer) h2.get(kpx2);
                el2.setAttribute("kern", val.toString());
                el.appendChild(el2);
            }
        }
    }
}

From source file:org.apache.fop.fonts.apps.TTFReaderBBox.java

private void generateDOM4MultiByteExtras(Element parent, TTFFile ttf, boolean isCid) {
    Element el;//from   ww w  .j  a v a2  s  .co m
    Document doc = parent.getOwnerDocument();

    Element mel = doc.createElement("multibyte-extras");
    parent.appendChild(mel);

    el = doc.createElement("cid-type");
    mel.appendChild(el);
    el.appendChild(doc.createTextNode("CIDFontType2"));

    el = doc.createElement("default-width");
    mel.appendChild(el);
    el.appendChild(doc.createTextNode("0"));

    el = doc.createElement("bfranges");
    mel.appendChild(el);
    Iterator iter = ttf.getCMaps().listIterator();
    while (iter.hasNext()) {
        TTFCmapEntry ce = (TTFCmapEntry) iter.next();
        Element el2 = doc.createElement("bf");
        el.appendChild(el2);
        el2.setAttribute("us", String.valueOf(ce.getUnicodeStart()));
        el2.setAttribute("ue", String.valueOf(ce.getUnicodeEnd()));
        el2.setAttribute("gi", String.valueOf(ce.getGlyphStartIndex()));
    }

    el = doc.createElement("cid-widths");
    el.setAttribute("start-index", "0");
    mel.appendChild(el);

    int[] wx = ttf.getWidths();
    for (int i = 0; i < wx.length; i++) {
        Element wxel = doc.createElement("wx");
        wxel.setAttribute("w", String.valueOf(wx[i]));
        // Add bounding box
        int[] bbox = ttf.getBBox(i);
        wxel.setAttribute("xMin", String.valueOf(bbox[0]));
        wxel.setAttribute("yMin", String.valueOf(bbox[1]));
        wxel.setAttribute("xMax", String.valueOf(bbox[2]));
        wxel.setAttribute("yMax", String.valueOf(bbox[3]));
        el.appendChild(wxel);
    }
}

From source file:org.apache.fop.fonts.apps.TTFReaderBBox.java

private void generateDOM4Kerning(Element parent, TTFFile ttf, boolean isCid) {
    Element el;//from  ww  w .  j a v  a2 s  .c  o m
    Document doc = parent.getOwnerDocument();

    // Get kerning
    Iterator iter;
    if (isCid) {
        iter = ttf.getKerning().keySet().iterator();
    } else {
        iter = ttf.getAnsiKerning().keySet().iterator();
    }

    while (iter.hasNext()) {
        Integer kpx1 = (Integer) iter.next();

        el = doc.createElement("kerning");
        el.setAttribute("kpx1", kpx1.toString());
        parent.appendChild(el);
        Element el2 = null;

        Map h2;
        if (isCid) {
            h2 = (Map) ttf.getKerning().get(kpx1);
        } else {
            h2 = (Map) ttf.getAnsiKerning().get(kpx1);
        }

        Iterator iter2 = h2.keySet().iterator();
        while (iter2.hasNext()) {
            Integer kpx2 = (Integer) iter2.next();
            if (isCid || kpx2.intValue() < 256) {
                el2 = doc.createElement("pair");
                el2.setAttribute("kpx2", kpx2.toString());
                Integer val = (Integer) h2.get(kpx2);
                el2.setAttribute("kern", val.toString());
                el.appendChild(el2);
            }
        }
    }
}

From source file:org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo.java

/**
 * Creates a <code>DOMSignedInfo</code> from an element.
 *
 * @param siElem a SignedInfo element// ww w  .  j a va2  s .  c o m
 */
public DOMSignedInfo(Element siElem, XMLCryptoContext context, Provider provider) throws MarshalException {
    localSiElem = siElem;
    ownerDoc = siElem.getOwnerDocument();

    // get Id attribute, if specified
    id = DOMUtils.getAttributeValue(siElem, "Id");

    // unmarshal CanonicalizationMethod
    Element cmElem = DOMUtils.getFirstChildElement(siElem);
    canonicalizationMethod = new DOMCanonicalizationMethod(cmElem, context, provider);

    // unmarshal SignatureMethod
    Element smElem = DOMUtils.getNextSiblingElement(cmElem);
    signatureMethod = DOMSignatureMethod.unmarshal(smElem);

    Boolean secureValidation = (Boolean) context.getProperty("org.apache.jcp.xml.dsig.secureValidation");
    boolean secVal = false;
    if (secureValidation != null && secureValidation.booleanValue()) {
        secVal = true;
    }

    String signatureMethodAlgorithm = signatureMethod.getAlgorithm();
    if (secVal && ((ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5.equals(signatureMethodAlgorithm)
            || ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5.equals(signatureMethodAlgorithm)))) {
        throw new MarshalException(
                "It is forbidden to use algorithm " + signatureMethod + " when secure validation is enabled");
    }

    // unmarshal References
    ArrayList<Reference> refList = new ArrayList<Reference>(5);
    Element refElem = DOMUtils.getNextSiblingElement(smElem);

    int refCount = 0;
    while (refElem != null) {
        refList.add(new DOMReference(refElem, context, provider));
        refElem = DOMUtils.getNextSiblingElement(refElem);

        refCount++;
        if (secVal && (refCount > MAXIMUM_REFERENCE_COUNT)) {
            String error = "A maxiumum of " + MAXIMUM_REFERENCE_COUNT + " "
                    + "references per Manifest are allowed with secure validation";
            throw new MarshalException(error);
        }
    }
    references = Collections.unmodifiableList(refList);
}

From source file:org.apache.juddi.mapping.MappingApiToModel.java

private static String serializeTransformElement(Element xformEl) throws DOMException, LSException {
    Document document = xformEl.getOwnerDocument();
    DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation();
    LSSerializer serializer = domImplLS.createLSSerializer();
    //        serializer.getDomConfig().setParameter("namespaces", true);
    //        serializer.getDomConfig().setParameter("namespace-declarations", true);
    serializer.getDomConfig().setParameter("canonical-form", false);
    serializer.getDomConfig().setParameter("xml-declaration", false);
    String str = serializer.writeToString(xformEl);
    return str;// ww  w  .  java  2  s.  co  m
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addSSLControllerService(final Element element,
        SecurityPropertiesSchema securityProperties) throws ConfigurationChangeException {
    try {/*  w  ww.j  av  a2 s  .  c  om*/
        final Element serviceElement = element.getOwnerDocument().createElement("controllerService");
        addTextElement(serviceElement, "id", "SSL-Context-Service");
        addTextElement(serviceElement, "name", "SSL-Context-Service");
        addTextElement(serviceElement, "comment", "");
        addTextElement(serviceElement, "class", "org.apache.nifi.ssl.StandardSSLContextService");

        addTextElement(serviceElement, "enabled", "true");

        Map<String, Object> attributes = new HashMap<>();
        attributes.put("Keystore Filename", securityProperties.getKeystore());
        attributes.put("Keystore Type", securityProperties.getKeystoreType());
        attributes.put("Keystore Password", securityProperties.getKeyPassword());
        attributes.put("Truststore Filename", securityProperties.getTruststore());
        attributes.put("Truststore Type", securityProperties.getTruststoreType());
        attributes.put("Truststore Password", securityProperties.getTruststorePassword());
        attributes.put("SSL Protocol", securityProperties.getSslProtocol());

        addConfiguration(serviceElement, attributes);

        element.appendChild(serviceElement);
    } catch (Exception e) {
        throw new ConfigurationChangeException(
                "Failed to parse the config YAML while trying to create an SSL Controller Service", e);
    }
}

From source file:org.apache.nifi.minifi.bootstrap.util.ConfigTransformer.java

protected static void addControllerService(final Element element,
        ControllerServiceSchema controllerServiceSchema) throws ConfigurationChangeException {
    try {//  w  w w.j  av  a 2s . c  o  m
        final Element serviceElement = element.getOwnerDocument().createElement("controllerService");
        addTextElement(serviceElement, "id", controllerServiceSchema.getId());
        addTextElement(serviceElement, "name", controllerServiceSchema.getName());
        addTextElement(serviceElement, "comment", "");
        addTextElement(serviceElement, "class", controllerServiceSchema.getServiceClass());

        addTextElement(serviceElement, "enabled", "true");

        Map<String, Object> attributes = controllerServiceSchema.getProperties();

        addConfiguration(serviceElement, attributes);

        String annotationData = controllerServiceSchema.getAnnotationData();
        if (annotationData != null && !annotationData.isEmpty()) {
            addTextElement(element, "annotationData", annotationData);
        }

        element.appendChild(serviceElement);
    } catch (Exception e) {
        throw new ConfigurationChangeException(
                "Failed to parse the config YAML while trying to create an SSL Controller Service", e);
    }
}