Search in sources :

Example 11 with Element

use of org.w3c.dom.Element in project che by eclipse.

the class ClasspathEntry method decodeExtraAttributes.

static IClasspathAttribute[] decodeExtraAttributes(NodeList attributes) {
    if (attributes == null)
        return NO_EXTRA_ATTRIBUTES;
    int length = attributes.getLength();
    if (length == 0)
        return NO_EXTRA_ATTRIBUTES;
    IClasspathAttribute[] result = new IClasspathAttribute[length];
    int index = 0;
    for (int i = 0; i < length; ++i) {
        Node node = attributes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element attribute = (Element) node;
            String name = attribute.getAttribute(TAG_ATTRIBUTE_NAME);
            if (name == null)
                continue;
            String value = attribute.getAttribute(TAG_ATTRIBUTE_VALUE);
            if (value == null)
                continue;
            result[index++] = new ClasspathAttribute(name, value);
        }
    }
    if (index != length)
        System.arraycopy(result, 0, result = new IClasspathAttribute[index], 0, index);
    return result;
}
Also used : IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute)

Example 12 with Element

use of org.w3c.dom.Element in project che by eclipse.

the class ClasspathEntry method decodeAccessRules.

static IAccessRule[] decodeAccessRules(NodeList list) {
    if (list == null)
        return null;
    int length = list.getLength();
    if (length == 0)
        return null;
    IAccessRule[] result = new IAccessRule[length];
    int index = 0;
    for (int i = 0; i < length; i++) {
        Node accessRule = list.item(i);
        if (accessRule.getNodeType() == Node.ELEMENT_NODE) {
            Element elementAccessRule = (Element) accessRule;
            String pattern = elementAccessRule.getAttribute(TAG_PATTERN);
            if (pattern == null)
                continue;
            String tagKind = elementAccessRule.getAttribute(TAG_KIND);
            int kind;
            if (TAG_ACCESSIBLE.equals(tagKind))
                kind = IAccessRule.K_ACCESSIBLE;
            else if (TAG_NON_ACCESSIBLE.equals(tagKind))
                kind = IAccessRule.K_NON_ACCESSIBLE;
            else if (TAG_DISCOURAGED.equals(tagKind))
                kind = IAccessRule.K_DISCOURAGED;
            else
                continue;
            //$NON-NLS-1$
            boolean ignoreIfBetter = "true".equals(elementAccessRule.getAttribute(TAG_IGNORE_IF_BETTER));
            result[index++] = new ClasspathAccessRule(new Path(pattern), ignoreIfBetter ? kind | IAccessRule.IGNORE_IF_BETTER : kind);
        }
    }
    if (index != length)
        System.arraycopy(result, 0, result = new IAccessRule[index], 0, index);
    return result;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) IAccessRule(org.eclipse.jdt.core.IAccessRule)

Example 13 with Element

use of org.w3c.dom.Element in project che by eclipse.

the class BuildFileGenerator method createProperty.

/**
     * Create property tag.
     * <property name="value" {location,value}="value"/>
     */
private void createProperty() {
    Map<String, String> locationProperties = new TreeMap<>();
    locationProperties.put("build", "${basedir}/build");
    locationProperties.put("build.classes", "${build}/classes");
    locationProperties.put("src.dir", "${basedir}/src");
    Element nameProperty = doc.createElement("property");
    nameProperty.setAttribute("name", "name");
    nameProperty.setAttribute("value", projectName);
    Node node = root.getFirstChild();
    node = root.insertBefore(nameProperty, node);
    for (Map.Entry<String, String> locationProperty : locationProperties.entrySet()) {
        Element locationElement = doc.createElement("property");
        locationElement.setAttribute("name", locationProperty.getKey());
        locationElement.setAttribute("location", locationProperty.getValue());
        node = node.getNextSibling();
        node = root.insertBefore(locationElement, node);
    }
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 14 with Element

use of org.w3c.dom.Element in project che by eclipse.

the class DialogSettings method load.

/* (non-Javadoc)
     * Load the setting from the <code>document</code>
     */
private void load(Document document, Element root) {
    name = root.getAttribute(TAG_NAME);
    NodeList l = root.getElementsByTagName(TAG_ITEM);
    for (int i = 0; i < l.getLength(); i++) {
        Node n = l.item(i);
        if (root == n.getParentNode()) {
            String key = ((Element) l.item(i)).getAttribute(TAG_KEY);
            String value = ((Element) l.item(i)).getAttribute(TAG_VALUE);
            items.put(key, value);
        }
    }
    l = root.getElementsByTagName(TAG_LIST);
    for (int i = 0; i < l.getLength(); i++) {
        Node n = l.item(i);
        if (root == n.getParentNode()) {
            Element child = (Element) l.item(i);
            String key = child.getAttribute(TAG_KEY);
            NodeList list = child.getElementsByTagName(TAG_ITEM);
            List<String> valueList = new ArrayList<String>();
            for (int j = 0; j < list.getLength(); j++) {
                Element node = (Element) list.item(j);
                if (child == node.getParentNode()) {
                    valueList.add(node.getAttribute(TAG_VALUE));
                }
            }
            String[] value = new String[valueList.size()];
            valueList.toArray(value);
            arrayItems.put(key, value);
        }
    }
    l = root.getElementsByTagName(TAG_SECTION);
    for (int i = 0; i < l.getLength(); i++) {
        Node n = l.item(i);
        if (root == n.getParentNode()) {
            //$NON-NLS-1$
            DialogSettings s = new DialogSettings("NoName");
            s.load(document, (Element) n);
            addSection(s);
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 15 with Element

use of org.w3c.dom.Element in project hadoop by apache.

the class TestRMWithCSRFFilter method verifyClusterInfoXML.

public void verifyClusterInfoXML(String xml) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xml));
    Document dom = db.parse(is);
    NodeList nodes = dom.getElementsByTagName("clusterInfo");
    assertEquals("incorrect number of elements", 1, nodes.getLength());
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        verifyClusterGeneric(WebServicesTestUtils.getXmlLong(element, "id"), WebServicesTestUtils.getXmlLong(element, "startedOn"), WebServicesTestUtils.getXmlString(element, "state"), WebServicesTestUtils.getXmlString(element, "haState"), WebServicesTestUtils.getXmlString(element, "haZooKeeperConnectionState"), WebServicesTestUtils.getXmlString(element, "hadoopVersionBuiltOn"), WebServicesTestUtils.getXmlString(element, "hadoopBuildVersion"), WebServicesTestUtils.getXmlString(element, "hadoopVersion"), WebServicesTestUtils.getXmlString(element, "resourceManagerVersionBuiltOn"), WebServicesTestUtils.getXmlString(element, "resourceManagerBuildVersion"), WebServicesTestUtils.getXmlString(element, "resourceManagerVersion"));
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) Document(org.w3c.dom.Document)

Aggregations

Element (org.w3c.dom.Element)9072 Document (org.w3c.dom.Document)2651 NodeList (org.w3c.dom.NodeList)2103 Node (org.w3c.dom.Node)1855 ArrayList (java.util.ArrayList)957 DocumentBuilder (javax.xml.parsers.DocumentBuilder)793 IOException (java.io.IOException)732 Test (org.junit.Test)693 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)591 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)489 HashMap (java.util.HashMap)434 SAXException (org.xml.sax.SAXException)406 File (java.io.File)358 Attr (org.w3c.dom.Attr)333 InputStream (java.io.InputStream)309 QName (javax.xml.namespace.QName)292 Map (java.util.Map)285 JAXBElement (javax.xml.bind.JAXBElement)285 NamedNodeMap (org.w3c.dom.NamedNodeMap)266 List (java.util.List)264