List of usage examples for org.w3c.dom Element getNodeName
public String getNodeName();
From source file:org.apache.axis.encoding.SerializationContextImpl.java
/** * Output a DOM representation to a SerializationContext * @param el is a DOM Element// w w w .j a va 2 s .co m */ public void writeDOMElement(Element el) throws IOException { AttributesImpl attributes = null; NamedNodeMap attrMap = el.getAttributes(); if (attrMap.getLength() > 0) { attributes = new AttributesImpl(); for (int i = 0; i < attrMap.getLength(); i++) { Attr attr = (Attr)attrMap.item(i); String tmp = attr.getNamespaceURI(); if ( tmp != null && tmp.equals(Constants.NS_URI_XMLNS) ) { String prefix = attr.getLocalName(); if (prefix != null) { if (prefix.equals("xmlns")) prefix = ""; String nsURI = attr.getValue(); registerPrefixForURI(prefix, nsURI); } continue; } attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getName(), "CDATA", attr.getValue()); } } String namespaceURI = el.getNamespaceURI(); String localPart = el.getLocalName(); if(namespaceURI == null || namespaceURI.length()==0) localPart = el.getNodeName(); QName qName = new QName(namespaceURI, localPart); startElement(qName, attributes); NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { writeDOMElement((Element)child); } else if (child instanceof CDATASection) { writeString("<![CDATA["); writeString(((Text)child).getData()); writeString("]]>"); } else if (child instanceof Comment) { writeString("<!--"); writeString(((CharacterData)child).getData()); writeString("-->"); } else if (child instanceof Text) { writeSafeString(((Text)child).getData()); } } endElement(); }
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
@Validated @Test/* w ww . j ava2 s. com*/ public void testCreateElement2() { try { SOAPFactory sf = SOAPFactory.newInstance(); //SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); if (sf == null) { fail("could not create SOAPFactory object"); } log.info("Create a DOMElement"); DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbfactory.newDocumentBuilder(); Document document = builder.newDocument(); Element de = document.createElementNS("http://MyNamespace.org/", "MyTag"); //Calling SOAPFactory.createElement(org.w3c.dom.Element) SOAPElement se = sf.createElement(de); if (!de.getNodeName().equals(se.getNodeName()) || !de.getNamespaceURI().equals(se.getNamespaceURI())) { //Node names are not equal fail("Got: <URI=" + se.getNamespaceURI() + ", PREFIX=" + se.getPrefix() + ", NAME=" + se.getNodeName() + ">" + "Expected: <URI=" + de.getNamespaceURI() + ", PREFIX=" + de.getPrefix() + ", NAME=" + de.getNodeName() + ">"); } } catch (Exception e) { fail("Exception: " + e); } }
From source file:org.apache.beehive.netui.util.config.internal.catalog.CatalogParser.java
private static CommandConfig parseCommand(Element element) { assert element != null; assert element.getNodeName().equals("command"); CommandConfig commandConfig = new CommandConfig(); String id = DomUtils.getChildElementText(element, "id"); String classname = DomUtils.getChildElementText(element, "command-class"); commandConfig.setId(id);//from w w w. ja v a2s . c o m commandConfig.setClassname(classname); NodeList propertyList = element.getElementsByTagName("custom-property"); if (propertyList != null) { for (int k = 0; k < propertyList.getLength(); k++) { Element propertyElement = (Element) propertyList.item(k); String propName = DomUtils.getChildElementText(propertyElement, "name"); String propValue = DomUtils.getChildElementText(propertyElement, "value"); CustomPropertyConfig propertyConfig = new CustomPropertyConfig(propName, propValue); commandConfig.addParameter(propertyConfig); } } return commandConfig; }
From source file:org.apache.camel.blueprint.handler.CamelNamespaceHandler.java
public Metadata parse(Element element, ParserContext context) { renameNamespaceRecursive(element);/*from w ww . j a v a2 s.c o m*/ if (element.getNodeName().equals(CAMEL_CONTEXT)) { // Find the id, generate one if needed String contextId = element.getAttribute("id"); boolean implicitId = false; // lets avoid folks having to explicitly give an ID to a camel context if (ObjectHelper.isEmpty(contextId)) { // if no explicit id was set then use a default auto generated name CamelContextNameStrategy strategy = new DefaultCamelContextNameStrategy(); contextId = strategy.getName(); element.setAttribute("id", contextId); implicitId = true; } // now lets parse the routes with JAXB Binder<Node> binder; try { binder = getJaxbContext().createBinder(); } catch (JAXBException e) { throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e); } Object value = parseUsingJaxb(element, context, binder); if (!(value instanceof CamelContextFactoryBean)) { throw new ComponentDefinitionException("Expected an instance of " + CamelContextFactoryBean.class); } CamelContextFactoryBean ccfb = (CamelContextFactoryBean) value; ccfb.setImplicitId(implicitId); MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class); factory.setId(".camelBlueprint.passThrough." + contextId); factory.setObject(new PassThroughCallable<Object>(value)); MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class); factory2.setId(".camelBlueprint.factory." + contextId); factory2.setFactoryComponent(factory); factory2.setFactoryMethod("call"); factory2.setInitMethod("afterPropertiesSet"); factory2.setDestroyMethod("destroy"); factory2.addProperty("blueprintContainer", createRef(context, "blueprintContainer")); factory2.addProperty("bundleContext", createRef(context, "blueprintBundleContext")); MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class); ctx.setId(contextId); ctx.setRuntimeClass(BlueprintCamelContext.class); ctx.setFactoryComponent(factory2); ctx.setFactoryMethod("getContext"); ctx.setInitMethod("init"); ctx.setDestroyMethod("destroy"); // Register objects registerBeans(context, contextId, ccfb.getEndpoints()); registerBeans(context, contextId, ccfb.getThreadPools()); registerBeans(context, contextId, ccfb.getBeans()); // Register processors MutablePassThroughMetadata beanProcessorFactory = context .createMetadata(MutablePassThroughMetadata.class); beanProcessorFactory.setId(".camelBlueprint.processor.bean.passThrough." + contextId); beanProcessorFactory.setObject(new PassThroughCallable<Object>(new CamelInjector(contextId))); MutableBeanMetadata beanProcessor = context.createMetadata(MutableBeanMetadata.class); beanProcessor.setId(".camelBlueprint.processor.bean." + contextId); beanProcessor.setRuntimeClass(CamelInjector.class); beanProcessor.setFactoryComponent(beanProcessorFactory); beanProcessor.setFactoryMethod("call"); beanProcessor.setProcessor(true); beanProcessor.addProperty("blueprintContainer", createRef(context, "blueprintContainer")); context.getComponentDefinitionRegistry().registerComponentDefinition(beanProcessor); MutablePassThroughMetadata regProcessorFactory = context .createMetadata(MutablePassThroughMetadata.class); regProcessorFactory.setId(".camelBlueprint.processor.registry.passThrough." + contextId); regProcessorFactory .setObject(new PassThroughCallable<Object>(new CamelDependenciesFinder(contextId, context))); MutableBeanMetadata regProcessor = context.createMetadata(MutableBeanMetadata.class); regProcessor.setId(".camelBlueprint.processor.registry." + contextId); regProcessor.setRuntimeClass(CamelDependenciesFinder.class); regProcessor.setFactoryComponent(regProcessorFactory); regProcessor.setFactoryMethod("call"); regProcessor.setProcessor(true); regProcessor.addDependsOn(".camelBlueprint.processor.bean." + contextId); regProcessor.addProperty("blueprintContainer", createRef(context, "blueprintContainer")); context.getComponentDefinitionRegistry().registerComponentDefinition(regProcessor); return ctx; } if (element.getNodeName().equals(ROUTE_CONTEXT)) { // now lets parse the routes with JAXB Binder<Node> binder; try { binder = getJaxbContext().createBinder(); } catch (JAXBException e) { throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e); } Object value = parseUsingJaxb(element, context, binder); if (!(value instanceof CamelRouteContextFactoryBean)) { throw new ComponentDefinitionException( "Expected an instance of " + CamelRouteContextFactoryBean.class); } CamelRouteContextFactoryBean rcfb = (CamelRouteContextFactoryBean) value; String id = rcfb.getId(); MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class); factory.setId(".camelBlueprint.passThrough." + id); factory.setObject(new PassThroughCallable<Object>(rcfb)); MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class); factory2.setId(".camelBlueprint.factory." + id); factory2.setFactoryComponent(factory); factory2.setFactoryMethod("call"); MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class); ctx.setId(id); ctx.setRuntimeClass(List.class); ctx.setFactoryComponent(factory2); ctx.setFactoryMethod("getRoutes"); return ctx; } return null; }
From source file:org.apache.cayenne.xml.XMLUtil.java
/** * Returns the first element among the direct children that has a matching name. *///from www.j a va 2 s . c o m static Element getChild(Node node, final String name) { Predicate p = new Predicate() { public boolean evaluate(Object object) { if (object instanceof Element) { Element e = (Element) object; return name.equals(e.getNodeName()); } return false; } }; return (Element) firstMatch(node.getChildNodes(), p); }
From source file:org.apache.cayenne.xml.XMLUtil.java
/** * Returns all elements among the direct children that have a matching name. *//*from w w w . j ava2 s . c om*/ static List<Element> getChildren(Node node, final String name) { Predicate p = new Predicate() { public boolean evaluate(Object object) { if (object instanceof Element) { Element e = (Element) object; return name.equals(e.getNodeName()); } return false; } }; return (List<Element>) CollectionUtils.select(getChildren(node), p); }
From source file:org.apache.empire.xml.XMLConfiguration.java
/** * reads all properties from a given properties node and applies them to the given bean * @param bean the bean to which to apply the configuration * @param propertiesNode the properties node *//*from www . jav a2 s . c om*/ public void readProperties(Object bean, Element propertiesNode) { // Check arguments if (propertiesNode == null) throw new InvalidArgumentException("propertiesNode", propertiesNode); if (bean == null) throw new InvalidArgumentException("bean", bean); // apply configuration log.info("reading bean properties from node: {}", propertiesNode.getNodeName()); NodeList nodeList = propertiesNode.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node item = nodeList.item(i); if (item.getNodeType() != Node.ELEMENT_NODE) continue; // Get the Text and set the Property setPropertyValue(bean, item); } }
From source file:org.apache.myfaces.shared_impl.webapp.webxml.WebXmlParser.java
public WebXml parse() { _webXml = new WebXml(); try {/*from www. j av a2 s . c om*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setIgnoringElementContentWhitespace(true); dbf.setIgnoringComments(true); dbf.setNamespaceAware(true); dbf.setValidating(false); // dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver(new _EntityResolver()); db.setErrorHandler(new MyFacesErrorHandler(log)); InputSource is = createContextInputSource(null, WEB_XML_PATH); if (is == null) { URL url = _context.getResource(WEB_XML_PATH); log.debug("No web-xml found at : " + (url == null ? " null " : url.toString())); return _webXml; } Document document = db.parse(is); Element webAppElem = document.getDocumentElement(); if (webAppElem == null || !webAppElem.getNodeName().equals("web-app")) { throw new FacesException("No valid web-app root element found!"); } readWebApp(webAppElem); return _webXml; } catch (Exception e) { log.fatal("Unable to parse web.xml", e); throw new FacesException(e); } }
From source file:org.apache.myfaces.shared_impl.webapp.webxml.WebXmlParser.java
private void readServlet(Element servletElem) { String servletName = null;//from w w w . ja va 2 s.c om String servletClass = null; NodeList nodeList = servletElem.getChildNodes(); for (int i = 0, len = nodeList.getLength(); i < len; i++) { Node n = nodeList.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { if (n.getNodeName().equals("servlet-name")) { servletName = XmlUtils.getElementText((Element) n); } else if (n.getNodeName().equals("servlet-class")) { servletClass = org.apache.myfaces.shared_impl.util.xml.XmlUtils.getElementText((Element) n) .trim(); } else if (n.getNodeName().equals("description") || n.getNodeName().equals("load-on-startup") || n.getNodeName().equals("init-param")) { //ignore } else { if (log.isDebugEnabled()) log.debug("Ignored element '" + n.getNodeName() + "' as child of '" + servletElem.getNodeName() + "'."); } } else { if (log.isDebugEnabled()) log.debug("Ignored node '" + n.getNodeName() + "' of type " + n.getNodeType()); } } _webXml.addServlet(servletName, servletClass); }
From source file:org.apache.myfaces.shared_impl.webapp.webxml.WebXmlParser.java
private void readServletMapping(Element servletMappingElem) { String servletName = null;//from w ww .j ava2 s . com String urlPattern = null; NodeList nodeList = servletMappingElem.getChildNodes(); for (int i = 0, len = nodeList.getLength(); i < len; i++) { Node n = nodeList.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { if (n.getNodeName().equals("servlet-name")) { servletName = org.apache.myfaces.shared_impl.util.xml.XmlUtils.getElementText((Element) n); } else if (n.getNodeName().equals("url-pattern")) { urlPattern = org.apache.myfaces.shared_impl.util.xml.XmlUtils.getElementText((Element) n) .trim(); } else { if (log.isWarnEnabled()) log.warn("Ignored element '" + n.getNodeName() + "' as child of '" + servletMappingElem.getNodeName() + "'."); } } else { if (log.isDebugEnabled()) log.debug("Ignored node '" + n.getNodeName() + "' of type " + n.getNodeType()); } } urlPattern = urlPattern.trim(); _webXml.addServletMapping(servletName, urlPattern); }