Java Code Examples for org.w3c.dom.Element#getNodeName()
The following examples show how to use
org.w3c.dom.Element#getNodeName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractConfig.java From jackrabbit-filevault with Apache License 2.0 | 7 votes |
public void load(Element doc) throws ConfigurationException { if (!doc.getNodeName().equals(getRootElemName())) { throw new ConfigurationException("unexpected element: " + doc.getNodeName()); } String v = doc.getAttribute(ATTR_VERSION); if (v == null || v.equals("")) { v = "1.0"; } version = Double.parseDouble(v); if (version > getSupportedVersion()) { throw new ConfigurationException("version " + version + " not supported."); } NodeList nl = doc.getChildNodes(); for (int i=0; i<nl.getLength(); i++) { Node child = nl.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { doLoad((Element) child); } } }
Example 2
Source File: DomConfigPayloadBuilder.java From vespa with Apache License 2.0 | 6 votes |
private String extractName(Element element) { String initial = element.getNodeName(); if (initial.indexOf('-') < 0) { return initial; } StringBuilder buf = new StringBuilder(); boolean upcase = false; for (char ch : initial.toCharArray()) { if (ch == '-') { upcase = true; } else if (upcase && ch >= 'a' && ch <= 'z') { buf.append((char)('A' + ch - 'a')); upcase = false; } else { buf.append(ch); upcase = false; } } return buf.toString(); }
Example 3
Source File: AnnotationListConditionHandler.java From windup with Eclipse Public License 1.0 | 6 votes |
@Override public AnnotationCondition processElement(ParserContext handlerManager, Element element) throws ConfigurationException { String indexStr = element.getAttribute(INDEX); AnnotationListCondition condition; if (StringUtils.isNotBlank(indexStr)) condition = new AnnotationListCondition(Integer.parseInt(indexStr)); else condition = new AnnotationListCondition(); List<Element> children = $(element).children().get(); for (Element child : children) { switch (child.getNodeName()) { case AnnotationTypeConditionHandler.ANNOTATION_TYPE: case AnnotationListConditionHandler.ANNOTATION_LIST_CONDITION: case AnnotationLiteralConditionHandler.ANNOTATION_LITERAL: AnnotationCondition annotationCondition = handlerManager.processElement(child); condition.addCondition(annotationCondition); break; } } return condition; }
Example 4
Source File: ResourceTree.java From Juicebox with MIT License | 6 votes |
private DefaultMutableTreeNode createTreeFromDOM(Document document) { Element rootElement = (Element) document.getElementsByTagName(GLOBAL).item(0); if (rootElement == null) { return new DefaultMutableTreeNode(""); } String nodeName = rootElement.getNodeName(); if (!nodeName.equalsIgnoreCase(GLOBAL)) { throw new RuntimeException(rootElement + " is not the root of the xml document!"); } String rootLabel = getAttribute(rootElement, "name"); DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(rootLabel); // Build and attach descendants of the root node to the tree buildLocatorTree(rootNode, rootElement); return rootNode; }
Example 5
Source File: DefaultXmlConfigParse.java From nacos-spring-project with Apache License 2.0 | 6 votes |
private void recursionXmlToMap(Map<String, Object> outMap, Element element) { NodeList nodeList = element.getChildNodes(); String name = element.getNodeName(); if (nodeList.getLength() == 1 && !nodeList.item(0).hasChildNodes()) { addData(outMap, name, element.getTextContent()); } else { Map<String, Object> innerMap = new LinkedHashMap<String, Object>(1); int length = nodeList.getLength(); for (int i = 0; i < length; i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element tElement = (Element) node; recursionXmlToMap(innerMap, tElement); } } addData(outMap, name, innerMap); } }
Example 6
Source File: MULParser.java From megamek with GNU General Public License v2.0 | 6 votes |
public void parse(Element element) { String version = element.getAttribute(VERSION); if (version.equals("")){ warning.append("Warning: No version specified, correct parsing ") .append("not guaranteed!\n"); } String nodeName = element.getNodeName(); if(nodeName.equalsIgnoreCase(RECORD)) { parseRecord(element); } else if (nodeName.equalsIgnoreCase(UNIT)){ parseUnit(element, entities); } else if (nodeName.equalsIgnoreCase(ENTITY)){ parseEntity(element, entities); } else { warning.append("Error: root element isn't a Record, Unit, or Entity tag! ") .append("Nothing to parse!\n"); } }
Example 7
Source File: ResponseParser.java From supervisord4j with Apache License 2.0 | 6 votes |
private Object extract(Element element) { Element childElement = getOnlyChildElement(element.getChildNodes()); String nodeName = childElement.getNodeName(); TYPE type = TYPE.valueOf(nodeName.toUpperCase()); switch (type) { case INT: return extractInt(childElement); case BOOLEAN: return true; case STRING: return extractString(childElement); case STRUCT: return extractStruct(childElement); case ARRAY: return extractArray(childElement); default: return 0; } }
Example 8
Source File: XmlElement.java From allure2 with Apache License 2.0 | 6 votes |
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public XmlElement(final Element element) { this.name = element.getNodeName(); final NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { final Node item = attributes.item(i); this.attributes.put(item.getNodeName(), item.getNodeValue()); } final StringBuilder textValue = new StringBuilder(); final NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { final Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { this.children.add(new XmlElement((Element) node)); } if (node.getNodeType() == Node.TEXT_NODE) { textValue.append(node.getNodeValue()); } if (node.getNodeType() == Node.CDATA_SECTION_NODE) { textValue.append(((CharacterData) node).getData()); } } this.value = textValue.toString(); }
Example 9
Source File: BundleLoader.java From birt with Eclipse Public License 1.0 | 5 votes |
protected ConfigurationElement parseConfiguration( Object parent, Element element ) { ConfigurationElement config = new ConfigurationElement( ); config.parent = parent; config.name = element.getNodeName( ); config.attributes = new HashMap<String, String>( ); NamedNodeMap nodeAttrs = element.getAttributes( ); for ( int i = 0; i < nodeAttrs.getLength( ); i++ ) { Node attr = nodeAttrs.item( i ); String nodeName = attr.getNodeName( ); String nodeValue = attr.getNodeValue( ); nodeValue = loadProperty( nodeValue ); config.attributes.put( nodeName, nodeValue ); } ArrayList<ConfigurationElement> childConfigs = new ArrayList<ConfigurationElement>( ); NodeList children = element.getChildNodes( ); for ( int i = 0; i < children.getLength( ); i++ ) { Node node = children.item( i ); if ( node.getNodeType( ) == Node.ELEMENT_NODE ) { ConfigurationElement childConfig = parseConfiguration( config, (Element) node ); childConfigs.add( childConfig ); } } config.children = childConfigs .toArray( new ConfigurationElement[childConfigs.size( )] ); return config; }
Example 10
Source File: AbstractXmlBinding.java From arctic-sea with Apache License 2.0 | 5 votes |
private XmlNamespaceOperationDecoderKey getNamespaceOperationDecoderKey(Element element) { String nodeName = element.getNodeName(); if (Strings.isNullOrEmpty(element.getNamespaceURI())) { String[] splittedNodeName = nodeName.split(":"); String elementName; String namespace; String name; String prefix = null; if (splittedNodeName.length == 2) { prefix = splittedNodeName[0]; elementName = splittedNodeName[1]; } else { elementName = splittedNodeName[0]; } // TODO get namespace for prefix if (prefix == null || prefix.isEmpty()) { name = W3CConstants.AN_XMLNS; } else { name = W3CConstants.PREFIX_XMLNS + prefix; } namespace = element.getAttribute(name); return new XmlNamespaceOperationDecoderKey(namespace, elementName); } else { return new XmlNamespaceOperationDecoderKey(element.getNamespaceURI(), nodeName.substring(nodeName.indexOf(':') + 1)); } }
Example 11
Source File: ElementSelectors.java From xmlunit with Apache License 2.0 | 5 votes |
static Predicate<Element> elementNamePredicate(final String expectedName) { return new Predicate<Element>() { @Override public boolean test(Element e) { if (e == null) { return false; } String name = e.getLocalName(); if (name == null) { name = e.getNodeName(); } return expectedName.equals(name); } }; }
Example 12
Source File: PastePropertiesAction.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private void pasteProperties(final DisplayEditor editor, final List<Widget> widgets) { try { final ByteArrayInputStream clipstream = new ByteArrayInputStream(Clipboard.getSystemClipboard().getString().getBytes()); final ModelReader model_reader = new ModelReader(clipstream); final Element xml = XMLUtil.getChildElement(model_reader.getRoot(), "properties"); if (xml == null) throw new Exception("Clipboard does not hold properties"); for (final Element prop_xml : XMLUtil.getChildElements(xml)) { final String prop_name = prop_xml.getNodeName(); for (Widget widget : widgets) { // Skip unknown properties final Optional<WidgetProperty<Object>> prop = widget.checkProperty(prop_name); if (! prop.isPresent()) continue; // Update property's value from XML final WidgetProperty<Object> property = prop.get(); final Object orig_value = property.getValue(); property.readFromXML(model_reader, prop_xml); final Object value = property.getValue(); // Register with undo/redo editor.getUndoableActionManager().add(new SetWidgetPropertyAction<>(property, orig_value, value)); } } } catch (Exception ex) { ExceptionDetailsErrorDialog.openError("Paste Properties", "Cannot paste properties", ex); } }
Example 13
Source File: ModelViewEntity.java From scipio-erp with Apache License 2.0 | 5 votes |
public ComplexAlias(Element complexAliasElement) { this.operator = complexAliasElement.getAttribute("operator").intern(); // handle all complex-alias and complex-alias-field sub-elements for (Element subElement: UtilXml.childElementList(complexAliasElement)) { String nodeName = subElement.getNodeName(); if ("complex-alias".equals(nodeName)) { this.addComplexAliasMember(new ComplexAlias(subElement)); } else if ("complex-alias-field".equals(nodeName)) { this.addComplexAliasMember(new ComplexAliasField(subElement)); } } }
Example 14
Source File: ExtractorModelParser_v1.java From link-move with Apache License 2.0 | 5 votes |
protected void doParse(Element rootElement, MutableExtractorModelContainer container, MutableExtractorModel extractor) throws DOMException { NodeList nodes = rootElement.getChildNodes(); int len = nodes.getLength(); for (int i = 0; i < len; i++) { Node c = nodes.item(i); if (Node.ELEMENT_NODE == c.getNodeType()) { Element e = (Element) c; switch (e.getNodeName()) { case "type": // enough to set this at the container level.. extractor // will inherit the type container.setType(e.getTextContent()); break; case "connectorId": // enough to set this at the container level.. extractor // will inherit the connectorId container.addConnectorId(e.getTextContent()); break; case "attributes": processAttributes(e, extractor); break; case "properties": processProperties(e, extractor); break; } } } }
Example 15
Source File: XmlUtils.java From ats-framework with Apache License 2.0 | 5 votes |
/** * * @param node the node {@link Element} * @param attributeName the attribute name * @return the attribute value * @throws XMLException if the mandatory attribute is missing or its value is empty */ public static String getMandatoryAttribute( Element node, String attributeName ) throws XMLException { String attributeValue = getAttribute(node, attributeName); if (StringUtils.isNullOrEmpty(attributeValue)) { throw new XMLException(node.getNodeName() + " is missing mandatory attribute '" + attributeName + "'"); } return attributeValue; }
Example 16
Source File: UDA10ServiceDescriptorBinderImpl.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
protected void hydrateRoot(MutableService descriptor, Element rootElement) throws DescriptorBindingException { // We don't check the XMLNS, nobody bothers anyway... if (!ELEMENT.scpd.equals(rootElement)) { throw new DescriptorBindingException("Root element name is not <scpd>: " + rootElement.getNodeName()); } NodeList rootChildren = rootElement.getChildNodes(); for (int i = 0; i < rootChildren.getLength(); i++) { Node rootChild = rootChildren.item(i); if (rootChild.getNodeType() != Node.ELEMENT_NODE) continue; if (ELEMENT.specVersion.equals(rootChild)) { // We don't care about UDA major/minor specVersion anymore - whoever had the brilliant idea that // the spec versions can be declared on devices _AND_ on their services should have their fingers // broken so they never touch a keyboard again. // hydrateSpecVersion(descriptor, rootChild); } else if (ELEMENT.actionList.equals(rootChild)) { hydrateActionList(descriptor, rootChild); } else if (ELEMENT.serviceStateTable.equals(rootChild)) { hydrateServiceStateTableList(descriptor, rootChild); } else { log.finer("Ignoring unknown element: " + rootChild.getNodeName()); } } }
Example 17
Source File: DomElements.java From lightning with MIT License | 5 votes |
public static int getIntegerValueFromElement(Element element, String subElement) { String elementValue = getSubElementValueByTagName(element, subElement); try { return Integer.parseInt(elementValue); } catch (NumberFormatException e) { String parentNodeName = element.getNodeName(); String errorMessage = String.format(EXCEPTION_MESSAGE, subElement, parentNodeName, elementValue); throw new NumberFormatException(errorMessage); } }
Example 18
Source File: WeiboResponseUtil.java From albert with MIT License | 5 votes |
public static void ensureRootNodeNameIs(String rootName, Document doc) throws WeiboException { Element elem = doc.getDocumentElement(); if (!rootName.equals(elem.getNodeName())) { throw new WeiboException("Unexpected root node name:" + elem.getNodeName() + ". Expected:" + rootName + ". Check the availability of the Weibo API at http://open.t.sina.com.cn/"); } }
Example 19
Source File: AtsProjectConfiguration.java From ats-framework with Apache License 2.0 | 4 votes |
public void loadConfigurationFile() { sourceProject = null; agents.clear(); applications.clear(); shellCommands.clear(); try { doc = DocumentBuilderFactory.newInstance() .newDocumentBuilder() .parse(new File(atsConfigurationFile)); doc.getDocumentElement().normalize(); } catch (Exception e) { throw new AtsConfigurationException("Error reading ATS configuration file '" + atsConfigurationFile + "'", e); } Element atsProjectNode = doc.getDocumentElement(); if (!NODE_ATS_PROJECT.equals(atsProjectNode.getNodeName())) { throw new AtsConfigurationException("Bad ATS configuration file. Root node name is expected to be '" + NODE_ATS_PROJECT + "', but it is '" + atsProjectNode.getNodeName() + "'"); } // project with source libraries List<Element> sourceNodes = XmlUtils.getChildrenByTagName(atsProjectNode, NODE_SOURCE_PROJECT); if (sourceNodes.size() != 1) { throw new AtsConfigurationException("Bad ATS configuration file. We must have exactly 1 " + NODE_SOURCE_PROJECT + " node, but we got " + sourceNodes.size()); } sourceProject = new AtsSourceProjectInfo(sourceNodes.get(0)); // load the default agent values final Map<String, String> agentDefaultValues = readAgentGlobalProperties(atsProjectNode); // ATS agents List<Element> agentNodes = XmlUtils.getChildrenByTagName(atsProjectNode, NODE_ATS_AGENT); for (Element agentNode : agentNodes) { String agentAlias = XmlUtils.getMandatoryAttribute(agentNode, NODE_ATTRIBUTE_ALIAS); if (agents.containsKey(agentAlias)) { throw new AtsConfigurationException("'" + agentAlias + "' is not a unique agent alias"); } agents.put(agentAlias, new AgentInfo(agentAlias, agentNode, agentDefaultValues)); } // make sure we do not have same: host + port or host + path checkForDuplicatedHostAndPort(agents); checkForDuplicatedHostAndHome(agents); // Generic applications List<Element> applicationNodes = XmlUtils.getChildrenByTagName(atsProjectNode, NODE_APPLICATION); for (Element applicationNode : applicationNodes) { String applicationAlias = XmlUtils.getMandatoryAttribute(applicationNode, NODE_ATTRIBUTE_ALIAS); if (applications.containsKey(applicationAlias)) { throw new AtsConfigurationException("'" + applicationAlias + "' is not a unique application alias"); } applications.put(applicationAlias, new ApplicationInfo(applicationAlias, applicationNode, agentDefaultValues)); } // make sure we do not have same: host + port or host + path checkForDuplicatedHostAndPort(applications); checkForDuplicatedHostAndHome(applications); // Shell commands List<Element> shellCommandsNodes = XmlUtils.getChildrenByTagName(atsProjectNode, NODE_SHELL_COMMANDS); if (shellCommandsNodes.size() > 0) { // now get the actual commands shellCommandsNodes = XmlUtils.getChildrenByTagName(shellCommandsNodes.get(0), "command"); for (Element commandNode : shellCommandsNodes) { String shellCommandAlias = XmlUtils.getAttribute(commandNode, NODE_ATTRIBUTE_ALIAS); String theCommand = commandNode.getTextContent(); shellCommands.add(new ShellCommand(shellCommandAlias, theCommand)); } } }
Example 20
Source File: Calculate.java From scipio-erp with Apache License 2.0 | 4 votes |
public Calculate(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); if (MiniLangValidate.validationOn()) { if (MiniLangValidate.deprecatedCommonOn()) { // SCIPIO MiniLangValidate.handleError("<calculate> element is deprecated (use <set>)", simpleMethod, element); } MiniLangValidate.attributeNames(simpleMethod, element, "field", "decimal-scale", "decimal-format", "rounding-mode", "type"); MiniLangValidate.requiredAttributes(simpleMethod, element, "field"); MiniLangValidate.expressionAttributes(simpleMethod, element, "field"); MiniLangValidate.childElements(simpleMethod, element, "calcop", "number"); } this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field")); this.decimalFormatFse = FlexibleStringExpander.getInstance(element.getAttribute("decimal-format")); this.decimalScaleFse = FlexibleStringExpander.getInstance(element.getAttribute("decimal-scale")); this.roundingModeFse = FlexibleStringExpander.getInstance(element.getAttribute("rounding-mode")); this.typeString = element.getAttribute("type"); int type = Calculate.TYPE_BIG_DECIMAL; if ("Double".equals(typeString)) { type = Calculate.TYPE_DOUBLE; } else if ("Float".equals(typeString)) { type = Calculate.TYPE_FLOAT; } else if ("Long".equals(typeString)) { type = Calculate.TYPE_LONG; } else if ("Integer".equals(typeString)) { type = Calculate.TYPE_INTEGER; } else if ("String".equals(typeString)) { type = Calculate.TYPE_STRING; } else if ("BigDecimal".equals(typeString)) { type = Calculate.TYPE_BIG_DECIMAL; } this.type = type; List<? extends Element> calcopElements = UtilXml.childElementList(element); calcops = new Calculate.SubCalc[calcopElements.size()]; int i = 0; for (Element calcopElement : calcopElements) { String nodeName = calcopElement.getNodeName(); if ("calcop".equals(nodeName)) { calcops[i] = new CalcOp(calcopElement, simpleMethod); } else if ("number".equals(nodeName)) { calcops[i] = new NumberOp(calcopElement, simpleMethod); } else { MiniLangValidate.handleError("Invalid calculate sub-element.", simpleMethod, calcopElement); calcops[i] = new InvalidOp(calcopElement, simpleMethod); } i++; } }