List of usage examples for org.w3c.dom Element getAttribute
public String getAttribute(String name);
From source file:com.tascape.qa.th.android.model.UIA.java
public static WindowHierarchy parseHierarchy(InputStream in, UiAutomatorDevice device) throws SAXException, ParserConfigurationException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(in); Element doc = document.getDocumentElement(); NodeList nl = doc.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node node = nl.item(i);//from w w w .ja va 2 s. c o m UIANode uiNode = parseNode(node); if (uiNode != null) { WindowHierarchy hierarchy = new WindowHierarchy(uiNode); hierarchy.setRotation(doc.getAttribute("rotation")); LOG.debug("{}", hierarchy); hierarchy.setUiAutomatorDevice(device); return hierarchy; } } throw new UIAException("Cannot parse view hierarchy"); }
From source file:eu.eidas.configuration.ConfigurationReader.java
/** * Read configuration./* w w w. j a v a 2 s. c o m*/ * * @return the map< string, instance engine> * * @throws SAMLEngineException the EIDASSAML engine runtime * exception */ public static Map<String, InstanceEngine> readConfiguration() throws SAMLEngineException { LOGGER.debug("Init reader: " + ENGINE_CONF_FILE); final Map<String, InstanceEngine> instanceConfs = new HashMap<String, InstanceEngine>(); Document document = null; // Load configuration file final DocumentBuilderFactory factory = EIDASSAMLEngine.newDocumentBuilderFactory(); DocumentBuilder builder; InputStream engineConf = null; try { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); builder = factory.newDocumentBuilder(); 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 EIDASSAMLEngineRuntimeException("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 EIDASSAMLEngineRuntimeException("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.warn("ERROR : init library parser.", e.getMessage()); LOGGER.debug("ERROR : init library parser.", e); throw new SAMLEngineException(e); } catch (ParserConfigurationException e) { LOGGER.warn("ERROR : parser configuration file xml."); LOGGER.debug("ERROR : parser configuration file xml.", e); throw new SAMLEngineException(e); } catch (IOException e) { LOGGER.warn("ERROR : read configuration file.", e.getMessage()); LOGGER.debug("ERROR : read configuration file.", e); throw new SAMLEngineException(e); } finally { IOUtils.closeQuietly(engineConf); } return instanceConfs; }
From source file:eidassaml.starterkit.EidasRequest.java
/** * Returns {@link EidasPersonAttributes} enum from given {@link Element}. * In case enum can not be found null is returned; unknown attributes should be ignored. * /*ww w .j av a 2s . c o m*/ * @param el * @return */ private static EidasPersonAttributes getEidasPersonAttributes(Element el) { EidasPersonAttributes eidasPersonAttributes = null; try { eidasPersonAttributes = EidasNaturalPersonAttributes.GetValueOf(el.getAttribute("Name")); } catch (ErrorCodeException e) { try { eidasPersonAttributes = EidasLegalPersonAttributes.GetValueOf(el.getAttribute("Name")); } catch (ErrorCodeException e1) { LOG.warn("Attribute " + el.getAttribute("Name") + " not an eIDAS attribute. Ignoring."); } } return eidasPersonAttributes; }
From source file:Main.java
/** * Get the value of a node specified by a starting node and a * path string. If the starting node is a Document, use the * document element as the starting point. * A path to an element has the form: elem1/.../elemN * A path to an attribute has the form: elem1/.../elemN@attr * The value of an element node is the sum of all the element's * first generation child text nodes. Note that this is not what you * would get from a mixed element in an XSL program. * @param node the top of the tree to search. * @param path the path from the top of the tree to the desired node. * @return the value of the first node matching the path, or the * empty string if no node exists at the path location or if the * starting node is not an element.//from ww w. ja v a 2 s . c o m */ public static String getValueViaPath(Node node, String path) { if (node instanceof Document) node = ((Document) node).getDocumentElement(); if (!(node instanceof Element)) return ""; path = path.trim(); int kAtsign = path.indexOf("@"); //If the target is an element, get the element's value. if (kAtsign == -1) { Element target = getElementViaPath(node, path); if (target == null) return ""; return getElementValue(target); } //The target is an attribute; first find the element. String subpath = path.substring(0, kAtsign); Element target = getElementViaPath(node, subpath); if (target == null) return null; String name = path.substring(kAtsign + 1); return target.getAttribute(name); }
From source file:it.polimi.diceH2020.plugin.control.FileManager.java
/** * Scans Hadoop model to extract information * //from ww w . j av a 2s. c om * @param fileName * XML file path * @return A map containing the parameters extracted from the model */ public static Map<String, String> parseDOMXmlFile(String fileName) { File src = new File(fileName); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; Map<String, String> res = new HashMap<String, String>(); try { builder = factory.newDocumentBuilder(); Document doc = builder.parse(src); NodeList group = doc.getElementsByTagName("group"); for (int i = 0; i < group.getLength(); i++) { Element e = (Element) group.item(i); if (e.getAttribute("name").equals("Reducer")) { String data = group.item(i).getTextContent().trim(); res.put("rTasks", data.substring(data.indexOf('[') + 1, data.indexOf(']'))); res.put("rDemand", data.substring(data.indexOf('x') + 4, data.indexOf('u') - 1)); } if (e.getAttribute("name").equals("Mapper")) { String data = group.item(i).getTextContent().trim(); res.put("mTasks", data.substring(data.indexOf('[') + 1, data.indexOf(']'))); res.put("mDemand", data.substring(data.indexOf('x') + 4, data.indexOf('u') - 1)); } } } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return res; }
From source file:org.xacml4j.spring.pdp.PolicyDecisionPointDefinitionParser.java
private static BeanDefinitionBuilder parseComponent(Element element) { BeanDefinitionBuilder component = element.getLocalName().equals("PolicyIdReference") ? BeanDefinitionBuilder.rootBeanDefinition(PolicyIDReferenceFactoryBean.class) : BeanDefinitionBuilder.rootBeanDefinition(PolicySetIDReferenceFactoryBean.class); String id = element.getTextContent(); if (StringUtils.hasText(id)) { component.addPropertyValue("id", id); }/* ww w .j a v a2 s .co m*/ String version = element.getAttribute("version"); if (StringUtils.hasText(version)) { component.addPropertyValue("version", version); } String latest = element.getAttribute("latest"); if (StringUtils.hasText(latest)) { component.addPropertyValue("latest", latest); } String earliest = element.getAttribute("earliest"); if (StringUtils.hasText(earliest)) { component.addPropertyValue("earliest", earliest); } return component; }
From source file:com.portfolio.data.utils.DomUtils.java
public static String getRootuuid(Node node) throws Exception { // --------------------------------------------------- String result = null;/*from ww w . jav a2s . c o m*/ NodeList liste = ((Document) node).getElementsByTagName("asmRoot"); if (liste.getLength() != 0) { Element elt = (Element) liste.item(0); result = elt.getAttribute("uuid"); } return result; }
From source file:fll.web.admin.UploadSubjectiveData.java
/** * Save the subjective data in scoreDocument to the database. */// w ww . j a v a2 s .com public static void saveSubjectiveData(final Document scoreDocument, final int currentTournament, final ChallengeDescription challengeDescription, final Connection connection) throws SQLException, IOException, ParseException { // make sure all judges exist in the database first addMissingJudges(connection, currentTournament, scoreDocument); final Element scoresElement = scoreDocument.getDocumentElement(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("first element: " + scoresElement); } for (final Element scoreCategoryNode : new NodelistElementCollectionAdapter( scoresElement.getChildNodes())) { final Element scoreCategoryElement = scoreCategoryNode; // "subjectiveCategory" final String categoryName = scoreCategoryElement.getAttribute("name"); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Saving category: " + categoryName); } ScoreCategory categoryElement = null; for (final ScoreCategory cat : challengeDescription.getSubjectiveCategories()) { if (cat.getName().equals(categoryName)) { categoryElement = cat; } } if (null == categoryElement) { throw new RuntimeException( "Cannot find subjective category description for category in score document category: " + categoryName); } saveCategoryData(currentTournament, connection, scoreCategoryElement, categoryName, categoryElement); } removeNullSubjectiveRows(connection, currentTournament, challengeDescription); final Tournament tournament = Tournament.findTournamentByID(connection, currentTournament); tournament.recordSubjectiveModified(connection); }
From source file:fll.web.admin.UploadSubjectiveData.java
/** * Add any judges to the database that are referenced in the score file that * aren't already in the database./*from w w w. j av a2s . co m*/ */ private static void addMissingJudges(final Connection connection, final int tournamentId, final Document scoreDocument) throws SQLException { PreparedStatement insertJudge = null; try { insertJudge = connection .prepareStatement("INSERT INTO Judges (id, category, Tournament, station) VALUES (?, ?, ?, ?)"); insertJudge.setInt(3, tournamentId); final Collection<JudgeInformation> currentJudges = JudgeInformation.getJudges(connection, tournamentId); final Element scoresElement = scoreDocument.getDocumentElement(); for (final Element scoreCategoryNode : new NodelistElementCollectionAdapter( scoresElement.getChildNodes())) { final Element scoreCategoryElement = scoreCategoryNode; // "subjectiveCategory" final String categoryName = scoreCategoryElement.getAttribute("name"); for (final Element scoreElement : new NodelistElementCollectionAdapter( scoreCategoryElement.getElementsByTagName("score"))) { final String judgeId = scoreElement.getAttribute("judge"); final String station = scoreElement.getAttribute("judging_station"); final JudgeInformation judge = new JudgeInformation(judgeId, categoryName, station); if (!doesJudgeExist(currentJudges, judge)) { // add judge insertJudge.setString(1, judge.getId()); insertJudge.setString(2, judge.getCategory()); insertJudge.setString(4, judge.getGroup()); insertJudge.executeUpdate(); currentJudges.add(judge); } } // foreach score } // foreach category } finally { SQLFunctions.close(insertJudge); } }
From source file:cz.incad.kramerius.rest.api.k5.client.search.SearchResource.java
public static Element findSolrElement(Element docE, final String name) { Element found = XMLUtils.findElement(docE, new XMLUtils.ElementsFilter() { @Override//from w w w.j av a 2 s . c o m public boolean acceptElement(Element element) { return (element.hasAttribute("name") && element.getAttribute("name").equals(name)); } }); return found; }