Search in sources :

Example 61 with Attr

use of org.w3c.dom.Attr in project jdk8u_jdk by JetBrains.

the class MyAttrNode method test2.

public static void test2() {
    String name = "attr";
    String oldValue = "old value";
    String newValue = "new value";
    Attr retAttr;
    IIOMetadataNode parent = new IIOMetadataNode("parent");
    MyAttrNode attrNode1 = new MyAttrNode(name, oldValue);
    MyAttrNode attrNode2 = new MyAttrNode(name, newValue);
    retAttr = parent.setAttributeNode(attrNode1);
    retAttr = parent.setAttributeNode(attrNode2);
    String actName = retAttr.getNodeName();
    String actValue = retAttr.getValue();
    if (!actName.equals(name) || !actValue.equals(oldValue)) {
        throw new RuntimeException("Test 2 failed: Invalid attribute " + "returned: " + "(name: " + actName + ", value: " + actValue + ")");
    }
}
Also used : IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) Attr(org.w3c.dom.Attr)

Example 62 with Attr

use of org.w3c.dom.Attr in project midpoint by Evolveum.

the class DOMUtil method getNamespaceDeclarations.

/**
	 * Returns map of all namespace declarations from specified element (prefix -> namespace).
	 */
public static Map<String, String> getNamespaceDeclarations(Element element) {
    Map<String, String> nsDeclMap = new HashMap<>();
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (isNamespaceDefinition(attr)) {
            String prefix = getNamespaceDeclarationPrefix(attr);
            String namespace = getNamespaceDeclarationNamespace(attr);
            nsDeclMap.put(prefix, namespace);
        }
    }
    return nsDeclMap;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Attr(org.w3c.dom.Attr)

Example 63 with Attr

use of org.w3c.dom.Attr in project midpoint by Evolveum.

the class DOMUtil method setQNameAttribute.

public static void setQNameAttribute(Element element, String attributeName, QName attributeValue) {
    Document doc = element.getOwnerDocument();
    Attr attr = doc.createAttribute(attributeName);
    setQNameAttribute(element, attr, attributeValue, element);
}
Also used : Document(org.w3c.dom.Document) Attr(org.w3c.dom.Attr)

Example 64 with Attr

use of org.w3c.dom.Attr in project midpoint by Evolveum.

the class DOMUtil method isPrefixUsed.

public static boolean isPrefixUsed(Element targetElement, String prefix) {
    if (comparePrefix(prefix, targetElement.getPrefix())) {
        return true;
    }
    NamedNodeMap attributes = targetElement.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attr = (Attr) attributes.item(i);
        if (comparePrefix(prefix, attr.getPrefix())) {
            return true;
        }
    }
    NodeList childNodes = targetElement.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node instanceof Element) {
            Element element = (Element) node;
            if (isPrefixUsed(element, prefix)) {
                return true;
            }
        }
    }
    return false;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Attr(org.w3c.dom.Attr)

Example 65 with Attr

use of org.w3c.dom.Attr in project aries by apache.

the class SpringOsgiExtension method start.

@Override
public void start() throws Exception {
    List<Object> bpPaths = new ArrayList<Object>();
    Set<URI> namespaces = new LinkedHashSet<URI>();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    for (URL url : paths) {
        InputStream is = url.openStream();
        try {
            InputSource inputSource = new InputSource(is);
            DocumentBuilder builder = dbf.newDocumentBuilder();
            Document doc = builder.parse(inputSource);
            Attr schemaLoc = doc.getDocumentElement().getAttributeNodeNS("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
            if (schemaLoc != null) {
                List<String> locs = new ArrayList<String>(Arrays.asList(schemaLoc.getValue().split("\\s+")));
                locs.remove("");
                for (int i = 0; i < locs.size() / 2; i++) {
                    String ns = locs.get(i * 2);
                    namespaces.add(URI.create(ns));
                    if (ns.startsWith("http://www.springframework.org/schema/osgi-compendium")) {
                        namespaces.add(URI.create(SpringOsgiCompendiumNamespaceHandler.CM_NAMESPACE));
                    }
                }
            }
        } finally {
            is.close();
        }
    }
    File file = File.createTempFile("blueprint-spring-extender", ".xml");
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
    try {
        writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        writer.write("<blueprint xmlns=\"http://www.osgi.org/xmlns/blueprint/v1.0.0\"\n");
        writer.write("\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
        writer.write("\txmlns:bean=\"http://www.springframework.org/schema/beans\"\n");
        writer.write("\txsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd\">\n");
        for (URL url : paths) {
            writer.write("\t<bean:import resource=\"" + url.toString() + "\"/>\n");
        }
        writer.write("</blueprint>\n");
    } finally {
        writer.close();
    }
    LOGGER.info("Generated blueprint for bundle {}/{} at {}", bundle.getSymbolicName(), bundle.getVersion(), file);
    bpPaths.add(file.toURI().toURL());
    container = blueprintExtenderService.createContainer(bundle, bpPaths, namespaces);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) URI(java.net.URI) URL(java.net.URL) Attr(org.w3c.dom.Attr) BufferedWriter(java.io.BufferedWriter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Aggregations

Attr (org.w3c.dom.Attr)461 Element (org.w3c.dom.Element)215 NamedNodeMap (org.w3c.dom.NamedNodeMap)194 Node (org.w3c.dom.Node)153 Document (org.w3c.dom.Document)147 NodeList (org.w3c.dom.NodeList)89 ArrayList (java.util.ArrayList)33 DOMException (org.w3c.dom.DOMException)32 QName (javax.xml.namespace.QName)22 HashMap (java.util.HashMap)18 DocumentBuilder (javax.xml.parsers.DocumentBuilder)17 Text (org.w3c.dom.Text)14 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)13 CanonicalizationException (com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException)10 RubyString (org.jruby.RubyString)10 IOException (java.io.IOException)9 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)8 File (java.io.File)8 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)8 ParseException (java.text.ParseException)6