Java Code Examples for org.w3c.dom.Element#getOwnerDocument()

The following examples show how to use org.w3c.dom.Element#getOwnerDocument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntegrityHmac.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method engineAddContextToElement
 *
 * @param element
 */
public void engineAddContextToElement(Element element) {
    if (element == null) {
        throw new IllegalArgumentException("null element");
    }

    if (this.HMACOutputLengthSet) {
        Document doc = element.getOwnerDocument();
        Element HMElem =
            XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_HMACOUTPUTLENGTH);
        Text HMText =
            doc.createTextNode(Integer.valueOf(this.HMACOutputLength).toString());

        HMElem.appendChild(HMText);
        XMLUtils.addReturnToElement(element);
        element.appendChild(HMElem);
        XMLUtils.addReturnToElement(element);
    }
}
 
Example 2
Source File: XMLUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static Element saveLocalizedString(
        final Map<Locale, String> map,
        final Element element) {
    final Document document = element.getOwnerDocument();
    
    final Element defaultElement = document.createElement("default");
    defaultElement.setTextContent(StringUtils.convertToAscii(
            map.get(new Locale(StringUtils.EMPTY_STRING))));
    element.appendChild(defaultElement);
    
    for (Locale locale: map.keySet()) {
        if (!map.get(locale).equals(map.get(new Locale(StringUtils.EMPTY_STRING)))) {
            final Element localizedElement = document.createElement("localized");
            
            localizedElement.setAttribute("locale", locale.toString());
            localizedElement.setTextContent(StringUtils.convertToAscii(
                    map.get(locale)));
            
            element.appendChild(localizedElement);
        }
    }
    
    return element;
}
 
Example 3
Source File: IntegrityHmac.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Method engineAddContextToElement
 *
 * @param element
 */
public void engineAddContextToElement(Element element) {
    if (element == null) {
        throw new IllegalArgumentException("null element");
    }

    if (this.HMACOutputLengthSet) {
        Document doc = element.getOwnerDocument();
        Element HMElem =
            XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_HMACOUTPUTLENGTH);
        Text HMText =
            doc.createTextNode(Integer.valueOf(this.HMACOutputLength).toString());

        HMElem.appendChild(HMText);
        XMLUtils.addReturnToElement(element);
        element.appendChild(HMElem);
        XMLUtils.addReturnToElement(element);
    }
}
 
Example 4
Source File: ModelTreeAction.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
public EntityCondition(ModelNode.ModelSubNode modelSubNode, Element entityConditionElement) {
    super(modelSubNode, entityConditionElement);
    Document ownerDoc = entityConditionElement.getOwnerDocument();
    boolean useCache = "true".equalsIgnoreCase(entityConditionElement.getAttribute("use-cache"));
    if (!useCache) {
        UtilXml.addChildElement(entityConditionElement, "use-iterator", ownerDoc);
    }
    String listName = UtilFormatOut.checkEmpty(entityConditionElement.getAttribute("list"),
            entityConditionElement.getAttribute("list-name"));
    if (UtilValidate.isEmpty(listName)) {
        listName = "_LIST_ITERATOR_";
    }
    this.listName = listName;
    entityConditionElement.setAttribute("list-name", this.listName);
    finder = new ByConditionFinder(entityConditionElement);
}
 
Example 5
Source File: WindowSettingsParameter.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void saveValueToXML(Element xmlElement) {

  // Add elements
  Document doc = xmlElement.getOwnerDocument();

  if (position != null) {
    Element positionElement = doc.createElement(POSITION_ELEMENT);
    xmlElement.appendChild(positionElement);
    positionElement.setTextContent(position.x + ":" + position.y);
  }

  if (dimension != null) {
    Element sizeElement = doc.createElement(SIZE_ELEMENT);
    xmlElement.appendChild(sizeElement);
    sizeElement.setTextContent(dimension.width + ":" + dimension.height);
  }

  Element maximizedElement = doc.createElement(MAXIMIZED_ELEMENT);
  xmlElement.appendChild(maximizedElement);
  maximizedElement.setTextContent(String.valueOf(isMaximized));

}
 
Example 6
Source File: JavaProjectGenerator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Update subprojects of the project. 
 * Project is left modified and you must save it explicitely.
 * @param helper AntProjectHelper instance
 * @param subprojects list of paths to subprojects
 */
public static void putSubprojects(AntProjectHelper helper, List<String> subprojects) {
    //assert ProjectManager.mutex().isWriteAccess();
    Element data = Util.getPrimaryConfigurationData(helper);
    Document doc = data.getOwnerDocument();
    Element subproject = XMLUtil.findElement(data, "subprojects", Util.NAMESPACE); // NOI18N
    if (subproject != null) {
        data.removeChild(subproject);
    }
    subproject = doc.createElementNS(Util.NAMESPACE, "subprojects"); // NOI18N
    XMLUtil.appendChildElement(data, subproject, rootElementsOrder);

    for (String proj : subprojects) {
        Element projEl = doc.createElementNS(Util.NAMESPACE, "project"); // NOI18N
        projEl.appendChild(doc.createTextNode(proj));
        subproject.appendChild(projEl);
    }
    Util.putPrimaryConfigurationData(helper, data);
}
 
Example 7
Source File: ElementProxy.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method setElement
 *
 * @param element
 * @param BaseURI
 * @throws XMLSecurityException
 */
public void setElement(Element element, String BaseURI) throws XMLSecurityException {
    if (element == null) {
        throw new XMLSecurityException("ElementProxy.nullElement");
    }

    if (log.isLoggable(java.util.logging.Level.FINE)) {
        log.log(java.util.logging.Level.FINE, "setElement(" + element.getTagName() + ", \"" + BaseURI + "\"");
    }

    this.doc = element.getOwnerDocument();
    this.constructionElement = element;
    this.baseURI = BaseURI;
}
 
Example 8
Source File: Base64.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method takes an (empty) Element and a BigInteger and adds the
 * base64 encoded BigInteger to the Element.
 *
 * @param element
 * @param biginteger
 */
public static final void fillElementWithBigInteger(Element element, BigInteger biginteger) {

    String encodedInt = encode(biginteger);

    if (!XMLUtils.ignoreLineBreaks() && encodedInt.length() > BASE64DEFAULTLENGTH) {
        encodedInt = "\n" + encodedInt + "\n";
    }

    Document doc = element.getOwnerDocument();
    Text text = doc.createTextNode(encodedInt);

    element.appendChild(text);
}
 
Example 9
Source File: XMLUtils.java    From xcurator with Apache License 2.0 5 votes vote down vote up
public static byte[] asByteArray(Element element) throws IOException {
    ByteArrayOutputStream bis = new ByteArrayOutputStream();

    OutputFormat format = new OutputFormat(element.getOwnerDocument());
    XMLSerializer serializer = new XMLSerializer(
            bis, format);
    serializer.asDOMSerializer();
    serializer.serialize(element);

    return bis.toByteArray();
}
 
Example 10
Source File: XMLHelper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Marshall an attribute name and value to a DOM Element. This is particularly useful for attributes whose names
 * appear in namespace-qualified form.
 * 
 * @param attributeName the attribute name in QName form
 * @param attributeValue the attribute value
 * @param domElement the target element to which to marshall
 * @param isIDAttribute flag indicating whether the attribute being marshalled should be handled as an ID-typed
 *            attribute
 */
public static void marshallAttribute(QName attributeName, String attributeValue, Element domElement,
        boolean isIDAttribute) {
    Document document = domElement.getOwnerDocument();
    Attr attribute = XMLHelper.constructAttribute(document, attributeName);
    attribute.setValue(attributeValue);
    domElement.setAttributeNodeNS(attribute);
    if (isIDAttribute) {
        domElement.setIdAttributeNode(attribute, true);
    }
}
 
Example 11
Source File: XSDHandler.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private String doc2SystemId(Element ele) {
    String documentURI = null;
    /**
     * REVISIT: Casting until DOM Level 3 interfaces are available. -- mrglavas
     */
    if(ele.getOwnerDocument() instanceof com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM){
        documentURI = ((com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM) ele.getOwnerDocument()).getDocumentURI();
    }
    return documentURI != null ? documentURI : (String) fDoc2SystemId.get(ele);
}
 
Example 12
Source File: SimpleParameterSet.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public void saveValuesToXML(Element xmlElement) {
  Document parentDocument = xmlElement.getOwnerDocument();
  for (Parameter<?> param : parameters) {
    if (skipSensitiveParameters && param.isSensitive())
      continue;
    Element paramElement = parentDocument.createElement(parameterElement);
    paramElement.setAttribute(nameAttribute, param.getName());
    xmlElement.appendChild(paramElement);
    param.saveValueToXML(paramElement);

  }
}
 
Example 13
Source File: XSDHandler.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private String doc2SystemId(Element ele) {
    String documentURI = null;
    /**
     * REVISIT: Casting until DOM Level 3 interfaces are available. -- mrglavas
     */
    if(ele.getOwnerDocument() instanceof com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM){
        documentURI = ((com.sun.org.apache.xerces.internal.impl.xs.opti.SchemaDOM) ele.getOwnerDocument()).getDocumentURI();
    }
    return documentURI != null ? documentURI : fDoc2SystemId.get(ele);
}
 
Example 14
Source File: LipidClassParameter.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void saveValueToXML(Element xmlElement) {
  if (values == null)
    return;
  Document parentDocument = xmlElement.getOwnerDocument();
  for (ValueType item : values) {
    Element newElement = parentDocument.createElement("item");
    newElement.setTextContent(item.toString());
    xmlElement.appendChild(newElement);
  }
}
 
Example 15
Source File: DOMSignedInfo.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a <code>DOMSignedInfo</code> from an element.
 *
 * @param siElem a SignedInfo element
 */
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");
    canonicalizationMethod = new DOMCanonicalizationMethod(cmElem, context,
                                                           provider);

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

    boolean secVal = Utils.secureValidation(context);

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

    // unmarshal References
    ArrayList<Reference> refList = new ArrayList<Reference>(5);
    Element refElem = DOMUtils.getNextSiblingElement(smElem, "Reference");
    refList.add(new DOMReference(refElem, context, provider));

    refElem = DOMUtils.getNextSiblingElement(refElem);
    while (refElem != null) {
        String name = refElem.getLocalName();
        if (!name.equals("Reference")) {
            throw new MarshalException("Invalid element name: " +
                                       name + ", expected Reference");
        }
        refList.add(new DOMReference(refElem, context, provider));

        if (secVal && Policy.restrictNumReferences(refList.size())) {
            String error = "A maximum of " + Policy.maxReferences()
                + " references per Manifest are allowed when"
                + " secure validation is enabled";
            throw new MarshalException(error);
        }
        refElem = DOMUtils.getNextSiblingElement(refElem);
    }
    references = Collections.unmodifiableList(refList);
}
 
Example 16
Source File: ActionButtonWidget.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean configureFromXML(final ModelReader model_reader, final Widget widget, final Element xml)
        throws Exception
{
    if (isMenuButton(xml))
    {
        if (shouldUseCombo(xml))
            return false;

        // Menu buttons used "label" instead of text
        final Element label_el = XMLUtil.getChildElement(xml, "label");

        if (label_el != null)
        {
            final Document doc = xml.getOwnerDocument();
            final Element the_text = doc.createElement(propText.getName());

            if (label_el.getFirstChild() != null)
                the_text.appendChild(label_el.getFirstChild().cloneNode(true));
            else
            {
                Text the_label = doc.createTextNode(VALUE_LABEL);
                the_text.appendChild(the_label);
            }
            xml.appendChild(the_text);
        }
    }

    super.configureFromXML(model_reader, widget, xml);

    final ActionButtonWidget button = (ActionButtonWidget)widget;
    final MacroizedWidgetProperty<String> tooltip = (MacroizedWidgetProperty<String>) button.propTooltip();
    if (xml_version.getMajor() < 3)
    {
        // See getInitialTooltip()
        tooltip.setSpecification(tooltip.getSpecification().replace("pv_value", "actions"));

        // In BOY, individual actions could have a <confirm_message>
        // This has been simplified to an overall confirmation setting for the button,
        // so move the (last) confirm message from action(s) to the button.
        final Element actions = XMLUtil.getChildElement(xml, CommonWidgetProperties.propActions.getName());
        if (actions != null)
            for (Element action : XMLUtil.getChildElements(actions, XMLTags.ACTION))
            {
                final String message = XMLUtil.getChildString(action, propConfirmMessage.getName()).orElse("");
                if (! message.isBlank())
                {
                    button.propConfirmMessage().setValue(message);
                    button.propConfirmDialog().setValue(true);
                }
            }
    }
    // If there is no pv_name, remove from tool tip
    if ( ((MacroizedWidgetProperty<String>)button.propPVName()).getSpecification().isEmpty())
        tooltip.setSpecification(tooltip.getSpecification().replace("$(pv_name)\n", ""));

    return true;
}
 
Example 17
Source File: ProgressBarWidget.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean configureFromXML(final ModelReader model_reader, final Widget widget, final Element xml)
        throws Exception
{
    super.configureFromXML(model_reader, widget, xml);

    if (xml_version.getMajor() < 2)
    {
        final ProgressBarWidget bar = (ProgressBarWidget) widget;
        // BOY progress bar reserved room on top for limit markers,
        // and on bottom for scale
        if (XMLUtil.getChildBoolean(xml, "show_markers").orElse(true))
        {
            // This widget has no markers on top, so move widget down and reduce height.
            // There is no 'marker font', seems to have constant height
            final int reduce = 25;
            bar.propY().setValue(bar.propY().getValue() + reduce);
            bar.propHeight().setValue(bar.propHeight().getValue() - reduce);
        }
        // Do use space below where BOY placed markers for the bar itself.
        // In the future, there could be a scale.

        final Element el = XMLUtil.getChildElement(xml, "color_fillbackground");
        if (el != null)
            bar.propBackgroundColor().readFromXML(model_reader, el);

        // Create text update for the value indicator
        if (XMLUtil.getChildBoolean(xml, "show_label").orElse(true))
        {
            final Document doc = xml.getOwnerDocument();
            final Element text = doc.createElement(XMLTags.WIDGET);
            text.setAttribute(XMLTags.TYPE, TextUpdateWidget.WIDGET_DESCRIPTOR.getType());
            XMLUtil.updateTag(text, XMLTags.NAME, widget.getName() + " Label");
            text.appendChild(doc.importNode(XMLUtil.getChildElement(xml, XMLTags.X), true));
            text.appendChild(doc.importNode(XMLUtil.getChildElement(xml, XMLTags.Y), true));
            text.appendChild(doc.importNode(XMLUtil.getChildElement(xml, XMLTags.WIDTH), true));
            text.appendChild(doc.importNode(XMLUtil.getChildElement(xml, XMLTags.HEIGHT), true));
            text.appendChild(doc.importNode(XMLUtil.getChildElement(xml, XMLTags.PV_NAME), true));

            Element e = doc.createElement(CommonWidgetProperties.propTransparent.getName());
            e.appendChild(doc.createTextNode(Boolean.TRUE.toString()));
            text.appendChild(e);

            e = doc.createElement(CommonWidgetProperties.propHorizontalAlignment.getName());
            e.appendChild(doc.createTextNode(Integer.toString(HorizontalAlignment.CENTER.ordinal())));
            text.appendChild(e);

            xml.getParentNode().appendChild(text);
        }
    }

    return true;
}
 
Example 18
Source File: DomWriter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @since 1.4
 */
public DomWriter(final Element rootElement, final NameCoder nameCoder) {
    this(rootElement, rootElement.getOwnerDocument(), nameCoder);
}
 
Example 19
Source File: JavaProjectGenerator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Update source views of the project. 
 * This method should be called always after the putSourceFolders method
 * to keep views and folders in sync.
 * Project is left modified and you must save it explicitely.
 * @param helper AntProjectHelper instance
 * @param sources list of SourceFolder instances
 * @param style style of source views to update. 
 *    Can be null in which case all styles will be overriden.
 *    Useful for overriding just one style of source view.
 */
public static void putSourceViews(AntProjectHelper helper, List<SourceFolder> sources, String style) {
    //assert ProjectManager.mutex().isWriteAccess();
    Element data = Util.getPrimaryConfigurationData(helper);
    Document doc = data.getOwnerDocument();
    Element viewEl = XMLUtil.findElement(data, "view", Util.NAMESPACE); // NOI18N
    if (viewEl == null) {
        viewEl = doc.createElementNS(Util.NAMESPACE, "view"); // NOI18N
        XMLUtil.appendChildElement(data, viewEl, rootElementsOrder);
    }
    Element itemsEl = XMLUtil.findElement(viewEl, "items", Util.NAMESPACE); // NOI18N
    if (itemsEl == null) {
        itemsEl = doc.createElementNS(Util.NAMESPACE, "items"); // NOI18N
        XMLUtil.appendChildElement(viewEl, itemsEl, viewElementsOrder);
    }
    List<Element> sourceViews = XMLUtil.findSubElements(itemsEl);
    for (Element sourceViewEl : sourceViews) {
        if (!sourceViewEl.getLocalName().equals("source-folder")) { // NOI18N
            continue;
        }
        String sourceStyle = sourceViewEl.getAttribute("style"); // NOI18N
        if (style == null || style.equals(sourceStyle)) {
            itemsEl.removeChild(sourceViewEl);
        }
    }
    
    for (SourceFolder sf : sources) {
        if (sf.style == null || sf.style.length() == 0) {
            // perhaps this is principal source folder?
            continue;
        }
        Element sourceFolderEl = doc.createElementNS(Util.NAMESPACE, "source-folder"); // NOI18N
        sourceFolderEl.setAttribute("style", sf.style); // NOI18N
        Element el;
        if (sf.label != null) {
            el = doc.createElementNS(Util.NAMESPACE, "label"); // NOI18N
            el.appendChild(doc.createTextNode(sf.label)); // NOI18N
            sourceFolderEl.appendChild(el);
        }
        if (sf.location != null) {
            el = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N
            el.appendChild(doc.createTextNode(sf.location)); // NOI18N
            sourceFolderEl.appendChild(el);
        }
        if (sf.includes != null) {
            el = doc.createElementNS(Util.NAMESPACE, "includes"); // NOI18N
            el.appendChild(doc.createTextNode(sf.includes)); // NOI18N
            sourceFolderEl.appendChild(el);
        }
        if (sf.excludes != null) {
            el = doc.createElementNS(Util.NAMESPACE, "excludes"); // NOI18N
            el.appendChild(doc.createTextNode(sf.excludes)); // NOI18N
            sourceFolderEl.appendChild(el);
        }
        XMLUtil.appendChildElement(itemsEl, sourceFolderEl, viewItemElementsOrder);
    }
    Util.putPrimaryConfigurationData(helper, data);
}
 
Example 20
Source File: XMLUtils.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void addReturnBeforeChild(Element e, Node child) {
    if (!ignoreLineBreaks) {
        Document doc = e.getOwnerDocument();
        e.insertBefore(doc.createTextNode("\n"), child);
    }
}