List of usage examples for org.w3c.dom Node getTextContent
public String getTextContent() throws DOMException;
From source file:edu.cornell.mannlib.vitro.utilities.containerneutral.CheckContainerNeutrality.java
private void checkFilterClasses() { for (Node n : findNodes("//j2ee:filter-class")) { String text = n.getTextContent(); String problem = confirmClassNameIsValid(text, Filter.class); if (problem != null) { messages.add("<filter-class>" + text + "</filter-class> is not valid: " + problem); }/*w w w . j av a2 s .co m*/ } }
From source file:Importers.ImportReportCompiler.java
private Vulnerability getVuln(Node vuln_node) { Base64 b64 = new Base64(); Vulnerability vuln = new Vulnerability(); String custom = "false"; String category = ""; String cvss_string = ""; try {//from ww w . j a va 2 s. c o m custom = vuln_node.getAttributes().getNamedItem("custom-risk").getTextContent(); } catch (NullPointerException e) { ; } try { category = vuln_node.getAttributes().getNamedItem("category").getTextContent(); } catch (NullPointerException e) { ; } try { cvss_string = vuln_node.getAttributes().getNamedItem("cvss").getTextContent(); } catch (NullPointerException e) { ; } // TODO read identifiers //vuln.setIdentifier(vuln_node.getAttributes().getNamedItem("id").getTextContent()); vuln.setIs_custom_risk(custom.equalsIgnoreCase("true")); vuln.setRisk_category(category); vuln.setCvss_vector_string(cvss_string); NodeList children = vuln_node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String name = node.getNodeName(); String value = node.getTextContent(); //System.out.println(name + ":" + value); if (name.equalsIgnoreCase("title")) { vuln.setTitle(new String(b64.decode(value))); } else if (name.equalsIgnoreCase("identifiers")) { NodeList identifiers = node.getChildNodes(); for (int ii = 0; ii < identifiers.getLength(); ii++) { Node idNode = identifiers.item(ii); if (idNode.getNodeType() == Node.ELEMENT_NODE) { String hash = idNode.getAttributes().getNamedItem("hash").getTextContent(); String import_tool = idNode.getAttributes().getNamedItem("import_tool") .getTextContent(); vuln.setImport_tool(import_tool); // this hash is a legacy broken from the before time if (hash.equalsIgnoreCase("24d459a81449d721c8f9a86c2913034")) { vuln.setIdentifier(); // this replaces the hash with the current MD5(vuln.getTitle()); } else { vuln.setIdentifierFromSaveFile(hash, import_tool); // this trusts the source tool and hash. } } } } else if (name.equalsIgnoreCase("description")) { vuln.setDescription(new String(b64.decode(value))); } else if (name.equalsIgnoreCase("recommendation")) { vuln.setRecommendation(new String(b64.decode(value))); } else if (name.equalsIgnoreCase("affected-hosts")) { Vector affected_hosts = getHosts(node); vuln.addAffectedHosts(affected_hosts); } else if (name.equalsIgnoreCase("references")) { NodeList references = node.getChildNodes(); for (int n = 0; n < references.getLength(); n++) { Node refNode = references.item(n); if (refNode.getNodeType() == Node.ELEMENT_NODE) { String description = refNode.getAttributes().getNamedItem("description") .getTextContent(); String url = refNode.getTextContent(); Reference ref = new Reference(description, url); vuln.addReference(ref); } } } } } // for original users with saved personal vulns saved without import tools if (vuln.getImport_tool() == "NULL") { vuln.setImport_tool("ReportCompiler"); vuln.setIdentifier(); System.out.println(vuln.getTitle() + ": hash: " + vuln.getIDsAsString()); } return vuln; }
From source file:edu.cornell.mannlib.vitro.utilities.containerneutral.CheckContainerNeutrality.java
private void checkServletClasses() { for (Node n : findNodes("//j2ee:servlet-class")) { String text = n.getTextContent(); String problem = confirmClassNameIsValid(text, HttpServlet.class); if (problem != null) { messages.add("<servlet-class>" + text + "</servlet-class> is not valid: " + problem); }/*from w w w .j a v a 2 s . c o m*/ } }
From source file:ar.com.zauber.commons.gis.street.impl.GMapsStreetDao.java
/** * * @param node en este nodo esta el placemark * @return un {@link Result} con los datos. *//*from ww w . ja v a 2s.c om*/ private Result getPlace(final Node node) throws NumberFormatException { Validate.notNull(node); Validate.isTrue(node.getNodeName().equals("Placemark")); Result res = null; Node details = find("AddressDetails", node); Node coordenadas = find("coordinates", node); // obtengo coordenadas y si es preciso if (coordenadas != null && details != null && details.hasAttributes()) { Node nprecision = details.getAttributes().getNamedItem("Accuracy"); if (nprecision != null) { String precision = nprecision.getTextContent(); boolean preciso = Integer.parseInt(precision) >= accu; String coord = coordenadas.getTextContent(); final String[] lonLat = coord.split(","); if (lonLat.length > 2 && preciso) { final Double lon = Double.valueOf(lonLat[0]); final Double lat = Double.valueOf(lonLat[1]); // obtengo nombre entero de la direccion String name = find("address", node).getTextContent(); //obtengo pais Node country = find("CountryNameCode", details); String countryCode = (country == null) ? null : country.getTextContent(); // obtengo ciudad Node place = find("LocalityName", details); Node ciudad = (place == null) ? find("AdministrativeAreaName", details) : place; String city = (ciudad == null) ? null : ciudad.getTextContent(); //armo el resultado if (lon != null && lat != null && name != null && city != null && countryCode != null) { res = new StreetResult(name, geometryFactory.createPoint(new Coordinate(lon, lat)), city, countryCode); } } } } return res; }
From source file:edu.cornell.mannlib.vitro.utilities.containerneutral.CheckContainerNeutrality.java
private void checkListenerClasses() { for (Node n : findNodes("//j2ee:listener-class")) { String text = n.getTextContent(); String problem = confirmClassNameIsValid(text, ServletContextListener.class); if (problem != null) { messages.add("<listener-class>" + text + "</listener-class> is not valid: " + problem); }//from w ww. j a va 2s. co m } }
From source file:org.openmrs.module.sync.web.controller.StateController.java
@Override protected Map<String, Object> referenceData(HttpServletRequest request, Object obj, Errors errors) throws Exception { Map<String, Object> ret = new HashMap<String, Object>(); Map<String, String> recordTypes = new HashMap<String, String>(); Map<Object, String> itemTypes = new HashMap<Object, String>(); Map<Object, String> itemGuids = new HashMap<Object, String>(); Map<String, String> recordText = new HashMap<String, String>(); Map<String, String> recordChangeType = new HashMap<String, String>(); // Sync statistics int totalRecords = 0; int synchronizedRecords = 0; int newRecords = 0; int pendingRecords = 0; int sentRecords = 0; int sendFailedRecords = 0; int ingestFailedRecords = 0; int retriedRecords = 0; int failedStoppedRecords = 0; int notSyncRecords = 0; int rejectedRecords = 0; int unknownstateRecords = 0; List<SyncRecord> recordList = (ArrayList<SyncRecord>) obj; totalRecords = recordList.size();//w ww .ja v a2 s. c o m // warning: right now we are assuming there is only 1 item per record for (SyncRecord record : recordList) { SyncRecordState state = record.getState(); if (state.isFinal()) synchronizedRecords++; else if (state == SyncRecordState.NEW) newRecords++; else if (state == SyncRecordState.PENDING_SEND) pendingRecords++; else if (state == SyncRecordState.SENT) sentRecords++; else if (state == SyncRecordState.SEND_FAILED) sendFailedRecords++; else if (state == SyncRecordState.FAILED) ingestFailedRecords++; else if (state == SyncRecordState.SENT_AGAIN) retriedRecords++; else if (state == SyncRecordState.FAILED_AND_STOPPED) failedStoppedRecords++; else if (state == SyncRecordState.NOT_SUPPOSED_TO_SYNC) notSyncRecords++; else if (state == SyncRecordState.REJECTED) rejectedRecords++; else unknownstateRecords++; String mainClassName = null; String mainGuid = null; String mainState = null; for (SyncItem item : record.getItems()) { String syncItem = item.getContent(); mainState = item.getState().toString(); Record xml = Record.create(syncItem); Item root = xml.getRootItem(); String className = root.getNode().getNodeName().substring("org.openmrs.".length()); itemTypes.put(item.getKey().getKeyValue(), className); if (mainClassName == null) mainClassName = className; //String itemInfoKey = itemInfoKeys.get(className); // now we have to go through the item child nodes to find the real GUID that we want NodeList nodes = root.getNode().getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node n = nodes.item(i); String propName = n.getNodeName(); if (propName.equalsIgnoreCase("guid")) { String guid = n.getTextContent(); itemGuids.put(item.getKey().getKeyValue(), guid); if (mainGuid == null) mainGuid = guid; } } } // persistent sets should show something other than their mainClassName (persistedSet) if (mainClassName.indexOf("Persistent") >= 0) mainClassName = record.getContainedClasses(); recordTypes.put(record.getUuid(), mainClassName); recordChangeType.put(record.getUuid(), mainState); // refactored - CA 21 Jan 2008 String displayName = ""; try { displayName = SyncUtil.displayName(mainClassName, mainGuid); } catch (Exception e) { // some methods like Concept.getName() throw Exception s all the time... displayName = ""; } if (displayName != null) if (displayName.length() > 0) recordText.put(record.getUuid(), displayName); } // reference statistics ret.put("totalRecords", new Integer(totalRecords)); ret.put("synchronizedRecords", new Integer(synchronizedRecords)); ret.put("newRecords", new Integer(newRecords)); ret.put("pendingRecords", new Integer(pendingRecords)); ret.put("sentRecords", new Integer(sentRecords)); ret.put("sendFailedRecords", new Integer(sendFailedRecords)); ret.put("ingestFailedRecords", new Integer(ingestFailedRecords)); ret.put("retriedRecords", new Integer(retriedRecords)); ret.put("failedStoppedRecords", new Integer(failedStoppedRecords)); ret.put("notSyncRecords", new Integer(notSyncRecords)); ret.put("rejectedRecords", new Integer(rejectedRecords)); ret.put("unknownstateRecords", new Integer(unknownstateRecords)); ret.put("recordTypes", recordTypes); ret.put("itemTypes", itemTypes); ret.put("itemGuids", itemGuids); ret.put("recordText", recordText); ret.put("recordChangeType", recordChangeType); ret.put("parent", Context.getService(SyncService.class).getParentServer()); ret.put("servers", Context.getService(SyncService.class).getRemoteServers()); ret.put("syncDateDisplayFormat", TimestampNormalizer.DATETIME_DISPLAY_FORMAT); return ret; }
From source file:com.cyc.corpus.nlmpaper.AIMedOpenAccessPaper.java
public AIMedArticle(String xmlFileContents) { taggedProteins = new HashSet<>(); String[] lines = xmlFileContents.split("\n"); try {//from w w w . ja v a 2 s.c om DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); for (String line : lines) { InputSource is = new InputSource(new StringReader(line)); Document document = docBuilder.parse(is); NodeList nodeList = document.getElementsByTagName("*"); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { final String nodeName = node.getNodeName(); final String textContent = node.getTextContent(); if (nodeName.equalsIgnoreCase("ArticleTitle")) { titleSectionText = textContent; } else if (nodeName.equalsIgnoreCase("AbstractText")) { abstractSectionText = textContent; } else if (nodeName.equalsIgnoreCase("prot")) { taggedProteins.add(textContent); } } } } } catch (DOMException | IOException | ParserConfigurationException | SAXException ex) { Logger.getLogger(AIMedOpenAccessPaper.class.getName()).log(Level.SEVERE, null, ex); //throw new RuntimeException(ex); } }
From source file:eu.transkribus.languageresources.extractor.pagexml.PAGEXMLExtractor.java
public String getTextFromNode(Node unicodeNode) { String textContent = unicodeNode.getTextContent(); Node textLineNode = unicodeNode.getParentNode().getParentNode(); Node customNode = textLineNode.getAttributes().getNamedItem("custom"); String customTagValue = null; if (customNode != null) { customTagValue = textLineNode.getAttributes().getNamedItem("custom").getTextContent(); }//from w w w . j a va 2 s . c om return getTextFromNode(textContent, customTagValue); }
From source file:biz.taoconsulting.dominodav.methods.PROPPATCH.java
/** * (non-Javadoc)//from w w w. j a va 2s.co m * * @see biz.taoconsulting.dominodav.methods.AbstractDAVMethod#action() */ @SuppressWarnings("deprecation") protected void action() throws Exception { // TODO Implement! IDAVRepository rep = this.getRepository(); String curURI = (String) this.getHeaderValues().get("uri"); IDAVResource resource = null; String relockToken = this.getRelockToken(this.getReq()); LockManager lm = this.getLockManager(); // int status = HttpServletResponse.SC_OK; // We presume success LockInfo li = null; HttpServletResponse resp = this.getResp(); Long TimeOutValue = this.getTimeOutValue(this.getReq()); try { // LOGGER.info("getResource"); resource = rep.getResource(curURI, true); } catch (DAVNotFoundException e) { // This exception isn't a problem since we just can create the new // URL // LOGGER.info("Exception not found resource"); } if (resource == null) { // LOGGER.info("Error, resource is null"); // Set the return error // Unprocessable Entity (see // http://www.webdav.org/specs/rfc2518.html#status.code.extensions.to.http11) this.setHTTPStatus(403); return; } if (resource.isReadOnly()) { this.setHTTPStatus(403); return; } if (relockToken != null) { li = lm.relock(resource, relockToken, TimeOutValue); if (li == null) { String eString = "Relock failed for " + relockToken; LOGGER.debug(eString); this.setErrorMessage(eString, 423); // Precondition failed this.setHTTPStatus(423); return; } } String creationDate = null, modifiedDate = null; Date dt = new Date(); Date dtM = new Date(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); LOGGER.info("DB Factory built OK"); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); LOGGER.info("Document builder OK"); Document doc = dBuilder.parse(this.getReq().getInputStream()); LOGGER.info("XML Doc ok read"); if (doc != null) { LOGGER.info("doc is not null"); NodeList nlCreation = doc.getElementsByTagName("Z:Win32CreationTime"); NodeList nlModified = doc.getElementsByTagName("Z:Win32LastModifiedTime"); if (nlCreation != null) { LOGGER.info("nlCreation not null"); Node nNodeCreation = nlCreation.item(0); if (nNodeCreation != null) { LOGGER.info("nNodeCreation not null, is " + nNodeCreation.getTextContent()); creationDate = nNodeCreation.getTextContent(); LOGGER.info("Creation date=" + creationDate + " Locale is " + this.getReq().getLocale().toString()); DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.getDefault()); LOGGER.info("SimpleDate Format ok created"); try { dt = df.parse(creationDate); } catch (Exception e) { creationDate += "+00"; dt = df.parse(creationDate); } try { // dt.setTime(dt.getTime()-3*60*60*1000); resource.patchCreationDate(dt); } catch (Exception e) { } LOGGER.info("Date dt parsed with value=" + dt.toString()); } } if (nlModified != null) { LOGGER.info("nlModified not null"); Node nNodeModified = nlModified.item(0); if (nNodeModified != null) { LOGGER.info("nNodeModified not null"); modifiedDate = nNodeModified.getTextContent(); LOGGER.info("Modified date=" + modifiedDate); Locale defLoc = Locale.getDefault(); // This is the crap reason why Win7 didn;t work! DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", defLoc); try { dtM = df.parse(modifiedDate); } catch (Exception e) { modifiedDate += "+00"; dtM = df.parse(modifiedDate); } try { // dtM.setTime(dtM.getTime()-3*60*60*1000); resource.patchLastModified(dtM); } catch (Exception e) { } LOGGER.info("Date dtM parsed with value=" + dtM.toString()); } } } IDAVXMLResponse xr = DavXMLResponsefactory.getXMLResponse(null, false); xr.openTag("multistatus"); resource.addToDavXMLResponsePROPPATCH(xr); xr.closeDocument(); this.setHTTPStatus(DAVProperties.STATUS_MULTIPART); // FIXME: this is depricated! resp.setStatus(DAVProperties.STATUS_MULTIPART, DAVProperties.STATUS_MULTIPART_STRING); resp.setContentType(DAVProperties.TYPE_XML); String result = xr.toString(); resp.setContentLength(result.length()); PrintWriter out = resp.getWriter(); out.write(result); out.close(); }
From source file:com.moss.schematrax.SchemaData.java
private void initUpdates(Document document) { NodeList nodes = document.getDocumentElement().getChildNodes(); ArrayList updatesList = new ArrayList(); for (int x = 0; x < nodes.getLength(); x++) { Node updateTag = nodes.item(x); if (updateTag.getNodeName().equals(UPDATE_TAG_NAME)) { Node updateId = updateTag.getAttributes().getNamedItem("id"); Node classNameAttribute = updateTag.getAttributes().getNamedItem("class"); if (classNameAttribute != null) { updatesList.add(new DynamicSchemaUpdate(updateId.getNodeValue(), loader, classNameAttribute.getNodeValue())); } else { List<String> aliases = new ArrayList<String>(); NodeList updateTagChildren = updateTag.getChildNodes(); for (int y = 0; y < updateTagChildren.getLength(); y++) { Node node = updateTagChildren.item(y); if (node.getNodeName().equals("alias")) { aliases.add(node.getTextContent()); }/*from w w w . j ava 2s. c o m*/ } updatesList.add( new LazyLoadingSchemaUpdate(updateId.getNodeValue(), aliases.toArray(new String[] {}))); } } } updates = (SchemaUpdate[]) updatesList.toArray(new SchemaUpdate[0]); }