List of usage examples for org.w3c.dom Element getNodeName
public String getNodeName();
From source file:com.github.dozermapper.core.loader.xml.XMLParser.java
private void parseCustomConverters(Element ele, DozerBuilder.ConfigurationBuilder config) { NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i);/*from www . j av a 2 s .c om*/ if (node instanceof Element) { Element element = (Element) node; debugElement(element); if (CONVERTER_ELEMENT.equals(element.getNodeName())) { String converterType = getAttribute(element, TYPE_ATTRIBUTE); DozerBuilder.CustomConverterBuilder customConverterBuilder = config .customConverter(converterType); NodeList list = element.getChildNodes(); for (int x = 0; x < list.getLength(); x++) { Node node1 = list.item(x); if (node1 instanceof Element) { Element element1 = (Element) node1; if (CLASS_A_ELEMENT.equals(element1.getNodeName())) { customConverterBuilder.classA(getNodeValue(element1)); } else if (CLASS_B_ELEMENT.equals(element1.getNodeName())) { customConverterBuilder.classB(getNodeValue(element1)); } } } } } } }
From source file:uk.co.markfrimston.tasktree.TaskTree.java
protected void loadFromDocument(Document doc) throws Exception { Element root = doc.getDocumentElement(); if (root == null || !root.getNodeName().equals("tasklist")) { throw new Exception("Missing root element \"tasklist\""); }//from w w w . j a v a 2s. c o m Iterator<Element> i = getElementChildren(root); if (!i.hasNext()) { throw new Exception("Missing element \"tasks\""); } clearTree(); Element tasks = i.next(); if (!tasks.getNodeName().equals("tasks")) { throw new Exception("Missing element \"tasks\""); } addTasksFromChildElements(tasks, this.root); }
From source file:com.predic8.membrane.annot.parser.BlueprintElementParser.java
protected void handleChildElement(Element ele, ParserContext context, MutableBeanMetadata mcm, BlueprintParser globalParser) {/*w w w .jav a2 s.com*/ Metadata m = globalParser.parse(globalParser, ele, context); Class<?> clazz = null; if (m instanceof MutableBeanMetadata) { clazz = ((MutableBeanMetadata) m).getRuntimeClass(); } else { throw new RuntimeException( "Don't know how to get bean class from " + m.getClass() + ": " + ele.getNodeName()); } handleChildObject(ele, context, mcm, clazz, m); }
From source file:org.springmodules.cache.config.BeanReferenceParserImpl.java
/** * @see BeanReferenceParser#parse(Element,ParserContext,boolean) *//*from ww w . j a va 2 s . c o m*/ public Object parse(Element element, ParserContext parserContext, boolean registerInnerBean) { String refId = element.getAttribute("refId"); if (StringUtils.hasText(refId)) { return new RuntimeBeanReference(refId); } Element beanElement = null; List beanElements = DomUtils.getChildElementsByTagName(element, "bean"); if (!CollectionUtils.isEmpty(beanElements)) { beanElement = (Element) beanElements.get(0); } if (beanElement == null) { throw new IllegalStateException("The XML element " + StringUtils.quote(element.getNodeName()) + " should either have a " + "reference to an already registered bean definition or contain a " + "bean definition"); } BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(beanElement); String beanName = holder.getBeanName(); if (registerInnerBean && StringUtils.hasText(beanName)) { BeanDefinitionRegistry registry = parserContext.getRegistry(); BeanDefinition beanDefinition = holder.getBeanDefinition(); registry.registerBeanDefinition(beanName, beanDefinition); return new RuntimeBeanReference(beanName); } return holder; }
From source file:com.bstek.dorado.view.config.XmlDocumentPreprocessor.java
private boolean processImports(List<Element> elements, PreparseContext preparseContext) throws Exception { boolean changed = false; for (Element childElement : elements.toArray(new Element[0])) { String nodeName = childElement.getNodeName(); if (XmlConstants.IMPORT.equals(nodeName)) { List<Element> importContent = getImportContent(childElement, preparseContext); if (importContent != null) { childElement.setUserData("dorado.replace", importContent, null); }/* w w w . jav a 2 s . c om*/ childElement.setUserData("dorado.delete", importContent, null); changed = true; } } return changed; }
From source file:com.github.dozermapper.core.loader.xml.XMLParser.java
private void parseMapping(Element ele, DozerBuilder builder) { DozerBuilder.MappingBuilder definitionBuilder = builder.mapping(); if (StringUtils.isNotEmpty(getAttribute(ele, DATE_FORMAT))) { definitionBuilder.dateFormat(getAttribute(ele, DATE_FORMAT)); }/*from ww w. j a v a2 s. com*/ if (StringUtils.isNotEmpty(getAttribute(ele, MAP_NULL_ATTRIBUTE))) { definitionBuilder.mapNull(BooleanUtils.toBoolean(getAttribute(ele, MAP_NULL_ATTRIBUTE))); } if (StringUtils.isNotEmpty(getAttribute(ele, MAP_EMPTY_STRING_ATTRIBUTE))) { definitionBuilder.mapEmptyString(BooleanUtils.toBoolean(getAttribute(ele, MAP_EMPTY_STRING_ATTRIBUTE))); } if (StringUtils.isNotEmpty(getAttribute(ele, BEAN_FACTORY))) { definitionBuilder.beanFactory(getAttribute(ele, BEAN_FACTORY)); } if (StringUtils.isNotEmpty(getAttribute(ele, RELATIONSHIP_TYPE))) { String relationshipTypeValue = getAttribute(ele, RELATIONSHIP_TYPE); RelationshipType relationshipType = RelationshipType.valueOf(relationshipTypeValue); definitionBuilder.relationshipType(relationshipType); } if (StringUtils.isNotEmpty(getAttribute(ele, WILDCARD))) { definitionBuilder.wildcard(Boolean.valueOf(getAttribute(ele, WILDCARD))); } if (StringUtils.isNotEmpty(getAttribute(ele, WILDCARD_CASE_INSENSITIVE))) { definitionBuilder .wildcardCaseInsensitive(Boolean.valueOf(getAttribute(ele, WILDCARD_CASE_INSENSITIVE))); } if (StringUtils.isNotEmpty(getAttribute(ele, TRIM_STRINGS))) { definitionBuilder.trimStrings(Boolean.valueOf(getAttribute(ele, TRIM_STRINGS))); } if (StringUtils.isNotEmpty(getAttribute(ele, STOP_ON_ERRORS_ATTRIBUTE))) { definitionBuilder.stopOnErrors(Boolean.valueOf(getAttribute(ele, STOP_ON_ERRORS_ATTRIBUTE))); } if (StringUtils.isNotEmpty(getAttribute(ele, MAPID_ATTRIBUTE))) { definitionBuilder.mapId(getAttribute(ele, MAPID_ATTRIBUTE)); } if (StringUtils.isNotEmpty(getAttribute(ele, TYPE_ATTRIBUTE))) { String mappingDirection = getAttribute(ele, TYPE_ATTRIBUTE); MappingDirection direction = MappingDirection.valueOf(mappingDirection); definitionBuilder.type(direction); } NodeList nl = ele.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node instanceof Element) { Element element = (Element) node; debugElement(element); if (CLASS_A_ELEMENT.equals(element.getNodeName())) { String typeName = getNodeValue(element); DozerBuilder.ClassDefinitionBuilder classBuilder = definitionBuilder.classA(typeName); parseClass(element, classBuilder); } if (CLASS_B_ELEMENT.equals(element.getNodeName())) { String typeName = getNodeValue(element); DozerBuilder.ClassDefinitionBuilder classBuilder = definitionBuilder.classB(typeName); parseClass(element, classBuilder); } if (FIELD_ELEMENT.equals(element.getNodeName())) { parseGenericFieldMap(element, definitionBuilder); } else if (FIELD_EXCLUDE_ELEMENT.equals(element.getNodeName())) { parseFieldExcludeMap(element, definitionBuilder); } } } }
From source file:de.xwic.appkit.core.config.XmlConfigLoader.java
/** * @param element/*from w ww . j a va 2 s . c o m*/ * @throws IOException * @throws ParseException * @throws ConfigurationException */ private void loadDomain(Element elDomain) throws IOException, ParseException, ConfigurationException { String id = elDomain.getAttribute("id"); Domain domain; if (profileMode) { // the domain has already been loaded/specified. domain = setup.getDomain(id); } else { domain = new Domain(); domain.setId(id); } NodeList nl = elDomain.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (element.getNodeName().equals("bundle") && !profileMode) { String basename = element.getAttribute("basename"); // load each configured language for (Iterator<Language> it = setup.getLanguages().iterator(); it.hasNext();) { Language lang = it.next(); String filename = basename + "_" + lang.getId() + ".properties"; URL bundleUrl = new URL(location, filename); fileList.add(bundleUrl); if (!headerOnly) { Properties prop = new Properties(); try { InputStream in = bundleUrl.openStream(); prop.load(in); in.close(); // use unsynchronized hashMap HashMap<String, String> map = new HashMap<String, String>(); for (Object key : prop.keySet()) { String strKey = (String) key; map.put(strKey, prop.getProperty(strKey)); } domain.addBundle(lang.getId(), new Bundle(map)); } catch (Exception e) { // file might not exist. if (setup.getDefaultLangId().equals(lang.getId())) { throw new ConfigurationException("The default language file for the bundle '" + basename + "' does not exist."); } } } } } else if (element.getNodeName().equals("resource") && !profileMode) { Resource res = new Resource(); res.setId(element.getAttribute("id")); URL resUrl = new URL(location, element.getAttribute("file")); res.setLocation(resUrl); res.setFilePath(element.getAttribute("file")); domain.addResource(res); fileList.add(resUrl); } else if (element.getNodeName().equals("entities")) { loadEntities(domain, element); } else if (element.getNodeName().equals("defaults")) { loadDefaults(domain, element); } } } if (!profileMode) { setup.addDomain(domain); } }
From source file:de.xwic.appkit.core.config.XmlConfigLoader.java
/** * load the configuration/* w w w. j a va 2s.c om*/ * @param in * @return * @throws IOException * @throws ParseException */ private Setup loadSetupInternal(URL pdsLocation) throws IOException, ParseException { InputStream in = pdsLocation.openStream(); try { DocumentBuilder dom = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = (Document) dom.parse(in); Element root = doc.getDocumentElement(); NodeList nl = root.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; String name = element.getNodeName(); if (!profileMode) { // the following attributes are "not allowed" in profiles and therefor skipped. if (name.equals("id")) { setup.setId(getNodeText(element)); } else if (name.equals("title")) { setup.setAppTitle(getNodeText(element)); } else if (name.equals("version")) { setup.setVersion(getNodeText(element)); } else if (name.equals("languages")) { loadLanguages(element); } else if (name.equals("properties")) { loadProperties(element); } else if (name.equals("apps")) { loadApps(element); } } if (name.equals("domain")) { loadDomain(element); } else if (name.equals("feature")) { String id = element.getAttribute("id"); if (id == null) { throw new ParseException("feature must specify id."); } profile.addFeature(id, !"false".equals(element.getAttribute("enabled"))); } else if (name.equals("profiles")) { loadProfiles(element); } } } setup.initializeConfig(); } catch (ConfigurationException ce) { throw new ParseException("Error parsing setup", ce); } catch (ParserConfigurationException pce) { throw new ParseException("Error parsing setup", pce); } catch (SAXException e) { throw new ParseException("Error parsing setup", e); } finally { in.close(); } return setup; }
From source file:uk.co.markfrimston.tasktree.TaskTree.java
public void loadConfig() throws Exception { try {/* ww w . j a v a 2 s .c o m*/ File file = new File(filePath + CONFIG_FILENAME); if (!file.exists()) { saveConfig(); } DocumentBuilder builder = builderFact.newDocumentBuilder(); Document doc = builder.parse(file); Element root = doc.getDocumentElement(); if (root == null || !root.getNodeName().equals("config")) { throw new Exception("Missing root element \"config\""); } Iterator<Element> i = getElementChildren(root); loadUrl = null; saveUrl = null; mergeCommand = null; lastSyncTime = 0L; unsynchedChanges = true; while (i.hasNext()) { Element el = i.next(); if (el.getNodeName().equals("load-url")) { loadUrl = el.getTextContent(); if (loadUrl != null && loadUrl.length() == 0) { loadUrl = null; } } else if (el.getNodeName().equals("save-url")) { saveUrl = el.getTextContent(); if (saveUrl != null && saveUrl.length() == 0) { saveUrl = null; } } else if (el.getNodeName().equals("merge-command")) { mergeCommand = el.getTextContent(); if (mergeCommand != null && mergeCommand.length() == 0) { mergeCommand = null; } } else if (el.getNodeName().equals("last-sync")) { try { lastSyncTime = Long.parseLong(el.getTextContent()); } catch (NumberFormatException e) { } } else if (el.getNodeName().equals("unsynched-changes")) { unsynchedChanges = Boolean.parseBoolean(el.getTextContent()); } } } catch (Exception e) { throw new Exception("Failed to load config file: " + e.getClass().getName() + " - " + e.getMessage()); } }
From source file:com.sqewd.os.maracache.core.Config.java
private ConfigPath load(ConfigNode parent, Element elm) throws ConfigException { if (parent instanceof ConfigPath) { // Check if there are any attributes. // Attributes are treated as Value nodes. if (elm.hasAttributes()) { NamedNodeMap map = elm.getAttributes(); if (map.getLength() > 0) { for (int ii = 0; ii < map.getLength(); ii++) { Node n = map.item(ii); ((ConfigPath) parent).addValueNode(n.getNodeName(), n.getNodeValue()); }/*from w ww .j a va2 s. com*/ } } if (elm.hasChildNodes()) { NodeList children = elm.getChildNodes(); for (int ii = 0; ii < children.getLength(); ii++) { Node cn = children.item(ii); if (cn.getNodeType() == Node.ELEMENT_NODE) { Element e = (Element) cn; if (e.hasChildNodes()) { int nc = 0; for (int jj = 0; jj < e.getChildNodes().getLength(); jj++) { Node ccn = e.getChildNodes().item(jj); // Read the text node if there is any. if (ccn.getNodeType() == Node.TEXT_NODE) { String n = e.getNodeName(); String v = ccn.getNodeValue(); if (!StringUtils.isEmpty(v.trim())) ((ConfigPath) parent).addValueNode(n, v); nc++; } } // Make sure this in not a text only node. if (e.getChildNodes().getLength() > nc) { // Check if this is a parameter node. Parameters are treated differently. if (e.getNodeName().compareToIgnoreCase(ConfigParams.NODE_NAME) == 0) { ConfigParams cp = ((ConfigPath) parent).addParamNode(); setParams(cp, e); } else { ConfigPath cp = ((ConfigPath) parent).addPathNode(e.getNodeName()); load(cp, e); } } } } } } } return (ConfigPath) parent; }