List of usage examples for org.w3c.dom Element getNodeName
public String getNodeName();
From source file:net.sf.jclal.experiment.ExperimentBuilder.java
private int expandElementsIterateAttributes(Element element) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNodeName().equals("multi")) { combinationBase.add(element.getElementsByTagName(element.getNodeName()).getLength()); return 1; }/*ww w. j a v a2s. c om*/ } return 0; }
From source file:de.codesourcery.utils.xml.XmlHelper.java
public boolean getBooleanAttribute(Element root, String attrName, boolean isRequired) throws ParseException { String sValue = root.getAttribute(attrName); if (!StringUtils.isBlank(sValue)) { if ("1".equalsIgnoreCase(sValue) || "true".equalsIgnoreCase(sValue) || "yes".equalsIgnoreCase(sValue)) { return true; }// w w w. j a v a 2 s .c om return false; } else { if (isRequired) { final String msg = "Tag <" + root.getNodeName() + "> is lacking required boolean attribute " + attrName; log.error("getBooleanAttribute(): " + msg); throw new ParseException(msg, -1); } return false; } }
From source file:de.xwic.appkit.core.config.XmlConfigLoader.java
/** * @param element/*from www .java2 s .c o m*/ * @throws IOException * @throws ParseException * @throws ConfigurationException */ private void loadEntities(Domain domain, Element entityElem) throws IOException, ParseException { List<URL> editorFiles = new ArrayList<URL>(); List<ListSetupFileIconWrapper> listFiles = new ArrayList<ListSetupFileIconWrapper>(); Model model = null; if (!profileMode) { String depends = entityElem.getAttribute("depends"); if (depends != null && depends.length() != 0) { try { Domain dm = setup.getDomain(depends); if (dm.getModel() == null) { throw new ParseException("Dependend model not found: " + depends); } model = new Model(dm.getModel()); } catch (ConfigurationException e) { throw new ParseException("Invalid depends reference: " + depends); } } else { model = new Model(); } domain.setModel(model); } else { model = domain.getModel(); } NodeList nl = entityElem.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("entity")) { // load specific attributes for the entity descriptor String fileName = element.getAttribute("file"); String className = element.getAttribute("class"); String iconKey = element.getAttribute("icon"); try { EntityDescriptor descriptor = null; if (fileName != null && fileName.length() > 0) { URL entityFile = new URL(location, fileName); fileList.add(entityFile); if (!headerOnly && !profileMode) { descriptor = XmlEntityDescriptorReader.loadEntityDescriptor(entityFile); descriptor.setDomain(domain); model.addEntityDescriptor(descriptor); } } else if (!profileMode) { try { descriptor = new EntityDescriptor( XmlEntityDescriptorReader.getClassLoader().loadClass(className)); descriptor.setDomain(domain); model.addEntityDescriptor(descriptor); } catch (Exception e) { throw new ParseException("Illegal entity class specified: " + e); } } if (null != descriptor) { descriptor.setIconKey(iconKey); } // register list and editor files to be loaded after the model // is completed NodeList nlEntity = element.getChildNodes(); for (int a = 0; a < nlEntity.getLength(); a++) { if (nlEntity.item(a).getNodeType() == Node.ELEMENT_NODE) { Element subElm = (Element) nlEntity.item(a); if (subElm.getNodeName().equals("list")) { URL listFile = new URL(location, subElm.getAttribute("file")); fileList.add(listFile); ListSetupFileIconWrapper wrapper = new ListSetupFileIconWrapper(); wrapper.setUrl(listFile); wrapper.setIconKey(subElm.getAttribute("icon")); listFiles.add(wrapper); } else if (subElm.getNodeName().equals("editor")) { URL editorFile = new URL(location, subElm.getAttribute("file")); fileList.add(editorFile); editorFiles.add(editorFile); } else if (subElm.getNodeName().equals("mailtemplate") && !profileMode) { String templateFile = subElm.getAttribute("file"); if (templateFile != null && templateFile.length() > 0) { URL emailTemplate = new URL(location, templateFile); fileList.add(emailTemplate); if (!headerOnly) { descriptor.setEmailTemplate(emailTemplate); } } } else if (subElm.getNodeName().equals("report") && !profileMode) { String templateFile = subElm.getAttribute("file"); if (templateFile != null && templateFile.length() > 0) { URL reportTemplate = new URL(location, templateFile); fileList.add(reportTemplate); if (!headerOnly) { ReportTemplate tpl = new ReportTemplate(); tpl.setLocation(reportTemplate); tpl.setFilePath(templateFile); if (subElm.hasAttribute("title")) { tpl.setTitle(subElm.getAttribute("title")); } if (subElm.hasAttribute("right")) { tpl.setRight(subElm.getAttribute("right")); } descriptor.addReportTemplate(tpl); } } } } } } catch (Exception e) { log.warn("Error loading EntityDescriptor for entity " + className + ". Skipping Descriptor! :" + e.toString()); } } } } if (!profileMode) { setup.addModel(model); } if (!headerOnly) { // load lists first for (Iterator<ListSetupFileIconWrapper> it = listFiles.iterator(); it.hasNext();) { ListSetupFileIconWrapper lFile = it.next(); ListSetup ls = XmlListSetupReader.loadListSetup(model, lFile.getUrl()); ls.setIconKey(lFile.getIconKey()); profile.addListSetup(ls); } // load editors for (Iterator<URL> it = editorFiles.iterator(); it.hasNext();) { URL eFile = it.next(); EditorConfiguration conf = XmlEditorConfigReader.readConfiguration(model, eFile); profile.addEditorConfiguration(conf); } } }
From source file:com.mtgi.analytics.aop.config.v11.BtPersisterChainBeanDefinitionParser.java
@Override @SuppressWarnings("unchecked") protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { //propagate shared template factory into sub-components if necessary. this would not be //necessary if parserContext gave us access to the entire component stack instead of just the //top. In that case, deeply nested children could search up the stack until they found //the template. perhaps a future version of the Spring API will support this. DefaultListableBeanFactory template = findEnclosingTemplateFactory(parserContext); if (template != null) parserContext.pushContainingComponent(new TemplateComponentDefinition(element.getNodeName(), parserContext.extractSource(element), template)); try {/*from ww w. j a v a2 s. c o m*/ //parse delegate persister definitions ManagedList persisters = new ManagedList(); persisters.setSource(element); NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); ++i) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String namespaceUri = node.getNamespaceURI(); NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver() .resolve(namespaceUri); Object def = handler == null ? parserContext.getDelegate().parsePropertySubElement((Element) node, builder.getRawBeanDefinition()) : handler.parse((Element) node, parserContext); persisters.add(def); } } builder.addPropertyValue("delegates", persisters); } finally { if (template != null) parserContext.popContainingComponent(); } //register persister implementation with parent. if (parserContext.isNested()) { AbstractBeanDefinition def = builder.getBeanDefinition(); String id = element.hasAttribute("id") ? element.getAttribute("id") : parserContext.getReaderContext().generateBeanName(def); BeanDefinitionHolder holder = new BeanDefinitionHolder(def, id); BtManagerBeanDefinitionParser.registerNestedBean(holder, "persister", parserContext); } }
From source file:net.sf.jclal.experiment.ExperimentBuilder.java
private int expandElementsIterateAtributes(Element element, int[] configurationSchema) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNodeName().equals("multi")) { NodeList list = element.getElementsByTagName(element.getNodeName()); for (int j = 0; j < configurationSchema.length; j++) { if (configurationSchema[j] != -1) { element.getParentNode().replaceChild(list.item(configurationSchema[j]), element); configurationSchema[j] = -1; break; }// www . java 2 s . co m } list = element.getChildNodes(); for (int j = 0; j < list.getLength(); j++) { if (list.item(j).getNodeName().equals(attribute.getNodeName())) { element.removeChild(list.item(j)); } } return 1; } } return 0; }
From source file:com.meidusa.amoeba.context.ProxyRuntimeContext.java
private void loadProxyConfig(Element current, ProxyServerConfig config) { NodeList children = current.getChildNodes(); int childSize = children.getLength(); Map<String, Object> map = new HashMap<String, Object>(); for (int i = 0; i < childSize; i++) { Node childNode = children.item(i); if (childNode instanceof Element) { Element child = (Element) childNode; final String nodeName = child.getNodeName(); if (nodeName.equals("property")) { String key = child.getAttribute("name"); String value = child.getTextContent(); map.put(key, value);// w ww . j a va2 s .com } else if (nodeName.equals("service")) { BeanObjectEntityConfig server = DocumentUtil.loadBeanConfig(child); config.addServerConfig(server); } else if (nodeName.equals("runtime")) { BeanObjectEntityConfig runtime = DocumentUtil.loadBeanConfig(child); config.setRuntimeConfig(runtime); } } } ParameterMapping.mappingObject(config, map, null); }
From source file:com.cloudseal.spring.client.namespace.CloudSealBeanDefinitionParserInstance.java
private String getRequiredAttribute(Element element, String attributeTag) { String attribute = element.getAttribute(attributeTag); if (attribute.trim().isEmpty()) { throw new IllegalStateException("Missing or empty attribute of " + element.getNodeName() + " element " + "in CloudSeal configuration: " + attributeTag); }//w w w. j a v a 2 s. c o m return attribute; }
From source file:com.bstek.dorado.view.config.XmlDocumentPreprocessor.java
private List<Element> getPlaceHolderContent(Element placeHolderElement, TemplateContext tempalteContext) throws Exception { String contentId = placeHolderElement.getAttribute(XmlConstants.ATTRIBUTE_ID); List<Element> concreteContent = null; Document document = tempalteContext.getSourceDocument(); Element groupStartElement = getGroupStartElement(document, contentId, tempalteContext); if (groupStartElement != null) { concreteContent = new ArrayList<Element>(); String nodeName = groupStartElement.getNodeName(); if (nodeName.equals(XmlConstants.GROUP_START)) { boolean groupEndFound = false; Node node = groupStartElement.getNextSibling(); while (true) { node = node.getNextSibling(); if (node == null) { break; }// ww w. j av a 2s .c o m if (node instanceof Element) { Element element = (Element) node; nodeName = element.getNodeName(); if (nodeName.equals(XmlConstants.GROUP_END)) { groupEndFound = true; break; } else if (nodeName.equals(XmlConstants.GROUP_START)) { throw new IllegalArgumentException("Nesting <GroupStart> not supported."); } else { concreteContent.add(element); } } } if (!groupEndFound) { throw new IllegalArgumentException("<GroupEnd> not found for [" + contentId + "]."); } } else if (nodeName.equals(XmlConstants.GROUP_END)) { // do nothing } else { concreteContent.add(groupStartElement); } } return concreteContent; }
From source file:com.inbravo.scribe.rest.service.crm.ms.MSCRMMessageFormatUtils.java
public static final List<Element> createEntityFromBusinessObject(final BusinessEntity businessEntity) throws Exception { /* Create list of elements */ final List<Element> elementList = new ArrayList<Element>(); if (businessEntity != null) { final Node node = businessEntity.getDomNode(); if (node.hasChildNodes()) { final NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { /* To avoid : 'DOM Level 3 Not implemented' error */ final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final Document document = builder.newDocument(); final Element element = (Element) document.importNode(nodeList.item(i), true); if (element.getNodeName() != null && element.getNodeName().contains(":")) { final String nodeName = element.getNodeName().split(":")[1]; /* Check for attributes */ final NamedNodeMap attributes = element.getAttributes(); if (attributes != null && attributes.getLength() != 0) { /* Create new map for attributes */ final Map<String, String> attributeMap = new HashMap<String, String>(); for (int j = 0; j < attributes.getLength(); j++) { final Attr attr = (Attr) attributes.item(j); /* Set node name and value in map */ attributeMap.put(attr.getNodeName(), attr.getNodeValue()); }//from w ww .ja v a 2 s . c o m /* Create node with attributes */ elementList.add(MSCRMMessageFormatUtils.createMessageElement(nodeName, element.getTextContent(), attributeMap)); } else { /* Create node without attributes */ elementList.add(MSCRMMessageFormatUtils.createMessageElement(nodeName, element.getTextContent())); } } } } return elementList; } else { return null; } }
From source file:importer.handler.post.stages.Discriminator.java
/** * Get the next true sibling of the given element * @param elem the element to get the next sibling of * @return the next true sibling of elem or null *///from w w w.j a v a2s . c o m Element nextTrueSibling(Element elem) { Node n = elem; while (elem != null) { n = n.getNextSibling(); if (n == null) elem = null; else if (n.getNodeType() == Node.ELEMENT_NODE) { Sibling s = siblings.get(n.getNodeName()); if (s != null) { String sName = s.getSibling(); String nName = n.getNodeName(); String eName = elem.getNodeName(); if (eName.equals(sName) || eName.equals(nName)) { elem = (Element) n; break; } else elem = null; } else elem = null; } else if (n.getNodeType() == Node.TEXT_NODE && !isWhitespace(n.getTextContent())) elem = null; } return elem; }