List of usage examples for org.jdom2.input SAXBuilder build
@Override public Document build(final String systemId) throws JDOMException, IOException
This builds a document from the supplied URI.
From source file:com.c4om.utils.xmlutils.JDOMUtils.java
License:Apache License
/** * Loads a XML file from a string as a JDOM Document * @param s the input string//w w w . j a v a 2 s . co m * @return the loaded document * @throws IOException Input/Output errors. * @throws JDOMException Errors at XML parsing. */ public static Document loadJDOMDocumentFromString(String s) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); return builder.build(new StringReader(s)); }
From source file:com.cats.version.VersionCfgParseAndSave.java
License:Apache License
public List<VersionInfo> getVersionInfo(String fullPath) { SAXBuilder builder = new SAXBuilder(); List<VersionInfo> infos = new ArrayList<VersionInfo>(); try {//from w w w . j ava 2s . c om Document doc = builder.build(new File(fullPath)); Element root = doc.getRootElement(); List<Element> softEles = root.getChildren("software"); for (Element softEle : softEles) { String appName = softEle.getAttribute("name").getValue(); String versionCode = softEle.getChildText("latest-version-code"); String versionName = softEle.getChildText("latest-version"); String versionPath = softEle.getChildText("latest-version-abspath"); String startupName = softEle.getChildText("latest-version-startup"); Element detailEles = softEle.getChild("latest-version-detail"); List<Element> detailItemEles = detailEles.getChildren("item"); List<VersionInfoDetail> details = new ArrayList<VersionInfoDetail>(); for (Element detailItem : detailItemEles) { String title = detailItem.getAttributeValue("name"); List<Element> detailEleList = detailItem.getChildren("detail"); List<String> detailList = new ArrayList<String>(); for (Element detailEle : detailEleList) { String strDetail = detailEle.getText(); detailList.add(strDetail); } details.add(new VersionInfoDetail(title, detailList)); } Element ignoreEles = softEle.getChild("ignore-files"); List<String> ignoreFiles = new ArrayList<String>(); if (ignoreEles != null) { List<Element> ignoreItems = ignoreEles.getChildren("item"); for (Element ignoreItem : ignoreItems) { ignoreFiles.add(ignoreItem.getText()); } } VersionInfo versionInfo = new VersionInfo(); versionInfo.setAppName(appName); versionInfo.setVersion(versionName); versionInfo.setStartupName(startupName); versionInfo.setVersionCode(Integer.parseInt(versionCode)); versionInfo.setPath(versionPath); versionInfo.setDetails(details); versionInfo.setIgnoreFiles(ignoreFiles); infos.add(versionInfo); } } catch (Exception e) { e.printStackTrace(); return null; } return infos; }
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 w w .j a v a2s. 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 {/* w w w.ja va 2 s. c om*/ 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 . java2 s .c o m 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/*w w w . j a v a2s .c o m*/ * @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;//from w ww. j a v a 2s . com 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 {/* ww w . ja v a2s . co 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 2 s . co 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 {//w w w . j a v a 2 s . com Document document = sxb.build(is); computeAnalyze(document); } catch (Exception e) { e.printStackTrace(); } }