List of usage examples for org.w3c.dom Document getElementsByTagName
public NodeList getElementsByTagName(String tagname);
NodeList
of all the Elements
in document order with a given tag name and are contained in the document. From source file:com.swetha.easypark.GetDirections.java
public String getDurationText(Document doc) { NodeList nl1 = doc.getElementsByTagName("duration"); Node node1 = nl1.item(nl1.getLength() - 1); NodeList nl2 = node1.getChildNodes(); Node node2 = nl2.item(getNodeIndex(nl2, "text")); Log.i("DurationText", node2.getTextContent()); return node2.getTextContent(); }
From source file:com.swetha.easypark.GetDirections.java
public String getDistanceText(Document doc) { NodeList nl1 = doc.getElementsByTagName("distance"); Node node1 = nl1.item(nl1.getLength() - 1); NodeList nl2 = node1.getChildNodes(); Node node2 = nl2.item(getNodeIndex(nl2, "text")); Log.i("DistanceText", node2.getTextContent()); return node2.getTextContent(); }
From source file:de.erdesignerng.model.serializer.xml10.XMLSubjectAreaSerializer.java
@Override public void deserialize(Model aModel, Document aDocument) { NodeList theElements = aDocument.getElementsByTagName(SUBJECTAREA); for (int i = 0; i < theElements.getLength(); i++) { Element theElement = (Element) theElements.item(i); SubjectArea theSubjectArea = new SubjectArea(); deserializeProperties(theElement, theSubjectArea); theSubjectArea.setColor(new Color(Integer.parseInt(theElement.getAttribute(COLOR)))); NodeList theTables = theElement.getElementsByTagName(ITEM); for (int j = 0; j < theTables.getLength(); j++) { Element theItemElement = (Element) theTables.item(j); String theTableId = theItemElement.getAttribute(TABLEREFID); String theCommentId = theItemElement.getAttribute(COMMENTREFID); if (!StringUtils.isEmpty(theTableId)) { Table theTable = aModel.getTables().findBySystemId(theTableId); if (theTable == null) { throw new IllegalArgumentException("Cannot find table with id " + theTableId); }/*w w w . ja v a 2 s . c om*/ theSubjectArea.getTables().add(theTable); } if (!StringUtils.isEmpty(theCommentId)) { Comment theComment = aModel.getComments().findBySystemId(theCommentId); if (theComment == null) { throw new IllegalArgumentException("Cannot find comment with id " + theCommentId); } theSubjectArea.getComments().add(theComment); } } aModel.getSubjectAreas().add(theSubjectArea); } }
From source file:eionet.meta.service.XmlConvServiceImpl.java
@Override public SchemaConversionsData getSchemaConversionsData(String schemaUrl) throws ServiceException { SchemaConversionsData result = new SchemaConversionsData(); InputStream inputStream = null; try {/* ww w. ja v a 2s . co m*/ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); // Conversions String conversionsUrl = Props.getRequiredProperty(PropsIF.XML_CONV_URL) + "/api/listConversions?schema=" + schemaUrl; URL url = new URL(conversionsUrl); inputStream = url.openStream(); Document doc = docBuilder.parse(inputStream); NodeList nodeList = doc.getElementsByTagName("conversion"); result.setNumberOfConversions(nodeList.getLength()); // QA Scrpits String scriptsUrl = Props.getRequiredProperty(PropsIF.XML_CONV_URL) + "/RpcRouter"; String scriptsService = "XQueryService"; ServiceClientIF client = ServiceClients.getServiceClient(scriptsService, scriptsUrl); @SuppressWarnings("unchecked") Vector<String> scriptsResult = (Vector<String>) client.getValue("listQAScripts", new Vector<String>(Collections.singletonList(schemaUrl))); result.setNumberOfQAScripts(scriptsResult.size()); // XML Conv schema page url result.setXmlConvUrl(Props.getRequiredProperty(PropsIF.XML_CONV_URL) + "/do/viewSchemaForm"); return result; } catch (Exception e) { throw new ServiceException("Failed to get scripts and conversions info from XmlConv: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:fr.aliasource.webmail.server.proxy.client.http.filters.ListFiltersMethod.java
public List<FilterDefinition> listFilters() { Map<String, String> params = new HashMap<String, String>(); params.put("token", token); Document doc = execute(params); if (logger.isDebugEnabled()) { DOMUtils.logDom(doc);//from w w w.ja v a 2 s . c om } NodeList nl = doc.getElementsByTagName("filter-definition"); List<FilterDefinition> ret = new ArrayList<FilterDefinition>(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { Element e = (Element) nl.item(i); ret.add(parseDefinition(e)); } return ret; }
From source file:org.openengsb.openengsbplugin.tools.OpenEngSBVersionResolver.java
public String resolveVersion(String content) throws NoVersionFoundException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true);/* w w w .j a v a2 s . c o m*/ try { DocumentBuilder builder = factory.newDocumentBuilder(); File tmpFile = createTmpFile(content); Document parse = builder.parse(tmpFile.getAbsolutePath()); NodeList latestNode = parse.getElementsByTagName("latest"); if (latestNode == null || latestNode.getLength() < 1) { throw new NoVersionFoundException("Could not resolve latest version"); } return latestNode.item(0).getFirstChild().getNodeValue(); } catch (ParserConfigurationException e) { throw new NoVersionFoundException("Could not retrieve latest version", e); } catch (SAXException e) { throw new NoVersionFoundException("Could not retrieve latest version", e); } catch (IOException e) { throw new NoVersionFoundException("IOException, tmp folder must be writable", e); } }
From source file:com.openkm.util.FormUtils.java
/** * Parse PropertyGroups.xml definitions//from w w w . j av a2 s . c o m * * @param pgDefFile Path to file where is the Property Groups definition. * @return A Map with all the forms and its form elements. */ public static synchronized Map<PropertyGroup, List<FormElement>> parsePropertyGroupsForms(String pgDefFile) throws IOException, ParseException { log.debug("parsePropertyGroupsForms({})", pgDefFile); if (pGroups == null) { long begin = System.currentTimeMillis(); pGroups = new HashMap<PropertyGroup, List<FormElement>>(); FileInputStream fis = null; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); dbf.setValidating(true); ErrorHandler handler = new ErrorHandler(); // EntityResolver resolver = new LocalResolver(Config.DTD_BASE); DocumentBuilder db = dbf.newDocumentBuilder(); db.setErrorHandler(handler); db.setEntityResolver(resolver); fis = new FileInputStream(pgDefFile); if (fis != null) { Document doc = db.parse(fis); doc.getDocumentElement().normalize(); NodeList nlForm = doc.getElementsByTagName("property-group"); for (int i = 0; i < nlForm.getLength(); i++) { Node nForm = nlForm.item(i); if (nForm.getNodeType() == Node.ELEMENT_NODE) { PropertyGroup pg = new PropertyGroup(); Node item = nForm.getAttributes().getNamedItem("label"); if (item != null) pg.setLabel(item.getNodeValue()); item = nForm.getAttributes().getNamedItem("name"); if (item != null) pg.setName(item.getNodeValue()); item = nForm.getAttributes().getNamedItem("visible"); if (item != null) pg.setVisible(Boolean.valueOf(item.getNodeValue())); item = nForm.getAttributes().getNamedItem("readonly"); if (item != null) pg.setReadonly(Boolean.valueOf(item.getNodeValue())); NodeList nlField = nForm.getChildNodes(); List<FormElement> fe = parseField(nlField); pGroups.put(pg, fe); } } } } catch (ParserConfigurationException e) { throw new ParseException(e.getMessage()); } catch (SAXException e) { throw new ParseException(e.getMessage()); } catch (IOException e) { throw e; } finally { IOUtils.closeQuietly(fis); } log.trace("parsePropertyGroupsForms.Time: {}", System.currentTimeMillis() - begin); } log.debug("parsePropertyGroupsForms: {}", pGroups); return clonedPropertyGroups(); }
From source file:de.erdesignerng.model.serializer.xml20.XMLSubjectAreaSerializer.java
@Override public void deserialize(Model aModel, Document aDocument) { NodeList theElements = aDocument.getElementsByTagName(SUBJECTAREA); for (int i = 0; i < theElements.getLength(); i++) { Element theElement = (Element) theElements.item(i); SubjectArea theSubjectArea = new SubjectArea(); deserializeProperties(theElement, theSubjectArea); theSubjectArea.setColor(new Color(Integer.parseInt(theElement.getAttribute(COLOR)))); if (theElement.hasAttribute(VISIBLE)) { theSubjectArea.setVisible(TRUE.equals(theElement.getAttribute(VISIBLE))); }/* w w w .java 2 s . c om*/ NodeList theTables = theElement.getElementsByTagName(ITEM); for (int j = 0; j < theTables.getLength(); j++) { Element theItemElement = (Element) theTables.item(j); String theTableId = theItemElement.getAttribute(TABLEREFID); String theViewId = theItemElement.getAttribute(VIEWREFID); String theCommentId = theItemElement.getAttribute(COMMENTREFID); if (!StringUtils.isEmpty(theTableId)) { Table theTable = aModel.getTables().findBySystemId(theTableId); if (theTable == null) { throw new IllegalArgumentException("Cannot find table with id " + theTableId); } theSubjectArea.getTables().add(theTable); } if (!StringUtils.isEmpty(theViewId)) { View theView = aModel.getViews().findBySystemId(theViewId); if (theView == null) { throw new IllegalArgumentException("Cannot find view with id " + theTableId); } theSubjectArea.getViews().add(theView); } if (!StringUtils.isEmpty(theCommentId)) { Comment theComment = aModel.getComments().findBySystemId(theCommentId); if (theComment == null) { throw new IllegalArgumentException("Cannot find comment with id " + theCommentId); } theSubjectArea.getComments().add(theComment); } } aModel.getSubjectAreas().add(theSubjectArea); } }
From source file:com.amazon.pay.impl.PayLogUtil.java
/** * * @param data - data to be sanitized.//from w w w . ja v a2s . c o m * @param removedata - List of strings to be removed from the data object. * @return - an XML not containing 'removedata' lists of strings. * * @throws TransformerFactoryConfigurationError - Thrown when a problem with configuration with the Transformer Factories exists. This error will typically be thrown when the class of a transformation factory specified in the system properties cannot be found or instantiated. */ public String getSanitizedData(String data, List<String> removedata) throws AmazonClientException { try { DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(data)); Document doc = db.parse(is); NodeList list = doc.getElementsByTagName("*"); for (int i = 0; i < list.getLength(); i++) { //Get Node Node node = (Node) list.item(i); for (Iterator<String> j = removedata.iterator(); j.hasNext();) { String item = j.next(); if (node.getNodeName().equalsIgnoreCase(item)) { node.setTextContent("*** Removed ***"); } } } StringWriter sw = new StringWriter(); Transformer serializer = TransformerFactory.newInstance().newTransformer(); serializer.transform(new DOMSource(list.item(0)), new StreamResult(sw)); String result = sw.toString(); return result; } catch (ParserConfigurationException e) { throw new AmazonClientException("Encountered UnsupportedEncodingException:", e); } catch (SAXException e) { throw new AmazonClientException("Encountered SAXException:", e); } catch (IOException e) { throw new AmazonClientException("Encountered IOException:", e); } catch (TransformerConfigurationException e) { throw new AmazonClientException("Encountered a Transformer Configuration Exception:", e); } catch (TransformerException e) { throw new AmazonClientException("Encountered a Transformer Exception:", e); } }
From source file:de.erdesignerng.model.serializer.xml50.XMLSubjectAreaSerializer.java
@Override public void deserialize(Model aModel, Document aDocument) { NodeList theElements = aDocument.getElementsByTagName(SUBJECTAREA); for (int i = 0; i < theElements.getLength(); i++) { Element theElement = (Element) theElements.item(i); SubjectArea theSubjectArea = new SubjectArea(); deserializeProperties(theElement, theSubjectArea); theSubjectArea.setColor(new Color(Integer.parseInt(theElement.getAttribute(COLOR)))); if (theElement.hasAttribute(VISIBLE)) { theSubjectArea.setVisible(TRUE.equals(theElement.getAttribute(VISIBLE))); }/*from www .j av a 2 s .c o m*/ if (theElement.hasAttribute(EXPANDED)) { theSubjectArea.setExpanded(TRUE.equals(theElement.getAttribute(EXPANDED))); } NodeList theTables = theElement.getElementsByTagName(ITEM); for (int j = 0; j < theTables.getLength(); j++) { Element theItemElement = (Element) theTables.item(j); String theTableId = theItemElement.getAttribute(TABLEREFID); String theViewId = theItemElement.getAttribute(VIEWREFID); String theCommentId = theItemElement.getAttribute(COMMENTREFID); if (!StringUtils.isEmpty(theTableId)) { Table theTable = aModel.getTables().findBySystemId(theTableId); if (theTable == null) { throw new IllegalArgumentException("Cannot find table with id " + theTableId); } theSubjectArea.getTables().add(theTable); } if (!StringUtils.isEmpty(theViewId)) { View theView = aModel.getViews().findBySystemId(theViewId); if (theView == null) { throw new IllegalArgumentException("Cannot find view with id " + theViewId); } theSubjectArea.getViews().add(theView); } if (!StringUtils.isEmpty(theCommentId)) { Comment theComment = aModel.getComments().findBySystemId(theCommentId); if (theComment == null) { throw new IllegalArgumentException("Cannot find comment with id " + theCommentId); } theSubjectArea.getComments().add(theComment); } } aModel.getSubjectAreas().add(theSubjectArea); } }