List of usage examples for org.w3c.dom Element hasChildNodes
public boolean hasChildNodes();
From source file:com.digitalpebble.stormcrawler.filtering.regex.RegexURLNormalizer.java
private List<Rule> readConfiguration(Reader reader) { List<Rule> rules = new ArrayList<>(); try {/* w ww. ja va 2 s. c o m*/ // borrowed heavily from code in Configuration.java Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(reader)); Element root = doc.getDocumentElement(); if ((!"regex-normalize".equals(root.getTagName())) && (LOG.isErrorEnabled())) { LOG.error("bad conf file: top-level element not <regex-normalize>"); } NodeList regexes = root.getChildNodes(); for (int i = 0; i < regexes.getLength(); i++) { Node regexNode = regexes.item(i); if (!(regexNode instanceof Element)) { continue; } Element regex = (Element) regexNode; if ((!"regex".equals(regex.getTagName())) && (LOG.isWarnEnabled())) { LOG.warn("bad conf file: element not <regex>"); } NodeList fields = regex.getChildNodes(); String patternValue = null; String subValue = null; for (int j = 0; j < fields.getLength(); j++) { Node fieldNode = fields.item(j); if (!(fieldNode instanceof Element)) { continue; } Element field = (Element) fieldNode; if ("pattern".equals(field.getTagName()) && field.hasChildNodes()) { patternValue = ((Text) field.getFirstChild()).getData(); } if ("substitution".equals(field.getTagName()) && field.hasChildNodes()) { subValue = ((Text) field.getFirstChild()).getData(); } if (!field.hasChildNodes()) { subValue = ""; } } if (patternValue != null && subValue != null) { Rule rule = createRule(patternValue, subValue); rules.add(rule); } } } catch (Exception e) { LOG.error("error parsing conf file", e); return EMPTY_RULES; } if (rules.size() == 0) { return EMPTY_RULES; } return rules; }
From source file:de.elbe5.base.data.XmlData.java
public String getText(Element node) { if (node.hasChildNodes()) { Node child = node.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.TEXT_NODE) { return child.getNodeValue(); }//from w ww. j a v a 2s .c om child = child.getNextSibling(); } } return ""; }
From source file:org.openhmis.oauth2.OAuth2Utils.java
public void parseXMLDoc(Element element, Document doc, Map<String, String> oauthResponse) { NodeList child = null;//from w w w. j a v a 2 s .c o m if (element == null) { child = doc.getChildNodes(); } else { child = element.getChildNodes(); } for (int j = 0; j < child.getLength(); j++) { if (child.item(j).getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { org.w3c.dom.Element childElement = (org.w3c.dom.Element) child.item(j); if (childElement.hasChildNodes()) { System.out.println(childElement.getTagName() + " : " + childElement.getTextContent()); oauthResponse.put(childElement.getTagName(), childElement.getTextContent()); parseXMLDoc(childElement, null, oauthResponse); } } } }
From source file:org.jboss.seam.spring.namespace.CdiBeanImportBeanDefinitionParser.java
@Override public AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder cdiBeanFactoryBuilder = BeanDefinitionBuilder .rootBeanDefinition(FACTORY_BEAN_CLASS_NAME); String beanManagerReference = element.getAttribute(BEAN_MANAGER_REFERENCE); if (StringUtils.hasText(beanManagerReference)) { cdiBeanFactoryBuilder.addPropertyReference("beanManager", beanManagerReference); } else {/*from w ww. ja v a2s .c o m*/ cdiBeanFactoryBuilder.addPropertyReference("beanManager", DEFAULT_BEAN_MANAGER_ID); } String name = element.getAttribute(NAME_ATTRIBUTE); String type = element.getAttribute("type"); if (!StringUtils.hasText(name) && !StringUtils.hasText(type)) { parserContext.getReaderContext() .error("A CDI bean reference must specify at least a name or the bean type", element); } ArrayList<Qualifier> qualifiers = new ArrayList<Qualifier>(); NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node childNode = children.item(i); if (childNode.getNodeType() == Node.ELEMENT_NODE && "qualifier".equals(childNode.getLocalName())) { Element qualifierElement = (Element) childNode; Qualifier qualifier = new Qualifier(); Map<String, Object> attributes = new HashMap<String, Object>(); qualifier.setClassName(qualifierElement.getAttribute("type")); if (qualifierElement.hasChildNodes()) { NodeList attributeNodes = qualifierElement.getChildNodes(); for (int j = 0; j < attributeNodes.getLength(); j++) { Node attributeNode = attributeNodes.item(j); if (attributeNode.getNodeType() == Node.ELEMENT_NODE && "attribute".equals(attributeNode.getLocalName())) { Element attributeElement = (Element) attributeNode; String attributeName = attributeElement.getAttribute("name"); String attributeValue = attributeElement.getAttribute("value"); if (!StringUtils.hasText(attributeName) || !StringUtils.hasText(attributeValue)) { parserContext.getReaderContext().error( "Qualifier attributes must have both a name and a value", attributeElement); } attributes.put(attributeName, attributeValue); } } } qualifier.setAttributes(attributes); qualifiers.add(qualifier); } } if (StringUtils.hasText(name) && !qualifiers.isEmpty()) { parserContext.getReaderContext() .error("A bean reference must either specify a name or qualifiers but not both", element); } BeanDefinitionBuilder lookupBuilder = BeanDefinitionBuilder .rootBeanDefinition(TYPE_SAFE_BEAN_LOOKUP_CLASS_NAME); lookupBuilder.addConstructorArgValue(type); lookupBuilder.addPropertyValue("qualifiers", qualifiers); AbstractBeanDefinition lookupBeanDefinition = lookupBuilder.getBeanDefinition(); String lookupBeanName = parserContext.getReaderContext().generateBeanName(lookupBeanDefinition); BeanDefinitionReaderUtils.registerBeanDefinition( new BeanDefinitionHolder(lookupBeanDefinition, lookupBeanName), parserContext.getRegistry()); cdiBeanFactoryBuilder.addPropertyReference("cdiBeanLookup", lookupBeanName); return cdiBeanFactoryBuilder.getBeanDefinition(); }
From source file:de.elbe5.base.data.XmlData.java
public List<Element> getChildElements(Element parent) { ArrayList<Element> list = new ArrayList<>(); if (parent.hasChildNodes()) { NodeList childNodes = parent.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node instanceof Element) list.add((Element) node); }//from w w w . ja v a 2s .c om } return list; }
From source file:com.alfaariss.oa.util.configuration.ConfigurationManager.java
private synchronized Element getSubSection(Element eRootSection, String sSectionType) { assert eRootSection != null : "Suplied root section is empty"; if (eRootSection.hasChildNodes()) { Node nTemp = eRootSection.getFirstChild(); while (nTemp != null) { if (nTemp.getNodeType() == Node.ELEMENT_NODE && nTemp.getNodeName().equals(sSectionType)) { return (Element) nTemp; }/* w ww. j av a 2 s.c o m*/ nTemp = nTemp.getNextSibling(); } } return null; }
From source file:com.krawler.esp.utils.ConfigReader.java
private void loadResource(Properties properties, Object name, boolean quietFail) { try {//from w ww . j a v a 2 s.co m DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = null; if (name instanceof String) { // a CLASSPATH resource String path = getResourceAsString((String) name); LOG.debug("Path is " + path); if (path != null) { doc = builder.parse(path); } } else if (name instanceof File) { // a file resource File file = (File) name; if (file.exists()) { doc = builder.parse(file); } } if (doc == null) { if (quietFail) return; throw new RuntimeException(name + " not found"); } Element root = doc.getDocumentElement(); if (!"krawler-conf".equals(root.getTagName())) System.err.print("bad conf file: top-level element not <krawler-conf>"); NodeList props = root.getChildNodes(); for (int i = 0; i < props.getLength(); i++) { Node propNode = props.item(i); if (!(propNode instanceof Element)) continue; Element prop = (Element) propNode; if (!"property".equals(prop.getTagName())) System.err.print("bad conf file: element not <property>"); NodeList fields = prop.getChildNodes(); String attr = null; String value = null; for (int j = 0; j < fields.getLength(); j++) { Node fieldNode = fields.item(j); if (!(fieldNode instanceof Element)) continue; Element field = (Element) fieldNode; if ("name".equals(field.getTagName())) attr = ((Text) field.getFirstChild()).getData(); if ("value".equals(field.getTagName()) && field.hasChildNodes()) value = ((Text) field.getFirstChild()).getData(); } if (attr != null && value != null) properties.setProperty(attr, value); } } catch (Exception e) { System.err.print("error parsing conf file: " + e); throw new RuntimeException(e); } }
From source file:com.redhat.rcm.maven.plugin.buildmetadata.io.SdocBuilder.java
private void createTagsElement(final Element docRoot) { final Element tags = document.createElement("tags"); final String tagsString = buildMetaDataProperties.getProperty(Constant.PROP_NAME_PROJECT_TAGS); renderList(tags, "tag", tagsString); if (tags.hasChildNodes()) { docRoot.appendChild(tags);/*from w w w . ja v a 2s .co m*/ } }
From source file:com.msopentech.odatajclient.engine.data.AbstractODataBinder.java
protected PropertyType guessPropertyType(final Element property) { PropertyType res = null;//from w w w .ja v a 2 s .com if (property.hasChildNodes()) { final NodeList children = property.getChildNodes(); for (int i = 0; res == null && i < children.getLength(); i++) { final Node child = children.item(i); if (child.getNodeType() == Node.ELEMENT_NODE && !child.getNodeName().startsWith(ODataConstants.PREFIX_GML)) { res = ODataConstants.ELEM_ELEMENT.equals(XMLUtils.getSimpleName(child)) ? PropertyType.COLLECTION : PropertyType.COMPLEX; } } } else { res = PropertyType.EMPTY; } if (res == null) { res = PropertyType.PRIMITIVE; } return res; }
From source file:com.redhat.rcm.maven.plugin.buildmetadata.io.SdocBuilder.java
private void createMavenElement(final Element runtime) { final Element parent = document.createElement("maven"); createContentElement(GI_VERSION, Constant.PROP_NAME_MAVEN_VERSION, parent); createContentElement("commandline", Constant.PROP_NAME_MAVEN_CMDLINE, parent); createContentElement("execution-project", Constant.PROP_NAME_MAVEN_EXECUTION_PROJECT, parent); createContentElement("is-excution-root", Constant.PROP_NAME_MAVEN_IS_EXECUTION_ROOT, parent); final Element goals = document.createElement("goals"); final String goalsString = buildMetaDataProperties.getProperty(Constant.PROP_NAME_MAVEN_GOALS); renderList(goals, "goal", goalsString); parent.appendChild(goals);//from w ww .j a v a 2 s.c om final Element filters = document.createElement("filters"); final String filtersString = buildMetaDataProperties.getProperty(Constant.PROP_NAME_MAVEN_FILTERS); renderFiles(filters, "filter", filtersString); if (filters.hasChildNodes()) { parent.appendChild(filters); } final Element profiles = document.createElement("profiles"); final String profilesString = buildMetaDataProperties.getProperty(Constant.PROP_NAME_MAVEN_ACTIVE_PROFILES); if (StringUtils.isNotBlank(profilesString)) { renderProfiles(profiles, profilesString); parent.appendChild(profiles); } createContentElement("options", Constant.PROP_NAME_MAVEN_OPTS, parent); if (parent.hasChildNodes()) { runtime.appendChild(parent); } }