List of usage examples for org.w3c.dom Element getElementsByTagNameNS
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;
NodeList
of all the descendant Elements
with a given local name and namespace URI in document order. From source file:org.brekka.stillingar.spring.config.ConfigurationServiceBeanDefinitionParser.java
/** * @param element//from w w w .j av a 2s . c om * @param string * @return */ protected static Element selectSingleChildElement(Element element, String tagName, boolean optional) { Element singleChild = null; NodeList children = element.getElementsByTagNameNS("*", tagName); if (children.getLength() == 1) { Node node = children.item(0); if (node instanceof Element) { singleChild = (Element) node; } else { throw new IllegalArgumentException( String.format( "Expected child node '%s' of element '%s' to be itself an instance of Element, " + "it is instead '%s'", tagName, element.getTagName(), node.getClass().getName())); } } else if (children.getLength() == 0) { if (!optional) { throw new IllegalArgumentException( String.format("Failed to find a single child element named '%s' for parent element '%s'", tagName, element.getTagName())); } } else { throw new IllegalArgumentException(String.format( "Expected element '%s' to have a single child element named '%s', found however %d elements", element.getTagName(), tagName, children.getLength())); } return singleChild; }
From source file:eu.elf.license.LicenseParser.java
public static UserLicenses parseUserLicensesAsLicenseModelGroupList(String xml, String userid) throws Exception { UserLicenses userLicenses = new UserLicenses(); try {//from w ww . ja va2 s . c o m Document xmlDoc = createXMLDocumentFromString(xml); Element ordersElement = (Element) xmlDoc .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "orders").item(0); NodeList orderList = ordersElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "order"); for (int i = 0; i < orderList.getLength(); i++) { UserLicense userLicense = new UserLicense(); try { Element orderElement = (Element) orderList.item(i); Element productionElement = (Element) orderElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "production").item(0); Element productionItemElement = (Element) productionElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "productionItem").item(0); Element LicenseReferenceElement = (Element) productionItemElement .getElementsByTagNameNS("http://www.52north.org/license/0.3.2", "LicenseReference") .item(0); Element attributeStatementElement = (Element) LicenseReferenceElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "AttributeStatement") .item(0); NodeList attributeElementList = attributeStatementElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute"); for (int j = 0; j < attributeElementList.getLength(); j++) { Element attributeElement = (Element) attributeElementList.item(j); Element AttributeValueElement = (Element) attributeElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "AttributeValue") .item(0); NamedNodeMap attributeMap = attributeElement.getAttributes(); for (int k = 0; k < attributeMap.getLength(); k++) { Attr attrs = (Attr) attributeMap.item(k); if ("Name".equals(attrs.getNodeName())) { if ("urn:opengeospatial:ows4:geodrm:NotOnOrAfter".equals(attrs.getNodeValue())) { userLicense.setValidTo(AttributeValueElement.getTextContent()); } if ("urn:opengeospatial:ows4:geodrm:LicenseID".equals(attrs.getNodeValue())) { userLicense.setLicenseId(AttributeValueElement.getTextContent()); } } } userLicense.setSecureServiceURL("/httpauth/licid-" + userLicense.getLicenseId()); } Element orderContentElement = (Element) orderElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "orderContent").item(0); Element catalogElement = (Element) orderContentElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "catalog").item(0); NodeList productGroupElementList = catalogElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "productGroup"); // setup user license flags in models List<LicenseModelGroup> list = createLicenseModelGroupList(productGroupElementList); for (LicenseModelGroup group : list) { group.setUserLicense(true); } userLicense.setLmgList(list); String WSS_URL = findWssUrlFromUserLicenseParamList(userLicense.getLmgList()); //Remove WSS from the WSS-url string WSS_URL = WSS_URL.substring(0, WSS_URL.lastIndexOf("/")); userLicense.setSecureServiceURL(WSS_URL + userLicense.getSecureServiceURL()); userLicenses.addUserLicense(userLicense); } catch (Exception e) { // Sometimes we get results without LicenseReference element: order/production/productionItem/LicenseReference // there might be valid results in the same response. Skipping the invalid ones. LOG.warn("Error while parsing user licenses"); } } return userLicenses; } catch (Exception e) { throw e; } }
From source file:com.nominanuda.springmvc.JsParserPlugin.java
public boolean supports(Element el) { return null != el.getElementsByTagNameNS(SITEMAP_NS, "js").item(0); }
From source file:com.nominanuda.springmvc.JsParserPlugin.java
public String generateHandler(Element element, ParserContext parserContext, String uriSpec) { Element handler = (Element) element.getElementsByTagNameNS(SITEMAP_NS, "js").item(0); String url = handler.getElementsByTagNameNS(SITEMAP_NS, "url").item(0).getTextContent(); String runtimeprofile = System.getProperty(RUNTIMEPROFILE); BeanDefinitionBuilder sourceBuilder = RUNTIMEPROFILE_DEV.equals(runtimeprofile) ? BeanDefinitionBuilder.genericBeanDefinition(RhinoHandler.class) : BeanDefinitionBuilder.genericBeanDefinition(CompilingRhinoHandler.class); sourceBuilder.addPropertyValue("spec", url); sourceBuilder.addPropertyReference("rhinoEmbedding", "rhinoEmbedding"); sourceBuilder.addPropertyReference("scopeFactory", "scopeFactory"); String id = MvcFrontControllerBeanDefinitionParser.uuid(); parserContext.getRegistry().registerBeanDefinition(id, sourceBuilder.getBeanDefinition()); return id;//from www .j a va 2 s .c om }
From source file:net.scriptability.core.integration.spring.ScriptAbilityBeanDefinitionParser.java
private boolean hasBindingsElement(final Element element) { return element.getElementsByTagNameNS(XML_NAMESPACE__SCRIPTABILITY, XML_ELEMENT__BINDINGS).getLength() > 0; }
From source file:ItemSearcher.java
/** * <p>This method takes a file, and searches it for specific * pieces of data using DOM traversal.</p> * * @param filename name of XML file to search through. * @throws <code>Exception</code> - generic problem handling. *//*from ww w . jav a 2 s . c om*/ public void search(String filename) throws Exception { // Parse into a DOM tree File file = new File(filename); DOMParser parser = new DOMParser(); parser.parse(file.toURL().toString()); Document doc = parser.getDocument(); // Get node to start iterating with Element root = doc.getDocumentElement(); NodeList descriptionElements = root.getElementsByTagNameNS(docNS, "description"); Element description = (Element) descriptionElements.item(0); // Get a NodeIterator NodeIterator i = ((DocumentTraversal) doc).createNodeIterator(description, NodeFilter.SHOW_ALL, new FormattingNodeFilter(), true); Node n; while ((n = i.nextNode()) != null) { System.out.println("Search phrase found: '" + n.getNodeValue() + "'"); } }
From source file:eu.elf.license.LicenseParser.java
/** * Creates list of license model parameters * * @param declarationListElement - XML element <x:declarationList> * @return List of LicenseParam objects/*from w w w . j av a 2 s . co m*/ */ private static List<LicenseParam> createLicenseModelParamList(Element declarationListElement) { List<LicenseParam> paramList = new ArrayList<LicenseParam>(); // Predefined Parameters - create as LicenseParamDisplay objects Element predefinedParametersElement = (Element) declarationListElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "predefinedParameters").item(0); if (predefinedParametersElement != null) { NodeList predefinedParametersParameterElementList = predefinedParametersElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter"); for (int n = 0; n < predefinedParametersParameterElementList.getLength(); n++) { Element parameterElement = (Element) predefinedParametersParameterElementList.item(n); LicenseParamDisplay displayParam = createLicenseParamDisplay(parameterElement, "predefinedParameter"); paramList.add(displayParam); } } // Configuration Parameters - might be LicenseParamDisplay || LicenseParamBln || LicenseParamEnum || LicenseParamInt || LicenseParamText Element configurationParametersElement = (Element) declarationListElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "configurationParameters").item(0); if (configurationParametersElement != null) { NodeList configurationParametersParameterElementList = configurationParametersElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter"); for (int n = 0; n < configurationParametersParameterElementList.getLength(); n++) { Element parameterElement = (Element) configurationParametersParameterElementList.item(n); LicenseParam lp = null; Boolean isStringType = false; Boolean multiAttributeExists = false; // true for enumration type parameters //Boolean multiAttributeValue = false; // value of the multi attribute //Boolean optionalAttribute = false; // What does optional attribute signify??? NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes(); // Create appropriate subclass object based on the "type" and "multi" attributes for (int o = 0; o < parameterElementAttributeMap.getLength(); o++) { Attr attrs = (Attr) parameterElementAttributeMap.item(o); if (attrs.getNodeName().equals("type")) { if (attrs.getNodeValue().equals("real")) { lp = createLicenseParamInt(parameterElement, "configurationParameter"); paramList.add(lp); //System.out.println("lp - name "+lpInt.getName()); } else if (attrs.getNodeValue().equals("string")) { isStringType = true; } else if (attrs.getNodeValue().equals("boolean")) { lp = createLicenseParamBln(parameterElement, "configurationParameter"); paramList.add(lp); } } if (attrs.getNodeName().equals("multi")) { multiAttributeExists = true; //if (attrs.getNodeValue().equals("true")) { //multiAttributeValue = true; //} //else { //multiAttributeExists = false; //multiAttributeValue = false; //} } // if (attrs.getNodeName().equals("optional")) { // if (attrs.getNodeName().equals("true")) { // optionalAttribute = true; // } // else { // optionalAttribute = false; // } // } } if (isStringType == true) { if (multiAttributeExists == true) { lp = createLicenseParamEnum(parameterElement, "configurationParameter"); paramList.add(lp); //if (optionalAttribute == true) { // // lp = createLicenseParamEnum(parameterElement, "configurationParameter"); // paramList.add(lp); //} } else { lp = createLicenseParamText(parameterElement, "configurationParameter"); paramList.add(lp); } } } } // Precalculated Parameters - create as LicenseParamDisplay objects Element precalculatedParametersElement = (Element) declarationListElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "precalculatedParameters").item(0); if (precalculatedParametersElement != null) { NodeList precalculatedParametersParameterElementList = precalculatedParametersElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter"); for (int n = 0; n < precalculatedParametersParameterElementList.getLength(); n++) { Element parameterElement = (Element) precalculatedParametersParameterElementList.item(n); LicenseParamDisplay displayParam = createLicenseParamDisplay(parameterElement, "precalculatedParameter"); paramList.add(displayParam); } } // Result Parameters - create as LicenseParamDisplay objects Element resultParametersElement = (Element) declarationListElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "resultParameters").item(0); if (resultParametersElement != null) { NodeList resultParametersParameterElementList = resultParametersElement .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "parameter"); for (int n = 0; n < resultParametersParameterElementList.getLength(); n++) { Element parameterElement = (Element) resultParametersParameterElementList.item(n); LicenseParamDisplay displayParam = createLicenseParamDisplay(parameterElement, "resultParameter"); paramList.add(displayParam); } } return paramList; }
From source file:com.github.xdcrafts.flower.spring.impl.xml.ExtensionBeanDefinitionHandler.java
protected void doParse(Element element, BeanDefinitionBuilder bean) { final Map<Object, Object> configuration = new ManagedMap<>(); final Node keywordValueNode = element .getElementsByTagNameNS("http://xdcrafts.github.com/schema/flower", "keyword-value").item(0); final Node predicateNode = element .getElementsByTagNameNS("http://xdcrafts.github.com/schema/flower", "predicate").item(0); if (keywordValueNode != null) { configuration.put("keyword-value", keywordValueNode.getTextContent()); }//w ww . ja va 2s . c o m if (predicateNode != null) { configuration.put("predicate", new RuntimeBeanReference(predicateNode.getTextContent())); } bean.addPropertyReference("action", element.getAttribute("action")).addPropertyValue("configuration", configuration); }
From source file:com.github.xdcrafts.flower.spring.impl.xml.FeatureBeanDefinitionHandler.java
protected void doParse(Element element, BeanDefinitionBuilder bean) { final ManagedMap<Object, Object> extensions = new ManagedMap<>(); final NodeList bindingNodes = element.getElementsByTagNameNS("http://xdcrafts.github.com/schema/flower", "binding"); if (bindingNodes != null && bindingNodes.getLength() != 0) { for (int i = 0; i < bindingNodes.getLength(); i++) { final Node bindingNode = bindingNodes.item(i); final String extension = bindingNode.getAttributes().getNamedItem("extension").getNodeValue(); final String selector = bindingNode.getAttributes().getNamedItem("selector").getNodeValue(); extensions.put(new RuntimeBeanReference(extension), new RuntimeBeanReference(selector)); }//ww w. j a v a2s .c o m } bean.addPropertyValue("extensions", extensions); }
From source file:com.example.switchyard.sap.Transformers.java
private String getElementValue(Element parent, String elementName) { String value = null;// w w w. j a v a 2 s. c o m NodeList nodes = parent.getElementsByTagNameNS("*", elementName); if (nodes.getLength() > 0 && nodes.item(0).getChildNodes() != null && nodes.item(0).getChildNodes().item(0) != null) { value = nodes.item(0).getChildNodes().item(0).getNodeValue(); } return value; }