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;
}
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);
}
}
}
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);
}
}
}
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);
}
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));
}
}
}
Aggregations