List of usage examples for org.w3c.dom Node getAttributes
public NamedNodeMap getAttributes();
NamedNodeMap
containing the attributes of this node (if it is an Element
) or null
otherwise. From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SRelationSLayerMatchCondition parseSRelationSLayerMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node slayerAttributeNode = attributes.getNamedItem(SREL_SLAYER_REGEXP); String slayerRegExp = null;/*w w w .j a v a 2 s . c om*/ if (slayerAttributeNode != null) { slayerRegExp = slayerAttributeNode.getNodeValue(); attributes.removeNamedItem(SREL_SLAYER_REGEXP); } else { throw new PepperModuleException("'" + SREL_SLAYER_REGEXP + " attribute not found on SRelation SLayer Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SRelation SLayer Match Condition '" + node + "'"); } return new SRelationSLayerMatchCondition(Pattern.compile(slayerRegExp)); }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SAnnotationNameSpaceMatchCondition parseSAnnotationNameSpaceMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node nsAttributeNode = attributes.getNamedItem(SANN_NS_REGEXP); String nsRegExp = null;//from w w w. j a v a2 s . com if (nsAttributeNode != null) { nsRegExp = nsAttributeNode.getNodeValue(); attributes.removeNamedItem(SANN_NS_REGEXP); } else { throw new PepperModuleException("'" + SANN_NS_REGEXP + "' attribute not found on SAnnotation NameSpace Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SAnnotation NameSpace Match Condition '" + node + "'"); } return new SAnnotationNameSpaceMatchCondition(Pattern.compile(nsRegExp)); }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SAnnotationStringValueMatchCondition parseSAnnotationStringValueMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node stringValueAttributeNode = attributes.getNamedItem(SANN_STRING_VALUE_REGEXP); String stringValueRegExp = null; if (stringValueAttributeNode != null) { stringValueRegExp = stringValueAttributeNode.getNodeValue(); attributes.removeNamedItem(SANN_STRING_VALUE_REGEXP); } else {/* w ww. jav a 2s.c o m*/ throw new PepperModuleException("'" + SANN_STRING_VALUE_REGEXP + "' attribute not found on SAnnotation String Value Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SAnnotation String Value Match Condition '" + node + "'"); } return new SAnnotationStringValueMatchCondition(Pattern.compile(stringValueRegExp)); }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SRelationSourceTypeMatchCondition parseSRelationSourceTypeMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node sourceTypeAttributeNode = attributes.getNamedItem(SREL_SOURCE_TYPE_REGEXP); String sourceTypeRegExp = null; if (sourceTypeAttributeNode != null) { sourceTypeRegExp = sourceTypeAttributeNode.getNodeValue(); attributes.removeNamedItem(SREL_SOURCE_TYPE_REGEXP); } else {/*w ww . ja v a 2 s . c o m*/ throw new PepperModuleException("'" + SREL_SOURCE_TYPE_REGEXP + " attribute not found on SRelation SourceType Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SRelation SourceType Match Condition '" + node + "'"); } return new SRelationSourceTypeMatchCondition(Pattern.compile(sourceTypeRegExp)); }
From source file:edu.eurac.commul.pepperModules.mmax2.Salt2MMAXMapping.java
public static SRelationTargetTypeMatchCondition parseSRelationTargetTypeMatchCondition(Node node) { NamedNodeMap attributes = node.getAttributes(); Node targetTypeAttributeNode = attributes.getNamedItem(SREL_TARGET_TYPE_REGEXP); String targetTypeRegExp = null; if (targetTypeAttributeNode != null) { targetTypeRegExp = targetTypeAttributeNode.getNodeValue(); attributes.removeNamedItem(SREL_TARGET_TYPE_REGEXP); } else {/*from w ww . j av a2s . c o m*/ throw new PepperModuleException("'" + SREL_TARGET_TYPE_REGEXP + " attribute not found on SRelation TargetType Match Condition '" + node + "'"); } if (attributes.getLength() != 0) { throw new PepperModuleException( "Additional unexpected attributes found on SRelation TargetType Match Condition '" + node + "'"); } return new SRelationTargetTypeMatchCondition(Pattern.compile(targetTypeRegExp)); }
From source file:Main.java
public static boolean compareNode(Node nQ, Node nN, Boolean considerLength, Map<String, Node> qvars) throws Exception { if (qvars == null) { throw new Exception("qvars array must not be null"); }/*w w w . j a v a 2s . c om*/ if (nQ.hasChildNodes()) { int nQChildLength = nQ.getChildNodes().getLength(); if (nN.hasChildNodes() && (!considerLength || nQChildLength == nN.getChildNodes().getLength())) { //loop through all childnodes for (int i = 0; i < nQChildLength; i++) { //System.out.println("recurse to "+ nQ.getChildNodes().item( i )+"vs"+nN.getChildNodes().item( i )); //DEBUG if (!compareNode(nQ.getChildNodes().item(i), nN.getChildNodes().item(i), considerLength, qvars)) { return false; } } } } if (nQ.getNodeName().equals("mws:qvar")) { String qvarName = nQ.getAttributes().getNamedItem("name").getNodeValue(); if (qvars.containsKey(qvarName)) { return compareNode(qvars.get(qvarName), nN, considerLength, qvars); } else { qvars.put(qvarName, nN); return true; } } else { if (nQ.getNodeName().equals(nN.getNodeName())) { try { return nQ.getNodeValue().trim().equals(nN.getNodeValue().trim()); } catch (NullPointerException e) { //NodeValue does not exist return true; } } else { return false; } } }
From source file:forge.quest.io.QuestDataIO.java
@SuppressWarnings("unchecked") private static <T> T readAsset(final XStream xs, final Document doc, final String tagName, final Class<T> clasz) { final NodeList nn = doc.getElementsByTagName(tagName); final Node n = nn.item(0); final Attr att = doc.createAttribute("resolves-to"); att.setValue(clasz.getCanonicalName()); n.getAttributes().setNamedItem(att); final String xmlData = XmlUtil.nodeToString(n); return (T) xs.fromXML(xmlData); }
From source file:com.photon.phresco.framework.commons.QualityUtil.java
private static Node appendHttpSamplerProxy(Document document, Node hashTree, String name, String context, String contextType, String contextPostData, String encodingType) { Node httpSamplerProxy = document.createElement("HTTPSamplerProxy"); String contentEncoding = null; if (contextType.equals(FrameworkConstants.POST)) { contentEncoding = encodingType;//from ww w .ja v a 2s . c o m } NamedNodeMap attributes = httpSamplerProxy.getAttributes(); attributes.setNamedItem(createAttribute(document, "guiclass", "HttpTestSampleGui")); attributes.setNamedItem(createAttribute(document, "testclass", "HTTPSamplerProxy")); attributes.setNamedItem(createAttribute(document, "testname", name)); //url name attributes.setNamedItem(createAttribute(document, "enabled", "true")); appendElementProp(document, httpSamplerProxy, contextType, contextPostData); appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.domain", null); appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.port", null); appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.connect_timeout", null); appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.response_timeout", null); appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.protocol", null); appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.contentEncoding", contentEncoding); appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.path", context); // server url appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.method", contextType); appendTypeProp(document, httpSamplerProxy, "boolProp", "HTTPSampler.follow_redirects", "false"); appendTypeProp(document, httpSamplerProxy, "boolProp", "HTTPSampler.auto_redirects", "true"); appendTypeProp(document, httpSamplerProxy, "boolProp", "HTTPSampler.use_keepalive", "true"); appendTypeProp(document, httpSamplerProxy, "boolProp", "HTTPSampler.DO_MULTIPART_POST", "false"); appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.implementation", "Java"); appendTypeProp(document, httpSamplerProxy, "boolProp", "HTTPSampler.monitor", "false"); appendTypeProp(document, httpSamplerProxy, "stringProp", "HTTPSampler.embedded_url_re", null); return httpSamplerProxy; }
From source file:Main.java
public static int getAllChildren(Node start, int offset) { //String spacers = " "; String tagOpen = "<"; String tagClose = ">"; String tagEndOpen = "</"; String tagEndClose = ">"; String tagName = start.getNodeName(); String tagValue = (start.getNodeValue() == null ? "" : start.getNodeValue()); if (start.getNodeName().trim().equals("#text")) { tagOpen = ""; tagClose = ""; tagName = ""; tagEndOpen = ""; tagEndClose = ""; } else if (start.getNodeName().trim().equals("#comment")) { tagOpen = "<!--"; tagClose = ""; tagName = ""; tagEndOpen = ""; tagEndClose = "-->"; }/*w w w . jav a 2s .c o m*/ if (offset == 0) HTMLString = ""; HTMLString += tagOpen + tagName; if (start.getNodeType() == Element.ELEMENT_NODE) { NamedNodeMap startAttr = start.getAttributes(); for (int i = 0; i < startAttr.getLength(); i++) { Node attr = startAttr.item(i); HTMLString += " " + attr.getNodeName() + "=\"" + attr.getNodeValue() + "\""; } } HTMLString += tagClose + tagValue; for (Node child = start.getFirstChild(); child != null; child = child.getNextSibling()) { getAllChildren(child, offset + 1); } //if (offset > 0 && tagName.length() > 0) { if (tagName.length() > 0 || start.getNodeName().trim().equals("#comment")) { HTMLString += tagEndOpen + tagName + tagEndClose; } return ++offset; }
From source file:com.puppycrawl.tools.checkstyle.internal.XdocsPagesTest.java
private static void validateUsageExample(String fileName, String sectionName, Node subSection) { final String text = subSection.getTextContent().replace("Checkstyle Style", "").replace("Google Style", "") .replace("Sun Style", "").trim(); Assert.assertTrue(/*from w w w .j a va 2s. co m*/ fileName + " section '" + sectionName + "' has unknown text in 'Example of Usage': " + text, text.isEmpty()); boolean hasCheckstyle = false; boolean hasGoogle = false; boolean hasSun = false; for (Node node : XmlUtil.findChildElementsByTag(subSection, "a")) { final String url = node.getAttributes().getNamedItem("href").getTextContent(); final String linkText = node.getTextContent().trim(); String expectedUrl = null; if ("Checkstyle Style".equals(linkText)) { hasCheckstyle = true; expectedUrl = "https://github.com/search?q=" + "path%3Aconfig+filename%3Acheckstyle_checks.xml+" + "repo%3Acheckstyle%2Fcheckstyle+" + sectionName; } else if ("Google Style".equals(linkText)) { hasGoogle = true; expectedUrl = "https://github.com/search?q=" + "path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+" + "repo%3Acheckstyle%2Fcheckstyle+" + sectionName; Assert.assertTrue( fileName + " section '" + sectionName + "' should be in google_checks.xml or not reference 'Google Style'", GOOGLE_MODULES.contains(sectionName)); } else if ("Sun Style".equals(linkText)) { hasSun = true; expectedUrl = "https://github.com/search?q=" + "path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+" + "repo%3Acheckstyle%2Fcheckstyle+" + sectionName; Assert.assertTrue( fileName + " section '" + sectionName + "' should be in sun_checks.xml or not reference 'Sun Style'", SUN_MODULES.contains(sectionName)); } Assert.assertEquals(fileName + " section '" + sectionName + "' should have matching url", expectedUrl, url); } Assert.assertTrue(fileName + " section '" + sectionName + "' should have a checkstyle section", hasCheckstyle); Assert.assertTrue( fileName + " section '" + sectionName + "' should have a google section since it is in it's config", hasGoogle || !GOOGLE_MODULES.contains(sectionName)); Assert.assertTrue( fileName + " section '" + sectionName + "' should have a sun section since it is in it's config", hasSun || !SUN_MODULES.contains(sectionName)); }