List of usage examples for org.jdom2.input SAXBuilder SAXBuilder
public SAXBuilder()
From source file:com.cedarsoft.serialization.test.performance.XmlParserPerformance.java
License:Open Source License
public void benchJdom() { runBenchmark(new Runnable() { @Override/*from w ww . ja v a 2s. c o m*/ public void run() { try { for (int i = 0; i < SMALL; i++) { Document doc = new SAXBuilder().build(new StringReader(CONTENT_SAMPLE)); Element fileTypeElement = doc.getRootElement(); Element extensionElement = fileTypeElement.getChild("extension"); Extension extension = new Extension(extensionElement.getAttributeValue("delimiter"), extensionElement.getText(), extensionElement.getAttribute("default").getBooleanValue()); FileType fileType = new FileType(fileTypeElement.getChildText("id"), extension, fileTypeElement.getAttribute("dependent").getBooleanValue()); assertNotNull(fileType); } } catch (Exception e) { throw new RuntimeException(e); } } }, 4); }
From source file:com.cisco.oss.foundation.logging.FoundationLogger.java
License:Apache License
/** * The sniffing Loggers are some special Loggers, whose level will be set to TRACE forcedly. * @param logger/*from w ww. j av a2 s . c om*/ */ private static void updateSniffingLoggersLevel(Logger logger) { InputStream settingIS = FoundationLogger.class.getResourceAsStream("/sniffingLogger.xml"); if (settingIS == null) { logger.debug("file sniffingLogger.xml not found in classpath"); } else { try { SAXBuilder builder = new SAXBuilder(); Document document = builder.build(settingIS); settingIS.close(); Element rootElement = document.getRootElement(); List<Element> sniffingloggers = rootElement.getChildren("sniffingLogger"); for (Element sniffinglogger : sniffingloggers) { String loggerName = sniffinglogger.getAttributeValue("id"); Logger.getLogger(loggerName).setLevel(Level.TRACE); } } catch (Exception e) { logger.error("cannot load the sniffing logger configuration file. error is: " + e, e); throw new IllegalArgumentException("Problem parsing sniffingLogger.xml", e); } } }
From source file:com.cisco.oss.foundation.logging.structured.AbstractFoundationLoggingMarker.java
License:Apache License
private static void udpateMarkerStructuredLogOverrideMap() { InputStream messageFormatIS = AbstractFoundationLoggingMarker.class .getResourceAsStream("/messageFormat.xml"); if (messageFormatIS == null) { LOGGER.debug("file messageformat.xml not found in classpath"); } else {//from w ww . ja va2s.com try { SAXBuilder builder = new SAXBuilder(); Document document = builder.build(messageFormatIS); messageFormatIS.close(); Element rootElement = document.getRootElement(); List<Element> markers = rootElement.getChildren("marker"); for (Element marker : markers) { AbstractFoundationLoggingMarker.markersXmlMap.put(marker.getAttributeValue("id"), marker); } } catch (Exception e) { LOGGER.error("cannot load the structured log override file. error is: " + e, e); throw new IllegalArgumentException("Problem parsing messageformat.xml", e); } } }
From source file:com.codeexcursion.PathCommon.java
public Document getDocument(File inputFile) { SAXBuilder jdomBuilder = new SAXBuilder(); Document jdomDocument = null; try {/*from w ww .ja v a 2 s . c om*/ jdomDocument = jdomBuilder.build(inputFile); } catch (JDOMException jde) { System.out.println(jde.toString()); jdomDocument = null; } catch (IOException ioe) { System.out.println(ioe.toString()); jdomDocument = null; } return jdomDocument; }
From source file:com.compomics.pladipus.core.control.updates.ProcessingBeanUpdater.java
/** * Adds a new class to the bean definition * @param fullyDefinedClassName the fully defined class name * @throws IllegalArgumentException//from w w w . j av a 2s . com * @throws IOException * @throws JDOMException */ public void addNewProcessingStep(String fullyDefinedClassName) throws IllegalArgumentException, IOException, JDOMException { String className = fullyDefinedClassName.substring(fullyDefinedClassName.lastIndexOf(".") + 1); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(beanXMLDefinitionFile); //check if the class is not already in there for (Element aBean : document.getRootElement().getChildren()) { if (aBean.getAttribute("class").getValue().equals(fullyDefinedClassName)) { throw new IllegalArgumentException( "Class is already defined in the bean configuration for " + aBean.getAttributeValue("id")); } else if (aBean.getAttribute("id").getValue().equals(className)) { throw new IllegalArgumentException("Classname is already in use"); } } Element newClassElement = new Element("bean").setAttribute("id", className) .setAttribute("class", fullyDefinedClassName).setAttribute("lazy-init", "true"); document.getRootElement().addContent(newClassElement); XMLOutputter outputter = new XMLOutputter(); try (StringWriter stringWriter = new StringWriter(); FileWriter writer = new FileWriter(beanXMLDefinitionFile);) { outputter.output(document, stringWriter); String output = stringWriter.getBuffer().toString(); //remove empty namespaces output = output.replace(" xmlns=\"\"", ""); writer.append(output); } }
From source file:com.constellio.app.services.appManagement.AppManagementService.java
License:Open Source License
public LicenseInfo getLicenseInfo() { LicenseInfo license = null;/*www . ja v a2s . c o m*/ try { String licenseString = ioServices.readFileToString(foldersLocator.getLicenseFile()); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(new StringReader(licenseString)); String name = document.getRootElement().getChild("name").getContent().get(0).getValue(); LocalDate date = new LocalDate( document.getRootElement().getChild("date").getContent().get(0).getValue()); String signature = document.getRootElement().getChild("signature").getContent().get(0).getValue(); license = new LicenseInfo(name, date, signature); } catch (IOException ioe) { } catch (JDOMException joe) { } return license; }
From source file:com.demo.impl.CoordenadasImpl.java
@Override public List<UbicacionCredito> obtenerCoincidencias(String colonia, String CP) { try {//from www . j a v a 2 s.c o m Session session = HibernateUtil.getSessionFactory().openSession(); Transaction t = session.beginTransaction(); //direccion completa dir.`DomDeu`,",",dir.`ColDeu`,",",dir.`Entdeu`,",",dir.`EdoDeu` String sql = "select ct.`CreditosII` as noCredito, dp.`Deudor` as nombreDeudor, cg.`Usu_login` as gestor, \n" + "ca.`Camp_Desc` as campagne, concat(dir.`DomDeu`,\",\",dir.`Entdeu`,\",\",dir.`EdoDeu`) as direccion from datos_primarios dp, direcciones dir, \n" + "credito_sf_lt_nt_ct ct, campagne ca, cat_gestores cg where\n" + "dp.`Folio`=dir.`Datos_primarios_Folio` \n" + "and ( (dir.`ColDeu`='" + colonia + "' and dir.`CodPos`='" + CP + "') or (dir.`CodPos`='" + CP + "') )\n" + "and dp.`Folio`=ct.`Datos_primarios_Folio`\n" + "and ct.`Campagne_Camp_Clv`=ca.`Camp_Clv` \n" + "and ct.`Cat_Gestores_Cat_Gestor_clv`=cg.`Cat_Gestor_clv` GROUP by dir.`idDirecciones` order by ct.`CreditosII`;"; List<UbicacionCredito> lista = session.createSQLQuery(sql).addEntity(UbicacionCredito.class).list(); t.commit(); if (lista.isEmpty()) { System.out.println(this.getClass().getName() + " Method: obtenerCoincidencias, la consulta no trajo resultados"); } else { Iterator iter = lista.listIterator(); LogSistema.guardarlog("tam lista " + lista.size()); while (iter.hasNext()) { UbicacionCredito ubicacion = new UbicacionCredito(); ubicacion = (UbicacionCredito) iter.next(); try { String direccion = ubicacion.getDireccion(); direccion = direccion.replace(" ", "%20"); direccion = direccion.replace(" norte ", ""); direccion = direccion.replace(" av ", ""); direccion = direccion.replace(" poniente ", ""); direccion = direccion.replace(" sur ", ""); direccion = direccion.replace(" oriente ", ""); direccion = direccion.replace(" calle ", ""); direccion = direccion.replace(" cll ", ""); direccion = direccion.replace(" col ", ""); direccion = direccion.replace(" norte ", ""); direccion = direccion.replace(" colonia ", ""); direccion = direccion.replace(" sn ", ""); direccion = direccion.replace(" SN ", ""); direccion = direccion.replace(" int ", ""); direccion = direccion.replace(" INT ", ""); URL url = new URL("https://maps.googleapis.com/maps/api/place/autocomplete/xml?input=" + direccion + "&types=geocode&sensor=false&key=AIzaSyDHdJ0GD3efGWzFnyQ0Dcw08eh1fb_9Pq4"); // URL url = new URL("https://maps.googleapis.com/maps/api/place/details/xml?reference=CkQ-AAAAFivu82hu1JJ7FMRBgoqZPG8yeIxL0GDB1_4g46eSghm3mV7DHXeoZkSWgii4MegpQAP2RyYRsqINAYQGZu2fURIQCjcNgINyC1BwT4zDel2FvRoU6-wFkI9DOnkb0WFyTeKdxXYh-4M&sensor=true&key=AIzaSyDHdJ0GD3efGWzFnyQ0Dcw08eh1fb_9Pq4"); LogSistema.guardarlog("URL 1: " + url.toString()); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/xml"); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String output; StringBuffer buffer = new StringBuffer(); while ((output = br.readLine()) != null) { buffer.append(output); } conn.disconnect(); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new StringReader(buffer.toString())); String ref = doc.getRootElement().getChildren("prediction").get(0).getChildren("reference") .get(0).getValue(); url = new URL("https://maps.googleapis.com/maps/api/place/details/xml?reference=" + ref + "&sensor=false&key=AIzaSyDHdJ0GD3efGWzFnyQ0Dcw08eh1fb_9Pq4"); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/xml"); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); } br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); buffer = new StringBuffer(); while ((output = br.readLine()) != null) { buffer.append(output); } conn.disconnect(); builder = new SAXBuilder(); doc = builder.build(new StringReader(buffer.toString())); ubicacion.setLatitud( doc.getRootElement().getChildren("result").get(0).getChildren("geometry").get(0) .getChildren("location").get(0).getChildren("lat").get(0).getValue()); ubicacion.setLongitud( doc.getRootElement().getChildren("result").get(0).getChildren("geometry").get(0) .getChildren("location").get(0).getChildren("lng").get(0).getValue()); //lista.add(ubicacion); ubicacion.setUbicacionEncontrada("ubicacionPositiva"); System.out.println("nombre " + ubicacion.getNombreDeudor()); LogSistema.guardarlog(this.getClass().getName() + ", latitud" + doc.getRootElement().getChildren("result").get(0).getChildren("geometry").get(0) .getChildren("location").get(0).getChildren("lat").get(0).getValue()); LogSistema.guardarlog(this.getClass().getName() + ",logitud " + doc.getRootElement().getChildren("result").get(0).getChildren("geometry").get(0) .getChildren("location").get(0).getChildren("lng").get(0).getValue()); } catch (MalformedURLException e) { e.printStackTrace(); LogSistema.guardarlog(this.getClass().getName() + " Method: obtenerCoincidencias, Exception: " + e.getMessage()); ubicacion.setUbicacionEncontrada("ubicacionNegativa"); } catch (IOException e) { LogSistema.guardarlog(this.getClass().getName() + " Method: obtenerCoincidencias, Exception: " + e.getMessage()); e.printStackTrace(); ubicacion.setUbicacionEncontrada("ubicacionNegativa"); } catch (JDOMException ex) { LogSistema.guardarlog(this.getClass().getName() + " Method: obtenerCoincidencias, Exception: " + ex.getMessage()); ubicacion.setUbicacionEncontrada("ubicacionNegativa"); } catch (IndexOutOfBoundsException ex) { LogSistema.guardarlog(this.getClass().getName() + " Method: obtenerCoincidencias, Exception: " + ex.getMessage()); ubicacion.setUbicacionEncontrada("ubicacionNegativa"); } } //fin del while } return lista; } catch (HibernateException he) { LogSistema.guardarlog( this.getClass().getName() + " Method: obtenerCoincidencias, Exception: " + he.getMessage()); List<UbicacionCredito> lista = new ArrayList<>(); return lista; } }
From source file:com.dexterapps.android.translator.TranslateTextForAndroid.java
License:Apache License
private void parseXMLAndGenerateDom(String sourceFile) { SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(sourceFile); //System.out.println(xmlFile.getAbsolutePath()); try {/* w w w . j a v a 2s. c o m*/ /*Navigate the XML DOM and populate the string array for translation We also map the XML in java object so we can use to navigate it again for generating the xml back */ Document document = (Document) builder.build(xmlFile); Element rootNode = document.getRootElement(); List list = rootNode.getChildren(); for (int i = 0; i < list.size(); i++) { AndroidStringMapping stringElement = new AndroidStringMapping(); Element stringNode = (Element) list.get(i); if (stringNode.getName().equalsIgnoreCase("string")) { stringElement.setType("string"); stringElement.setAttributeName(stringNode.getAttributeValue("name")); stringElement.setAttributeValue(stringNode.getText()); baseLanguageStringForTranslation.add(stringNode.getText()); baseStringResourcesMapping.put(stringNode.getText(), i); } else if (stringNode.getName().equalsIgnoreCase("string-array")) { List stringArrayNodeList = stringNode.getChildren(); ArrayList<String> stringArrayItems = new ArrayList<String>(); for (int j = 0; j < stringArrayNodeList.size(); j++) { Element stringArrayNode = (Element) stringArrayNodeList.get(j); baseLanguageStringForTranslation.add(stringArrayNode.getText()); baseStringResourcesMapping.put(stringArrayNode.getText(), i + j); stringArrayItems.add(stringArrayNode.getText()); } stringElement.setType("string-array"); stringElement.setAttributeName(stringNode.getAttributeValue("name")); stringElement.setAttributeValue(stringArrayItems); } else { List stringPluralNodeList = stringNode.getChildren(); ArrayList<AndroidStringPlurals> stringPluralsItems = new ArrayList<AndroidStringPlurals>(); for (int j = 0; j < stringPluralNodeList.size(); j++) { Element stringPluralNode = (Element) stringPluralNodeList.get(j); baseLanguageStringForTranslation.add(stringPluralNode.getText()); baseStringResourcesMapping.put(stringPluralNode.getText(), i + j); AndroidStringPlurals pluralItem = new AndroidStringPlurals(); pluralItem.setAttributeName(stringPluralNode.getAttributeValue("quantity")); pluralItem.setAttributeValue(stringPluralNode.getText()); stringPluralsItems.add(pluralItem); } stringElement.setType("plurals"); stringElement.setAttributeName(stringNode.getAttributeValue("name")); stringElement.setAttributeValue(stringPluralsItems); } stringXmlDOM.add(stringElement); } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } }
From source file:com.doubotis.sc2dd.util.FontStyleXMLAnalyzer.java
public void analyze(InputStream is) { SAXBuilder sxb = new SAXBuilder(); try {//from ww w .ja v a 2s. c o m Document document = sxb.build(is); computeAnalyze(document); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.eds.Model.XMLProcessor.java
License:Apache License
public AuthToken ProcessUIDAuthResponse(ServiceResponse response) { BufferedReader reader = response.getReader(); String authTokenXML = ""; AuthToken authToken = new AuthToken(); if (null != response.getErrorStream() && !response.getErrorStream().isEmpty()) { authToken.setErrorMessage(ProcessAuthError(response.getErrorNumber(), response.getErrorStream())); return authToken; }/*from w w w . ja va 2 s . c o m*/ if (null != reader) { try { String line = ""; while ((line = reader.readLine()) != null) { authTokenXML += line; } StringReader stringReader = new StringReader(authTokenXML); InputSource inputSource = new InputSource(stringReader); Document doc = (new SAXBuilder()).build(inputSource); Element root = doc.getRootElement(); Content content = root.getContent().get(0); Content timeout = root.getContent().get(1); if (content.getValue() != null) { authToken.setAuthToken(content.getValue()); authToken.setAuthTimeout(timeout.getValue()); } } catch (Exception e) { ApiErrorMessage errorMessage = new ApiErrorMessage(); errorMessage.setErrorDescription("Error processing UID auth response"); errorMessage.setDetailedErrorDescription(e.getMessage()); authToken.setErrorMessage(errorMessage); } } return authToken; }