Search in sources :

Example 81 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project buck by facebook.

the class ToolsInstructionsCleaner method cleanToolsReferences.

@NonNull
private static MergingReport.Result cleanToolsReferences(@NonNull ManifestMerger2.MergeType mergeType, @NonNull Element element, @NonNull ILogger logger) {
    NamedNodeMap namedNodeMap = element.getAttributes();
    if (namedNodeMap != null) {
        // make a copy of the original list of attributes as we will remove some during this
        // process.
        List<Node> attributes = new ArrayList<Node>();
        for (int i = 0; i < namedNodeMap.getLength(); i++) {
            attributes.add(namedNodeMap.item(i));
        }
        for (Node attribute : attributes) {
            if (SdkConstants.TOOLS_URI.equals(attribute.getNamespaceURI())) {
                // we need to special case when the element contained tools:node="remove"
                // since it also needs to be deleted unless it had a selector.
                // if this is tools:node="removeAll", we always delete the element whether or
                // not there is a tools:selector.
                boolean hasSelector = namedNodeMap.getNamedItemNS(SdkConstants.TOOLS_URI, "selector") != null;
                if (attribute.getLocalName().equals(NodeOperationType.NODE_LOCAL_NAME) && (attribute.getNodeValue().equals(REMOVE_ALL_OPERATION_XML_MAME) || (attribute.getNodeValue().equals(REMOVE_OPERATION_XML_MAME)) && !hasSelector)) {
                    if (element.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
                        logger.error(null, /* Throwable */
                        String.format("tools:node=\"%1$s\" not allowed on top level %2$s element", attribute.getNodeValue(), XmlNode.unwrapName(element)));
                        return ERROR;
                    } else {
                        element.getParentNode().removeChild(element);
                    }
                } else {
                    // libraries.
                    if (mergeType != ManifestMerger2.MergeType.LIBRARY) {
                        element.removeAttributeNS(attribute.getNamespaceURI(), attribute.getLocalName());
                    }
                }
            }
            // this could also be the xmlns:tools declaration.
            if (attribute.getNodeName().startsWith(SdkConstants.XMLNS_PREFIX) && SdkConstants.TOOLS_URI.equals(attribute.getNodeValue()) && mergeType != ManifestMerger2.MergeType.LIBRARY) {
                element.removeAttribute(attribute.getNodeName());
            }
        }
    }
    // make a copy of the element children since we will be removing some during
    // this process, we don't want side effects.
    NodeList childNodes = element.getChildNodes();
    ImmutableList.Builder<Element> childElements = ImmutableList.builder();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            childElements.add((Element) node);
        }
    }
    for (Element childElement : childElements.build()) {
        if (cleanToolsReferences(mergeType, childElement, logger) == ERROR) {
            return ERROR;
        }
    }
    return MergingReport.Result.SUCCESS;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) ImmutableList(com.google.common.collect.ImmutableList) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NonNull(com.android.annotations.NonNull)

Example 82 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project hazelcast by hazelcast.

the class XmlConfigBuilder method handlePort.

private void handlePort(Node node) {
    String portStr = getTextContent(node).trim();
    NetworkConfig networkConfig = config.getNetworkConfig();
    if (portStr != null && portStr.length() > 0) {
        networkConfig.setPort(parseInt(portStr));
    }
    NamedNodeMap atts = node.getAttributes();
    for (int a = 0; a < atts.getLength(); a++) {
        Node att = atts.item(a);
        String value = getTextContent(att).trim();
        if ("auto-increment".equals(att.getNodeName())) {
            networkConfig.setPortAutoIncrement(getBooleanValue(value));
        } else if ("port-count".equals(att.getNodeName())) {
            int portCount = parseInt(value);
            networkConfig.setPortCount(portCount);
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node)

Example 83 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project hazelcast by hazelcast.

the class XmlConfigBuilder method handleSecurity.

private void handleSecurity(Node node) throws Exception {
    NamedNodeMap atts = node.getAttributes();
    Node enabledNode = atts.getNamedItem("enabled");
    boolean enabled = enabledNode != null && getBooleanValue(getTextContent(enabledNode));
    config.getSecurityConfig().setEnabled(enabled);
    for (Node child : childElements(node)) {
        String nodeName = cleanNodeName(child);
        if ("member-credentials-factory".equals(nodeName)) {
            handleCredentialsFactory(child);
        } else if ("member-login-modules".equals(nodeName)) {
            handleLoginModules(child, true);
        } else if ("client-login-modules".equals(nodeName)) {
            handleLoginModules(child, false);
        } else if ("client-permission-policy".equals(nodeName)) {
            handlePermissionPolicy(child);
        } else if ("client-permissions".equals(nodeName)) {
            handleSecurityPermissions(child);
        } else if ("security-interceptors".equals(nodeName)) {
            handleSecurityInterceptors(child);
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node)

Example 84 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project hazelcast by hazelcast.

the class XmlConfigBuilder method handleMultiMap.

private void handleMultiMap(Node node) {
    Node attName = node.getAttributes().getNamedItem("name");
    String name = getTextContent(attName);
    MultiMapConfig multiMapConfig = new MultiMapConfig();
    multiMapConfig.setName(name);
    for (Node n : childElements(node)) {
        String nodeName = cleanNodeName(n);
        String value = getTextContent(n).trim();
        if ("value-collection-type".equals(nodeName)) {
            multiMapConfig.setValueCollectionType(value);
        } else if ("backup-count".equals(nodeName)) {
            multiMapConfig.setBackupCount(getIntegerValue("backup-count", value));
        } else if ("async-backup-count".equals(nodeName)) {
            multiMapConfig.setAsyncBackupCount(getIntegerValue("async-backup-count", value));
        } else if ("entry-listeners".equals(nodeName)) {
            for (Node listenerNode : childElements(n)) {
                if ("entry-listener".equals(cleanNodeName(listenerNode))) {
                    NamedNodeMap attrs = listenerNode.getAttributes();
                    boolean incValue = getBooleanValue(getTextContent(attrs.getNamedItem("include-value")));
                    boolean local = getBooleanValue(getTextContent(attrs.getNamedItem("local")));
                    String listenerClass = getTextContent(listenerNode);
                    multiMapConfig.addEntryListenerConfig(new EntryListenerConfig(listenerClass, local, incValue));
                }
            }
        } else if ("statistics-enabled".equals(nodeName)) {
            multiMapConfig.setStatisticsEnabled(getBooleanValue(value));
        } else if ("binary".equals(nodeName)) {
            multiMapConfig.setBinary(getBooleanValue(value));
        }
    }
    this.config.addMultiMapConfig(multiMapConfig);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node)

Example 85 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project hazelcast by hazelcast.

the class XmlConfigBuilder method mapAttributesHandle.

private void mapAttributesHandle(Node n, MapConfig mapConfig) {
    for (Node extractorNode : childElements(n)) {
        if ("attribute".equals(cleanNodeName(extractorNode))) {
            NamedNodeMap attrs = extractorNode.getAttributes();
            String extractor = getTextContent(attrs.getNamedItem("extractor"));
            String name = getTextContent(extractorNode);
            mapConfig.addMapAttributeConfig(new MapAttributeConfig(name, extractor));
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node)

Aggregations

NamedNodeMap (org.w3c.dom.NamedNodeMap)993 Node (org.w3c.dom.Node)690 NodeList (org.w3c.dom.NodeList)339 Attr (org.w3c.dom.Attr)295 Element (org.w3c.dom.Element)238 Document (org.w3c.dom.Document)154 ArrayList (java.util.ArrayList)92 HashMap (java.util.HashMap)91 DocumentBuilder (javax.xml.parsers.DocumentBuilder)59 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)58 IOException (java.io.IOException)53 SAXException (org.xml.sax.SAXException)41 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)40 List (java.util.List)36 Map (java.util.Map)33 File (java.io.File)27 InputStream (java.io.InputStream)26 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)25 DOMException (org.w3c.dom.DOMException)25 ByteArrayInputStream (java.io.ByteArrayInputStream)19