List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:applab.search.client.JsonSimpleParser.java
static String getKeywordsVersion(Document document) { Element rootNode = document.getDocumentElement(); if (rootNode != null) { String version = rootNode.getAttribute(VERSION_ATTRIBUTE_NAME); if (version.length() > 0) { return version; }//from ww w .jav a2 s . co m } return ""; }
From source file:net.sourceforge.dita4publishers.word2dita.Word2DitaValidationHelper.java
/** * @param pkg/*from w ww. j a v a 2 s. com*/ * @param bosOptions * @throws Exception */ static void addCommentFileRelationship(ZipComponents zipComponents, BosConstructionOptions bosOptions) throws Exception { ZipComponent comp = zipComponents.getEntry(DocxConstants.DOCUMENT_XML_RELS_PATH); Document doc = zipComponents.getDomForZipComponent(bosOptions, comp); Element docElem = doc.getDocumentElement(); NodeList nl = docElem.getElementsByTagNameNS(DocxConstants.RELS_NS, "Relationship"); boolean foundCommentRel = false; for (int i = 0; i < nl.getLength(); i++) { Element elem = (Element) nl.item(i); String type = elem.getAttribute("Type"); if (DocxConstants.COMMENT_REL_TYPE.equals(type)) { foundCommentRel = true; break; } } if (!foundCommentRel) { Element elem = doc.createElementNS(DocxConstants.RELS_NS, "Relationship"); elem.setAttribute("Type", DocxConstants.COMMENT_REL_TYPE); elem.setAttribute("Id", "rId" + (nl.getLength() + 1)); elem.setAttribute("Target", "comments.xml"); docElem.appendChild(elem); // System.out.println(IOUtils.toString(DomUtil.serializeToInputStream(doc, "utf-8"))); comp.setDom(doc); } }
From source file:Main.java
private static boolean equalElements(final Element a, final Element b) { if (!a.getTagName().equals(b.getTagName())) { return false; }// www . j a va 2 s . c o m final NamedNodeMap attributes = a.getAttributes(); int customAttributeCounter = 0; for (int i = 0, n = attributes.getLength(); i < n; i++) { final Node node = attributes.item(i); if (node != null && !node.getNodeName().startsWith("_")) { if (!node.getNodeName().equals("z") && (b.getAttribute(node.getNodeName()).length() == 0 || !b.getAttribute(node.getNodeName()).equals(node.getNodeValue()))) { return false; } } else { customAttributeCounter++; } } if (a.getAttributes().getLength() - customAttributeCounter != b.getAttributes().getLength()) { return false; } return true; }
From source file:com.weibo.api.motan.config.springsupport.MotanBeanDefinitionParser.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static void parseMethods(String id, NodeList nodeList, RootBeanDefinition beanDefinition, ParserContext parserContext) throws ClassNotFoundException { if (nodeList != null && nodeList.getLength() > 0) { ManagedList methods = null;/*from w w w. j a v a 2s . c o m*/ for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { Element element = (Element) node; if ("method".equals(node.getNodeName()) || "method".equals(node.getLocalName())) { String methodName = element.getAttribute("name"); if (methodName == null || methodName.length() == 0) { throw new IllegalStateException("<motan:method> name attribute == null"); } if (methods == null) { methods = new ManagedList(); } BeanDefinition methodBeanDefinition = parse((Element) node, parserContext, MethodConfig.class, false); String name = id + "." + methodName; BeanDefinitionHolder methodBeanDefinitionHolder = new BeanDefinitionHolder( methodBeanDefinition, name); methods.add(methodBeanDefinitionHolder); } } } if (methods != null) { beanDefinition.getPropertyValues().addPropertyValue("methods", methods); } } }
From source file:fll.xml.XMLUtils.java
public static List<String> getSubjectiveCategoryNames(final Document challengeDocument) { final List<String> subjectiveCategories = new LinkedList<String>(); for (final Element categoryElement : new NodelistElementCollectionAdapter( challengeDocument.getDocumentElement().getElementsByTagName("subjectiveCategory"))) { final String categoryName = categoryElement.getAttribute("name"); subjectiveCategories.add(categoryName); }/*from w ww . j av a2s .co m*/ return subjectiveCategories; }
From source file:com.msopentech.odatajclient.engine.data.Deserializer.java
private static ServiceDocumentResource toServiceDocumentFromXML(final InputStream input) { final Element service = toDOM(input); final XMLServiceDocument serviceDoc = new XMLServiceDocument(); serviceDoc.setBaseURI(URI.create(service.getAttribute(ODataConstants.ATTR_XMLBASE))); final NodeList collections = service.getElementsByTagName(ODataConstants.ELEM_COLLECTION); for (int i = 0; i < collections.getLength(); i++) { final Element collection = (Element) collections.item(i); final NodeList title = collection.getElementsByTagName(ODataConstants.ATOM_ATTR_TITLE); if (title.getLength() != 1) { throw new IllegalArgumentException("Invalid collection element found"); }/*from www. ja va2 s . com*/ serviceDoc.addToplevelEntitySet(title.item(0).getTextContent(), collection.getAttribute(ODataConstants.ATTR_HREF)); } return serviceDoc; }
From source file:com.impetus.kundera.ejb.PersistenceXmlLoader.java
/** * Parses the persistence unit.//from ww w. j av a2s. c o m * * @param top * the top * @return the persistence metadata * @throws Exception * the exception */ private static PersistenceMetadata parsePersistenceUnit(Element top) throws Exception { PersistenceMetadata metadata = new PersistenceMetadata(); String puName = top.getAttribute("name"); if (!isEmpty(puName)) { log.trace("Persistent Unit name from persistence.xml: " + puName); metadata.setName(puName); } NodeList children = top.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) children.item(i); String tag = element.getTagName(); if (tag.equals("provider")) { metadata.setProvider(getElementContent(element)); } else if (tag.equals("properties")) { NodeList props = element.getChildNodes(); for (int j = 0; j < props.getLength(); j++) { if (props.item(j).getNodeType() == Node.ELEMENT_NODE) { Element propElement = (Element) props.item(j); // if element is not "property" then skip if (!"property".equals(propElement.getTagName())) { continue; } String propName = propElement.getAttribute("name").trim(); String propValue = propElement.getAttribute("value").trim(); if (isEmpty(propValue)) { propValue = getElementContent(propElement, ""); } metadata.getProps().put(propName, propValue); } } } // Kundera doesn't support "class", "jar-file" and "excluded-unlisted-classes" for now.. but will someday. // let's parse it for now. else if (tag.equals("class")) { metadata.getClasses().add(getElementContent(element)); } else if (tag.equals("jar-file")) { metadata.getJarFiles().add(getElementContent(element)); } else if (tag.equals("exclude-unlisted-classes")) { metadata.setExcludeUnlistedClasses(true); } } } PersistenceUnitTransactionType transactionType = getTransactionType(top.getAttribute("transaction-type")); if (transactionType != null) { metadata.setTransactionType(transactionType); } return metadata; }
From source file:fll.xml.XMLUtils.java
/** * Find a subjective category by name.// w w w . ja v a2 s. c o m * * @param challengeDocument the document to look in * @param name the name to look for * @return the element or null if one is not found */ public static Element getSubjectiveCategoryByName(final Document challengeDocument, final String name) { for (final Element categoryElement : new NodelistElementCollectionAdapter( challengeDocument.getDocumentElement().getElementsByTagName("subjectiveCategory"))) { final String categoryName = categoryElement.getAttribute("name"); if (categoryName.equals(name)) { return categoryElement; } } return null; }
From source file:net.sourceforge.dita4publishers.word2dita.Word2DitaValidationHelper.java
/** * @param zipComponents//from w ww.j a va2 s . co m * @param bosOptions * @throws Exception */ public static void addCommentFileContentType(ZipComponents zipComponents, BosConstructionOptions bosOptions) throws Exception { /* * <Override PartName="/word/comments.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"/> */ ZipComponent comp = zipComponents.getEntry("[Content_Types].xml"); Document doc = zipComponents.getDomForZipComponent(bosOptions, comp); Element docElem = doc.getDocumentElement(); String contentTypesNs = "http://schemas.openxmlformats.org/package/2006/content-types"; NodeList nl = docElem.getElementsByTagNameNS(contentTypesNs, "Override"); boolean foundCommentType = false; for (int i = 0; i < nl.getLength(); i++) { Element elem = (Element) nl.item(i); String partName = elem.getAttribute("PartName"); if (DocxConstants.COMMENTS_PARTNAME.equals(partName)) { foundCommentType = true; break; } } if (!foundCommentType) { Element elem = doc.createElementNS(contentTypesNs, "Override"); elem.setAttribute("PartName", DocxConstants.COMMENTS_PARTNAME); elem.setAttribute("ContentType", DocxConstants.COMMENTS_CONTENT_TYPE); docElem.appendChild(elem); comp.setDom(doc); } }
From source file:eu.stork.peps.configuration.ConfigurationReader.java
/** * Read configuration./* w ww. jav a 2s . c om*/ * * @return the map< string, instance engine> * * @throws SAMLEngineException the STORKSAML engine runtime * exception */ public static Map<String, InstanceEngine> readConfiguration() throws SAMLEngineException { // fetch base from system properties, give a default if there is nothing configured String base = System.getProperty("eu.stork.samlengine.config.location"); if (null != base) if (!base.endsWith("/")) base += "/"; LOGGER.info("Init reader: " + base + ENGINE_CONF_FILE); final Map<String, InstanceEngine> instanceConfs = new HashMap<String, InstanceEngine>(); Document document = null; // Load configuration file final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; InputStream engineConf = null; try { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); builder = factory.newDocumentBuilder(); if (null != base) engineConf = new FileInputStream(base + ENGINE_CONF_FILE); else engineConf = ConfigurationReader.class.getResourceAsStream("/" + ENGINE_CONF_FILE); document = builder.parse(engineConf); // Read instance final NodeList list = document.getElementsByTagName(NODE_INSTANCE); for (int indexElem = 0; indexElem < list.getLength(); ++indexElem) { final Element element = (Element) list.item(indexElem); final InstanceEngine instanceConf = new InstanceEngine(); // read every configuration. final String instanceName = element.getAttribute(NODE_INST_NAME); if (StringUtils.isBlank(instanceName)) { throw new STORKSAMLEngineRuntimeException("Error reader instance name."); } instanceConf.setName(instanceName.trim()); final NodeList confNodes = element.getElementsByTagName(NODE_CONF); for (int indexNode = 0; indexNode < confNodes.getLength(); ++indexNode) { final Element configurationNode = (Element) confNodes.item(indexNode); final String configurationName = configurationNode.getAttribute(NODE_CONF_NAME); if (StringUtils.isBlank(configurationName)) { throw new STORKSAMLEngineRuntimeException("Error reader configuration name."); } final ConfigurationEngine confSamlEngine = new ConfigurationEngine(); // Set configuration name. confSamlEngine.setName(configurationName.trim()); // Read every parameter for this configuration. final Map<String, String> parameters = generateParam(configurationNode); // Set parameters confSamlEngine.setParameters(parameters); // Add parameters to the configuration. instanceConf.getConfiguration().add(confSamlEngine); } // Add to the list of configurations. instanceConfs.put(element.getAttribute(NODE_INST_NAME), instanceConf); } } catch (SAXException e) { LOGGER.error("Error: init library parser."); throw new SAMLEngineException(e); } catch (ParserConfigurationException e) { LOGGER.error("Error: parser configuration file xml."); throw new SAMLEngineException(e); } catch (IOException e) { LOGGER.error("Error: read configuration file."); throw new SAMLEngineException(e); } finally { IOUtils.closeQuietly(engineConf); } return instanceConfs; }