List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:eu.eidas.auth.engine.configuration.dom.DOMConfigurationParser.java
@Nonnull private static ConfigurationEntry parseConfigurationEntry(@Nonnull String configurationFileName, @Nonnull String instanceName, @Nonnull Element configurationTag) throws SamlEngineConfigurationException { String configurationName = configurationTag.getAttribute(InstanceTag.ConfigurationTag.Attribute.NAME); if (StringUtils.isBlank(configurationName)) { String message = "SAML engine configuration file \"" + configurationFileName + "\" contains a blank configuration name for instance name \"" + instanceName + "\""; LOG.error(message);// w w w . j av a 2 s . co m throw new SamlEngineConfigurationException(message); } // Set configuration name. String name = configurationName.trim(); // Read every parameter for this configuration. ImmutableMap<String, String> parameters = parseParameters(configurationFileName, instanceName, configurationName, configurationTag); return new ConfigurationEntry(name, parameters); }
From source file:Main.java
public static ArrayList<String> getNodeListAttValAsStringCols(String Xpath, Node node, String[] attrNames, String sep) throws Exception { ArrayList<String> retV = new ArrayList<String>(); if (sep == null) { sep = " "; }//from w w w. jav a2 s. c om int aNamesL = attrNames.length; if (aNamesL > 0) { NodeList nl = getNodesListXpathNode(Xpath, node); int l = nl.getLength(); Element e = null; String val = ""; for (int i = 0; i < l; i++) { e = (Element) nl.item(i); if (e.getNodeType() == Node.ELEMENT_NODE) { StringBuilder sb = new StringBuilder(); for (int y = 0; y < aNamesL; y++) { sb.append(e.getAttribute(attrNames[y])); if (y < aNamesL - 1) { sb.append(sep); } } val = sb.toString(); if (val != null && val.length() > 0) { //log.info("getNodeListAttValAsStringCol val = "+val +" attrNames = "+attrNames); /*try { log.info(convertToStringLeaveCDATA(e)); }catch(Exception E) { E.printStackTrace(); }*/ retV.add(val); } } } } return retV; }
From source file:Main.java
public static ArrayList<String> getNodeListAttValAsStringCols(final String xPath, final Node node, final String[] attrNames, final String sep) throws Exception { ArrayList<String> retV = new ArrayList<String>(); String locSep = " "; if (sep != null) { locSep = sep;//from ww w .j av a2s. c o m } int aNamesL = attrNames.length; if (aNamesL > 0) { NodeList nl = getNodesListXpathNode(xPath, node); int l = nl.getLength(); Element e = null; String val = ""; for (int i = 0; i < l; i++) { e = (Element) nl.item(i); if (e.getNodeType() == Node.ELEMENT_NODE) { StringBuilder sb = new StringBuilder(); for (int y = 0; y < aNamesL; y++) { sb.append(e.getAttribute(attrNames[y])); if (y < aNamesL - 1) { sb.append(locSep); } } val = sb.toString(); if (val != null && val.length() > 0) { retV.add(val); } } } } return retV; }
From source file:com.google.enterprise.adaptor.experimental.Sim.java
/** Find all record urls in Adaptor created XML metadata-and-url feed file. */ static Set<URL> extractUrls(String xml) throws SAXException, ParserConfigurationException, BadFeed { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); /* to avoid blowing up on doctype line: * http://stackoverflow.com/questions/155101/make-documentbuilder-parse-ignore-dtd-references */ dbf.setValidating(false);//ww w . j a va 2s. c o m dbf.setFeature("http://xml.org/sax/features/namespaces", false); dbf.setFeature("http://xml.org/sax/features/validation", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); DocumentBuilder db = dbf.newDocumentBuilder(); InputStream xmlStream = new ByteArrayInputStream(xml.getBytes(UTF8)); Document doc; try { doc = db.parse(xmlStream); } catch (IOException ie) { throw new BadFeed(ie.getMessage()); } doc.getDocumentElement().normalize(); NodeList nodes = doc.getElementsByTagName("record"); Set<URL> tmpUrls = new HashSet<URL>(); for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); String url = element.getAttribute("url"); if (null == url || url.trim().isEmpty()) { throw new BadFeed("record without url attribute"); } else { try { tmpUrls.add(new URL(url)); } catch (MalformedURLException male) { throw new BadFeed("record with bad url attribute: " + url); } } log.info("accepting url: " + url); } return tmpUrls; }
From source file:com.codebutler.farebot.card.felica.FelicaCard.java
public static FelicaCard fromXml(byte[] tagId, Date scannedAt, Element element) { Element systemsElement = (Element) element.getElementsByTagName("systems").item(0); NodeList systemElements = systemsElement.getElementsByTagName("system"); FeliCaLib.IDm idm = new FeliCaLib.IDm( Base64.decode(element.getElementsByTagName("idm").item(0).getTextContent(), Base64.DEFAULT)); FeliCaLib.PMm pmm = new FeliCaLib.PMm( Base64.decode(element.getElementsByTagName("pmm").item(0).getTextContent(), Base64.DEFAULT)); FelicaSystem[] systems = new FelicaSystem[systemElements.getLength()]; for (int x = 0; x < systemElements.getLength(); x++) { Element systemElement = (Element) systemElements.item(x); int systemCode = Integer.parseInt(systemElement.getAttribute("code")); Element servicesElement = (Element) systemElement.getElementsByTagName("services").item(0); NodeList serviceElements = servicesElement.getElementsByTagName("service"); FelicaService[] services = new FelicaService[serviceElements.getLength()]; for (int y = 0; y < serviceElements.getLength(); y++) { Element serviceElement = (Element) serviceElements.item(y); int serviceCode = Integer.parseInt(serviceElement.getAttribute("code")); Element blocksElement = (Element) serviceElement.getElementsByTagName("blocks").item(0); NodeList blockElements = blocksElement.getElementsByTagName("block"); FelicaBlock[] blocks = new FelicaBlock[blockElements.getLength()]; for (int z = 0; z < blockElements.getLength(); z++) { Element blockElement = (Element) blockElements.item(z); byte address = Byte.parseByte(blockElement.getAttribute("address")); byte[] data = Base64.decode(blockElement.getTextContent(), Base64.DEFAULT); blocks[z] = new FelicaBlock(address, data); }/*from w w w .j av a 2s. c o m*/ services[y] = new FelicaService(serviceCode, blocks); } systems[x] = new FelicaSystem(systemCode, services); } return new FelicaCard(tagId, scannedAt, idm, pmm, systems); }
From source file:de.codesourcery.jasm16.emulator.EmulationOptions.java
private static boolean isSet(Element element, String attribute) { final String value = element.getAttribute(attribute); return "true".equals(value); }
From source file:DOMEdit.java
public static void dupAttributes(Document doc) { Element root = doc.getDocumentElement(); Element personOne = (Element) root.getFirstChild(); Attr deptAttr = personOne.getAttributeNode("dept"); personOne.removeAttributeNode(deptAttr); String deptString = deptAttr.getValue(); personOne.setAttribute("dept", deptString + " updated"); String mailString = personOne.getAttribute("mail"); personOne.setAttribute("mail", mailString + " updated"); String titleString = personOne.getAttribute("title"); //personOne.removeAttribute("title"); personOne.setAttribute("title", titleString + " updated"); }/*from www.j av a2s . co m*/
From source file:Main.java
public static String argumentTagToCmd(Element jobElement) { // NodeList nl = jobElement.getChildNodes(); // for(int i=0;i<nl.getLength();i++) // {/*from w ww .j av a 2 s.c o m*/ // System.out.println(nl.item(i).getTextContent()); // } // System.exit(1); // Node n = jobElement.getElementsByTagName("argument").item(0); String taskName = jobElement.getAttribute("name"); // String nodeString = nodeToString(n); // nodeString = nodeString.replace("<"+n.getNodeName()+">", ""); // nodeString = nodeString.replace("</"+n.getNodeName()+">", ""); // nodeString = nodeString.trim(); // String[] lines = nodeString.split("\n"); StringBuilder cmd = new StringBuilder(taskName).append(";"); NodeList argList = jobElement.getElementsByTagName("argument").item(0).getChildNodes(); for (int i = 0; i < argList.getLength(); i++) { Node c = argList.item(i); String cStr; if (c.getNodeName().equals("file")) { Element ec = (Element) c; cStr = (ec.getAttribute("name")).trim(); if (!cStr.isEmpty()) { cmd.append(cStr).append(";"); } } else { cStr = (c.getTextContent().trim()); String[] cStrs = cStr.split("\\s+"); for (String cs : cStrs) { cs = cs.trim(); if (!cs.isEmpty()) { cmd.append(cs).append(";"); } } } } cmd.replace(cmd.length() - 1, cmd.length(), ""); return cmd.toString(); }
From source file:eu.eidas.auth.engine.configuration.dom.DOMConfigurationParser.java
@Nonnull private static InstanceEntry parseInstanceEntry(@Nonnull String configurationFileName, @Nonnull Element instanceTag) throws SamlEngineConfigurationException { // read every configuration. String instanceName = instanceTag.getAttribute(InstanceTag.Attribute.NAME); if (StringUtils.isBlank(instanceName)) { String message = "SAML engine configuration file \"" + configurationFileName + "\" contains a blank instance name"; LOG.error(message);// w w w . j a v a2 s . c o m throw new SamlEngineConfigurationException(message); } instanceName = instanceName.trim(); NodeList configurationTags = instanceTag.getElementsByTagName(InstanceTag.ConfigurationTag.TAG_NAME); Map<String, ConfigurationEntry> configurationEntries = new LinkedHashMap<>(); for (int i = 0, n = configurationTags.getLength(); i < n; i++) { Element configurationTag = (Element) configurationTags.item(i); ConfigurationEntry configurationEntry = parseConfigurationEntry(configurationFileName, instanceName, configurationTag); ConfigurationEntry previous = configurationEntries.put(configurationEntry.getName(), configurationEntry); if (null != previous) { String message = "Duplicate configuration entry names \"" + configurationEntry.getName() + "\" in SAML engine configuration file \"" + configurationFileName + "\""; LOG.error(message); throw new SamlEngineConfigurationException(message); } } return new InstanceEntry(instanceName, ImmutableMap.copyOf(configurationEntries)); }
From source file:Main.java
/** * Returns an element parent node with "name" attribute based on a complex * key filter (parent.child.child)//from w w w .java 2 s .c o m * @param xsdDoc * @param xsdKey * @return */ protected static Element getXsdParentComplexKey(Document xsdDoc, String xsdKey) { Element tmpRes = null; Element element = null; String[] splitStr = xsdKey.split("[.]"); String topParent = splitStr[0]; String Parent = splitStr[1]; String Node = splitStr[2]; try { NodeList allNodes = xsdDoc.getElementsByTagName("*"); for (int i = 0; i < allNodes.getLength(); i++) { element = (Element) allNodes.item(i); if (element.getAttribute("name").equals(Node)) { element = (Element) element.getParentNode(); while (!((Element) element).hasAttribute("name")) { element = (Element) element.getParentNode(); } if (element.getAttribute("name").equals(Parent)) { Element pElement = (Element) element.getParentNode(); while (!((Element) pElement).hasAttribute("name")) { pElement = (Element) pElement.getParentNode(); } if (pElement.getAttribute("name").equals(topParent)) { tmpRes = element; } } } } return tmpRes; } catch (Exception e) { e.printStackTrace(); return null; } }