Java Code Examples for org.w3c.dom.Element#getTagName()
The following examples show how to use
org.w3c.dom.Element#getTagName() .
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: DefaultTeXFontParser.java From FlexibleRichTextView with Apache License 2.0 | 6 votes |
public static int getIntAndCheck(String attrName, Element element) throws ResourceParseException { String attrValue = getAttrValueAndCheckIfNotNull(attrName, element); // try parsing string to integer value int res = 0; try { res = Integer.parseInt(attrValue); } catch (NumberFormatException e) { throw new XMLResourceParseException(RESOURCE_NAME, element.getTagName(), attrName, "has an invalid integer value!"); } // parsing OK return res; }
Example 2
Source File: PersistenceUnitDescriptorImpl.java From jpa-unit with Apache License 2.0 | 6 votes |
private void parseChild(final NodeList children, final int i) { final Element element = (Element) children.item(i); final String tag = element.getTagName(); if (tag.equals(ENTRY_PROVIDER)) { providerClassName = extractContent(element); } else if (tag.equals(ENTRY_PROPERTIES)) { parseProperties(element); } else if (tag.equals(ENTRY_CLASS)) { final String className = extractContent(element); try { classList.add(Class.forName(className, false, Thread.currentThread().getContextClassLoader())); } catch (final ClassNotFoundException e) { throw new JpaUnitException("Could not find class: " + className, e); } } }
Example 3
Source File: AnnotationDrivenBeanDefinitionParser.java From JGiven with Apache License 2.0 | 6 votes |
@Override public BeanDefinition parse( Element element, ParserContext parserContext ) { AopNamespaceUtils.registerAutoProxyCreatorIfNecessary( parserContext, element ); if( !parserContext.getRegistry().containsBeanDefinition( BEAN_NAME ) ) { Object eleSource = parserContext.extractSource( element ); RootBeanDefinition stageCreator = new RootBeanDefinition( SpringStageCreator.class ); stageCreator.setSource( eleSource ); stageCreator.setRole( BeanDefinition.ROLE_INFRASTRUCTURE ); String executorName = parserContext.getReaderContext().registerWithGeneratedName( stageCreator ); logger.debug( "Registered SpringStageCreator with name " + executorName ); RootBeanDefinition beanFactoryPostProcessor = new RootBeanDefinition( JGivenBeanFactoryPostProcessor.class ); beanFactoryPostProcessor.setRole( BeanDefinition.ROLE_INFRASTRUCTURE ); parserContext.getRegistry().registerBeanDefinition( BEAN_NAME, beanFactoryPostProcessor ); CompositeComponentDefinition componentDefinition = new CompositeComponentDefinition( element.getTagName(), eleSource ); componentDefinition.addNestedComponent( new BeanComponentDefinition( stageCreator, executorName ) ); componentDefinition.addNestedComponent( new BeanComponentDefinition( beanFactoryPostProcessor, BEAN_NAME ) ); parserContext.registerComponent( componentDefinition ); } return null; }
Example 4
Source File: WidgetDocumentInfo.java From scipio-erp with Apache License 2.0 | 6 votes |
/** * Makes description for an element, including tag name, location, and column/line, * for log/error messages. * FIXME: seems redundant, there is another utility somewhere that does this? */ public static String getElementDescriptor(Element element) { String desc = "element: " + element.getTagName(); String location = getResourceLocation(element); if (location != null) { desc += ", location: " + location; } Integer startLine = (Integer) element.getUserData("startLine"); if (startLine != null) { desc += ", line: " + startLine; } Integer startColumn = (Integer) element.getUserData("startColumn"); if (startColumn != null) { desc += ", column: " + startColumn; } return desc; }
Example 5
Source File: HtmlPanel.java From jamel with GNU General Public License v3.0 | 5 votes |
/** * Creates and returns a new HtmlPanel. * * @param elem * the description of the panel to be created. * @param gui * the parent gui. * @param expressionFactory * the expression factory. */ private HtmlPanel(final Element elem, final Gui gui, final ExpressionFactory expressionFactory) { super(); // TODO utiliser Parameters au lieu de Element final Element panelDescription; if (elem.hasAttribute("src")) { /* * Opens and reads the XML file that contains the specification of the panel. */ final String src = elem.getAttribute("src"); final String fileName = gui.getFile().getParent() + "/" + src; final File panelFile = new File(fileName); final Element root; try { root = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(panelFile).getDocumentElement(); } catch (final Exception e) { throw new RuntimeException("Something went wrong while reading \"" + fileName + "\"", e); } if (!root.getTagName().equals("html")) { throw new RuntimeException(fileName + ": Bad element: " + root.getTagName()); } panelDescription = root; } else { panelDescription = elem; } this.htmlElement = getNewHtmlElement(panelDescription, gui.getSimulation(), expressionFactory); init(this); this.text = this.htmlElement.getText(); }
Example 6
Source File: XMLParser_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
public Object buildObjectOrPrimitive(Element aElement, ParsingOptions aOptions) throws InvalidXMLException { // attempt to locate a Class that can be built from the element Class<? extends XMLizable> cls = mElementToClassMap.get(aElement.getTagName()); if (cls == null) { // attempt to parse as primitive Object primObj = XMLUtils.readPrimitiveValue(aElement); if (primObj != null) { return primObj; } // unknown element - throw exception throw new InvalidXMLException(InvalidXMLException.UNKNOWN_ELEMENT, new Object[] { aElement .getTagName() }); } // resolve the class name and instantiate the class XMLizable object; try { object = cls.newInstance(); } catch (Exception e) { throw new UIMA_IllegalStateException( UIMA_IllegalStateException.COULD_NOT_INSTANTIATE_XMLIZABLE, new Object[] { cls .getName() }, e); } // construct the XMLizable object from the XML element callBuildFromXMLElement(aElement, object, aOptions); return object; }
Example 7
Source File: PackageGenerator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static PackageGenerator processDataSet(Element rootElement) { PackageGenerator result = new PackageGenerator(); result.isDataSetProcessed = true; result.topLevels = new ArrayList<>(); result.nameIndex = new HashMap<>(); result.idBases = new HashMap<>(); result.idAnnos = new HashMap<>(); result.fx = false; if (!rootElement.getTagName().equals("package")) { throw new IllegalStateException("Unexpected tag name: " + rootElement.getTagName()); } result.packageName = rootElement.getAttribute("name"); result.id = rootElement.getAttribute("id"); result.fx = "fx".equals(rootElement.getAttribute("style")); result.packageDirName = result.packageName.replace('.', '/'); // process nodes (toplevels) NodeList nodeList = rootElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (!(node instanceof Element)) { continue; } result.processTopLevel((Element) node); } return result; }
Example 8
Source File: XMLTools.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * This method will return null if the element doesn't exist if obligatory is false. Otherwise * an exception is thrown. If the element is not unique, an exception is thrown in any cases. */ public static Element getUniqueInnerTag(Element element, String tagName, boolean obligatory) throws XMLException { NodeList children = element.getChildNodes(); Collection<Element> elements = new ArrayList<Element>(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i) instanceof Element) { Element child = (Element) children.item(i); if (tagName.equals(child.getTagName())) { elements.add(child); } } } switch (elements.size()) { case 0: if (obligatory) { throw new XMLException("Missing inner tag <" + tagName + "> inside <" + element.getTagName() + ">."); } else { return null; } case 1: return elements.iterator().next(); default: throw new XMLException("Inner tag <" + tagName + "> inside <" + element.getTagName() + "> must be unique, but found " + children.getLength() + "."); } }
Example 9
Source File: AbstractListenerContainerParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); PropertyValues commonProperties = parseCommonContainerProperties(element, parserContext); PropertyValues specificProperties = parseSpecificContainerProperties(element, parserContext); String factoryId = element.getAttribute(FACTORY_ID_ATTRIBUTE); if (StringUtils.hasText(factoryId)) { RootBeanDefinition beanDefinition = createContainerFactory( factoryId, element, parserContext, commonProperties, specificProperties); if (beanDefinition != null) { beanDefinition.setSource(parserContext.extractSource(element)); parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, factoryId)); } } NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { String localName = parserContext.getDelegate().getLocalName(child); if (LISTENER_ELEMENT.equals(localName)) { parseListener(element, (Element) child, parserContext, commonProperties, specificProperties); } } } parserContext.popAndRegisterContainingComponent(); return null; }
Example 10
Source File: AbstractListenerContainerParser.java From java-technology-stack with MIT License | 5 votes |
@Override @Nullable public BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); MutablePropertyValues commonProperties = parseCommonContainerProperties(element, parserContext); MutablePropertyValues specificProperties = parseSpecificContainerProperties(element, parserContext); String factoryId = element.getAttribute(FACTORY_ID_ATTRIBUTE); if (StringUtils.hasText(factoryId)) { RootBeanDefinition beanDefinition = createContainerFactory( factoryId, element, parserContext, commonProperties, specificProperties); if (beanDefinition != null) { beanDefinition.setSource(parserContext.extractSource(element)); parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, factoryId)); } } NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { String localName = parserContext.getDelegate().getLocalName(child); if (LISTENER_ELEMENT.equals(localName)) { parseListener(element, (Element) child, parserContext, commonProperties, specificProperties); } } } parserContext.popAndRegisterContainingComponent(); return null; }
Example 11
Source File: PredefinedTeXFormulaParser.java From AndroidMathKeyboard with Apache License 2.0 | 5 votes |
private static String getAttrValueAndCheckIfNotNull(String attrName, Element element) throws ResourceParseException { String attrValue = element.getAttribute(attrName); if (attrValue.equals("")) throw new XMLResourceParseException(RESOURCE_NAME, element.getTagName(), attrName, null); return attrValue; }
Example 12
Source File: GlueSettingsParser.java From lams with GNU General Public License v2.0 | 5 votes |
private static String getAttrValueAndCheckIfNotNull(String attrName, Element element) throws ResourceParseException { String attrValue = element.getAttribute(attrName); if (attrValue.equals("")) throw new XMLResourceParseException(RESOURCE_NAME, element.getTagName(), attrName, null); return attrValue; }
Example 13
Source File: PredefinedTeXFormulaParser.java From FlexibleRichTextView with Apache License 2.0 | 5 votes |
private static String getAttrValueAndCheckIfNotNull(String attrName, Element element) throws ResourceParseException { String attrValue = element.getAttribute(attrName); if (attrValue.equals("")) throw new XMLResourceParseException(RESOURCE_NAME, element.getTagName(), attrName, null); return attrValue; }
Example 14
Source File: Canonicalizer20010315.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Returns the Attr[]s to be output for the given element. * <br> * The code of this method is a copy of {@link #handleAttributes(Element, * NameSpaceSymbTable)}, * whereas it takes into account that subtree-c14n is -- well -- subtree-based. * So if the element in question isRoot of c14n, it's parent is not in the * node set, as well as all other ancestors. * * @param element * @param ns * @return the Attr[]s to be output * @throws CanonicalizationException */ @Override protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns) throws CanonicalizationException { if (!element.hasAttributes() && !firstCall) { return null; } // result will contain the attrs which have to be output final SortedSet<Attr> result = this.result; result.clear(); if (element.hasAttributes()) { NamedNodeMap attrs = element.getAttributes(); int attrsLength = attrs.getLength(); for (int i = 0; i < attrsLength; i++) { Attr attribute = (Attr) attrs.item(i); String NUri = attribute.getNamespaceURI(); String NName = attribute.getLocalName(); String NValue = attribute.getValue(); if (!XMLNS_URI.equals(NUri)) { //It's not a namespace attr node. Add to the result and continue. result.add(attribute); } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) { //The default mapping for xml must not be output. Node n = ns.addMappingAndRender(NName, NValue, attribute); if (n != null) { //Render the ns definition result.add((Attr)n); if (C14nHelper.namespaceIsRelative(attribute)) { Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() }; throw new CanonicalizationException( "c14n.Canonicalizer.RelativeNamespace", exArgs ); } } } } } if (firstCall) { //It is the first node of the subtree //Obtain all the namespaces defined in the parents, and added to the output. ns.getUnrenderedNodes(result); //output the attributes in the xml namespace. xmlattrStack.getXmlnsAttr(result); firstCall = false; } return result.iterator(); }
Example 15
Source File: ActionMappingScanner.java From netbeans with Apache License 2.0 | 4 votes |
/** * Scan through Element named action. */ void visitElement_action(Element element) { String name = element.getAttribute("name"); mapping = new DefaultActionMapping(name); mapping.withPlugins = withPlugins; NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); String value = attr.getValue(); switch (attr.getName()) { case "displayName": mapping.displayName = value; break; case "repeatable": mapping.repeatableAction = Boolean.parseBoolean(value); break; case "priority": try { mapping.priority = Integer.parseInt(value); } catch (NumberFormatException ex) { } break; } } NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element nodeElement = (Element) node; switch (nodeElement.getTagName()) { case "reload": visitElement_reload(nodeElement); break; case "args": mapping.args = visitElement_args(nodeElement); break; } } } mappings.add(mapping); }
Example 16
Source File: AndroidStringsXmlReader.java From mojito with Apache License 2.0 | 4 votes |
private static List<AndroidStringsTextUnit> fromDocument(Document document, String pluralNameSeparator) { List<AndroidStringsTextUnit> resultList = new ArrayList<>(); Node lastCommentNode = null; for (int i = 0; i < document.getDocumentElement().getChildNodes().getLength(); i++) { Node currentNode = document.getDocumentElement().getChildNodes().item(i); if (Node.COMMENT_NODE == currentNode.getNodeType()) { lastCommentNode = currentNode; } else if (Node.ELEMENT_NODE == currentNode.getNodeType()) { Element currentElement = (Element) currentNode; switch (currentElement.getTagName()) { case SINGULAR_ELEMENT_NAME: resultList.add(createSingular( getAttribute(currentElement, NAME_ATTRIBUTE_NAME), removeEscape(currentElement.getTextContent()), getContent(lastCommentNode), getAttribute(currentElement, ID_ATTRIBUTE_NAME))); break; case PLURAL_ELEMENT_NAME: String comment = getContent(lastCommentNode); String name = getAttribute(currentElement, NAME_ATTRIBUTE_NAME); NodeList nodeList = currentElement.getElementsByTagName(PLURAL_ITEM_ELEMENT_NAME); for (int j = 0; j < nodeList.getLength(); j++) { if (Node.ELEMENT_NODE == nodeList.item(j).getNodeType()) { Element itemElement = (Element) nodeList.item(j); resultList.add(createPlural(name, PluralItem.valueOf(getAttribute(itemElement, QUANTITY_ATTRIBUTE_NAME)), removeEscape(itemElement.getTextContent()), comment, getAttribute(itemElement, ID_ATTRIBUTE_NAME), pluralNameSeparator)); } } break; } } } return resultList; }
Example 17
Source File: ConfigModelRepo.java From vespa with Apache License 2.0 | 4 votes |
/** * Creates all the config models specified in the given XML element and * passes their respective XML node as parameter. * * @param root The Root to set as parent for all plugins * @param servicesRoot XML root node of the services file */ private void readConfigModels(ApplicationConfigProducerRoot root, Element servicesRoot, DeployState deployState, VespaModel vespaModel, ConfigModelRegistry configModelRegistry) throws IOException, SAXException { final Map<ConfigModelBuilder, List<Element>> model2Element = new LinkedHashMap<>(); ModelGraphBuilder graphBuilder = new ModelGraphBuilder(); final List<Element> children = getServiceElements(servicesRoot); if (XML.getChild(servicesRoot, "admin") == null) children.add(getImplicitAdmin(deployState)); children.addAll(getPermanentServices(deployState)); for (Element servicesElement : children) { String tagName = servicesElement.getTagName(); if (tagName.equals("config")) { // TODO: disallow on Vespa 8 continue; } if (tagName.equals("cluster")) { throw new IllegalArgumentException("<" + tagName + "> on top-level is not allowed anymore"); } if ((tagName.equals("clients")) && deployState.isHosted()) throw new IllegalArgumentException("<" + tagName + "> is not allowed when running Vespa in a hosted environment"); String tagVersion = servicesElement.getAttribute("version"); ConfigModelId xmlId = ConfigModelId.fromNameAndVersion(tagName, tagVersion); Collection<ConfigModelBuilder> builders = configModelRegistry.resolve(xmlId); if (builders.isEmpty()) throw new RuntimeException("Could not resolve tag <" + tagName + " version=\"" + tagVersion + "\"> to a config model component"); for (ConfigModelBuilder builder : builders) { if ( ! model2Element.containsKey(builder)) { model2Element.put(builder, new ArrayList<>()); graphBuilder.addBuilder(builder); } model2Element.get(builder).add(servicesElement); } } for (ModelNode node : graphBuilder.build().topologicalSort()) buildModels(node, getApplicationType(servicesRoot), deployState, vespaModel, root, model2Element.get(node.builder)); for (ConfigModel model : configModels) model.initialize(ConfigModelRepo.this); // XXX deprecated }
Example 18
Source File: PackageGenerator.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
ListBuffer<JCTree> processFields(Element fieldsNode, HashMap<String, Integer> scope) { String kind = fieldsNode.getTagName(); String baseName = fieldsNode.getAttribute("basename"); ListBuffer<JCTree> fields = new ListBuffer<>(); NodeList nodes = fieldsNode.getChildNodes(); SimpleMultiplier multiply = new SimpleMultiplier(); // for modifiers String[] types = new String[] {}; for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (!(node instanceof Element)) continue; // parse type and modifiers switch (((Element)node).getTagName()) { case "modifier": multiply.addAxis(((Element)node).getTextContent()); break; case "anno": multiply.addAxis(((Element)node).getTextContent()); case "type": types = ((Element)node).getTextContent().split("\\|"); break; } } // process through modifiers and types multiply.initIterator(); while (multiply.hasNext()) { ArrayList<String> tuple = multiply.getNext(); long declFlags = 0; ListBuffer<JCAnnotation> annos = new ListBuffer<>(); for (String modifier : tuple) { if (modifier.startsWith("@") && idAnnos.containsKey(modifier)) annos.add(idAnnos.get(modifier)); // it's anno else declFlags |= getFlagByName(modifier); // it's modifier } for (String type : types) { String declName = baseName + getUniqIndex(scope, baseName); Type initType = getTypeByName(type); JCExpression initExpr = null; if ((declFlags & Flags.STATIC) != 0) // static to be initialized initExpr = make.Literal(initType.isPrimitive() ? initType.getTag() : TypeTag.BOT, "String".equals(type) ? new String("blah-blah-blah") : Integer.valueOf(0)); JCVariableDecl fieldDecl = make.VarDef( make.Modifiers(declFlags, annos.toList()), names.fromString(declName), make.Type(getTypeByName(type)), initExpr); fields.append(fieldDecl); } } return fields; }
Example 19
Source File: TextSerializer.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Called to serialize a DOM element. Equivalent to calling {@link * #startElement}, {@link #endElement} and serializing everything * inbetween, but better optimized. */ protected void serializeElement( Element elem ) throws IOException { Node child; ElementState state; boolean preserveSpace; String tagName; tagName = elem.getTagName(); state = getElementState(); if ( isDocumentState() ) { // If this is the root element handle it differently. // If the first root element in the document, serialize // the document's DOCTYPE. Space preserving defaults // to that of the output format. if ( ! _started ) startDocument( tagName ); } // For any other element, if first in parent, then // use the parnet's space preserving. preserveSpace = state.preserveSpace; // Do not change the current element state yet. // This only happens in endElement(). // Ignore all other attributes of the element, only printing // its contents. // If element has children, then serialize them, otherwise // serialize en empty tag. if ( elem.hasChildNodes() ) { // Enter an element state, and serialize the children // one by one. Finally, end the element. state = enterElementState( null, null, tagName, preserveSpace ); child = elem.getFirstChild(); while ( child != null ) { serializeNode( child ); child = child.getNextSibling(); } endElementIO( tagName ); } else { if ( ! isDocumentState() ) { // After element but parent element is no longer empty. state.afterElement = true; state.empty = false; } } }
Example 20
Source File: TableProcessor.java From birt with Eclipse Public License 1.0 | 4 votes |
private void processNodes( Element ele ) { for ( Node node = ele.getFirstChild( ); node != null; node = node .getNextSibling( ) ) { if ( node.getNodeType( ) != Node.ELEMENT_NODE ) { continue; } Element element = (Element) node; String tagName = element.getTagName( ); if ( "tr".equals( tagName ) ) { RowState rowState = new RowState( element, cssStyles, content, action, records, index ); rowState.processNodes( ); columnCount = Math.max( columnCount, rowState.getColumnCount( ) ); if ( columnCount > table.getColumnCount( ) ) { addColumn( columnCount - table.getColumnCount( ) ); } ++rowCount; ++index; } else if ( "col".equals( tagName ) ) { Column column = new Column( content.getReportContent( ) ); DimensionType cw = PropertyUtil.getDimensionAttribute( element, "width" ); if ( cw != null ) { column.setWidth( cw ); } ( (TableContent) content ).addColumn( column ); handleColumnStyle( element, cssStyles, column ); } else if ( "tbody".equals( tagName ) || "thead".equals( tagName ) || "tfoot".equals( tagName ) ) { processNodes( element ); } } }