List of usage examples for org.jdom2 Element getChildTextTrim
public String getChildTextTrim(final String cname)
From source file:mailtorrentreceiver.MailTorrentReceiver.java
public static void retriveParms() { //Recupero l'xml di configurazione SAXBuilder builder = new SAXBuilder(); Element rootElement;/*from w w w . j a v a 2s .co m*/ Element mailConf; Document doc; try { doc = builder.build(new File("./settings/settings.xml")); } catch (Exception ex) { System.out.println("Filed to get mail settings from xml"); System.out.println(ex.toString()); return; } //Ottengo la root del documento xml rootElement = doc.getRootElement(); mailConf = rootElement.getChild("mail-config"); mailFrom = mailConf.getChildTextTrim("mail-address-from"); mailSubject = mailConf.getChildTextTrim("mail-subject-monitorig"); String encPassword = mailConf.getChildTextTrim("password"); UserName = mailConf.getChildTextTrim("user"); smtpHost = mailConf.getChildTextTrim("smtp-server"); smtpPort = Integer.parseInt(mailConf.getChildTextTrim("smtp-port")); if (mailConf.getChildTextTrim("use-smtp-SSL").equalsIgnoreCase("true")) { usesmtpSSL = true; } else { usesmtpSSL = false; } if (mailConf.getChildTextTrim("use-imap-SSL").equalsIgnoreCase("true")) { useimapSSL = true; } else { useimapSSL = false; } if (mailConf.getChildTextTrim("use-smtp-auth").equalsIgnoreCase("true")) { usesmtpAuth = true; } else { usesmtpAuth = false; } if (mailConf.getChildTextTrim("use-imap-auth").equalsIgnoreCase("true")) { useimapAuth = true; } else { useimapAuth = false; } imapHost = mailConf.getChildTextTrim("imap-server"); imapPort = Integer.parseInt(mailConf.getChildTextTrim("imap-port")); //Watch-dir watchdir = rootElement.getChildTextTrim("watch-dir"); Password = encPassword; //decrypto password File file = new File("./settings/.secret.bin"); if (file.exists() && !file.canRead()) { System.out.println("Read file permission Error \n Now Exit"); return; } if (!file.exists()) { System.out.println("File not exists \n Now Exit"); return; } FileInputStream inputfile; byte[] keyBytes; SecretKey key; try { inputfile = new FileInputStream(file); } catch (FileNotFoundException ex) { return; } byte[] buffer = new byte[4096]; int byteRead; try { keyBytes = getBytesFromInputStream(inputfile); } catch (IOException ex) { return; } try { inputfile.close(); } catch (IOException ex) { return; } key = new SecretKeySpec(keyBytes, "DES"); DesEncrypter encrypter; try { encrypter = new DesEncrypter(key); } catch (Exception ex) { return; } try { Password = encrypter.decrypt(encPassword); } catch (Exception ex) { return; } }
From source file:model.LecturaXML.java
public String[] cargarXml() { //Se crea un SAXBuilder para poder parsear el archivo String[] Archivo = new String[6]; SAXBuilder builder = new SAXBuilder(); File xmlFile = new File("C:\\website\\dbconnectionpla.xml"); try {/* ww w . j a v a2 s . c om*/ //Se crea el documento a traves del archivo Document document = (Document) builder.build(xmlFile); //Se obtiene la raiz 'tables' Element rootNode = document.getRootElement(); //Se obtiene la lista de hijos de la raiz 'tables' List list = rootNode.getChildren("WebAccess"); Archivo[0] = Integer.toString(list.size()); //Se recorre la lista de hijos de 'tables' for (int i = 0; i < list.size(); i++) { //Se obtiene el elemento 'tabla' Element tabla = (Element) list.get(i); //Se obtiene el atributo 'nombre' que esta en el tag 'tabla' String nombreTabla = tabla.getAttributeValue("web"); //System.out.println( "Tabla: " + nombreTabla ); //Se obtiene la lista de hijos del tag 'tabla' List lista_campos = tabla.getChildren(); //Se recorre la lista de campos for (int j = 0; j < lista_campos.size(); j++) { //Se obtiene el elemento 'campo' Element campo = (Element) lista_campos.get(j); //Se obtienen los valores que estan entre los tags '<Parametros></server>' //Se obtiene el valor que esta entre los tags '<server></server>' Archivo[0] = campo.getChildTextTrim("server"); //Se obtiene el valor que esta entre los tags '<port></port>' Archivo[1] = campo.getChildTextTrim("port"); //Se obtiene el valor que esta entre los tags '<database></database>' Archivo[2] = campo.getChildTextTrim("database"); //Se obtiene el valor que esta entre los tags '<username></username>' Archivo[3] = campo.getChildTextTrim("username"); //Se obtiene el valor que esta entre los tags '<password></password>' Archivo[4] = campo.getChildTextTrim("password"); //Se obtiene el valor que esta entre los tags '<driver></driver>' Archivo[5] = campo.getChildTextTrim("driver"); } } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } return Archivo; }
From source file:Modelo.FileRead.java
public void leer() { try {/* ww w .ja va 2s . com*/ //Se crea el documento a traves del archivo Document document = (Document) builder.build(xmlFile); //Se obtiene la raiz 'tables' Element rootNode = document.getRootElement(); //Se obtiene la lista de hijos de la raiz 'tables' List list = rootNode.getChildren(); //Se recorre la lista de hijos de 'tables' for (int i = 0; i < list.size(); i++) { //Se obtiene el elemento 'Familia' Element familia = (Element) list.get(i); //Se obtiene el atributo 'nombre' que esta en el tag 'tabla' String nombreTabla = familia.getAttributeValue("nombre"); //Se obtiene la lista de hijos del tag 'tabla' List lista_campos = familia.getChildren(); Familia aux = new Familia(nombreTabla); //Se recorre la lista de campos for (int j = 0; j < lista_campos.size(); j++) { //Se obtiene el elemento 'campo' Element campo = (Element) lista_campos.get(j); if (campo.getName().equals("MiembroFamilia")) { String nombre = campo.getChildTextTrim("nombre"); String rut = campo.getChildTextTrim("rut"); String clave = campo.getChildTextTrim("clave"); MiembroFamilia mf = new MiembroFamilia(nombre, rut, clave); aux.addMiembro(mf); } else if (campo.getName().equals("Fotografia")) { String path = campo.getChildTextTrim("path"); String comentario = campo.getChildTextTrim("comentario"); Fotografia f = new Fotografia(path, comentario); aux.addFoto(f); } } fam.add(aux); } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } }
From source file:mom.trd.opentheso.core.alignment.GpsQuery.java
private ArrayList<NodeAlignment> getlisteAlign(String xmlrecord) { ArrayList<NodeAlignment> listeAlign1 = new ArrayList<>(); //Se crea un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(xmlrecord); try {// ww w. j a v a 2s. c om //Se crea el documento a traves del archivo Document document = (Document) builder.build(xmlFile); //Se obtiene la raiz 'tables' Element rootNode = document.getRootElement(); //Se obtiene la lista de hijos de la raiz 'tables' List list = rootNode.getChildren("geoname"); //Se recorre la lista de hijos de 'tables' for (int i = 0; i < list.size(); i++) { //Se obtiene el elemento 'tabla' Element tabla = (Element) list.get(i); //Se obtiene la lista de hijos del tag 'tabla' List lista_campos = tabla.getChildren(); //Se recorre la lista de campos for (int j = 0; j < lista_campos.size(); j++) { //Se obtiene el elemento 'campo' Element campo = (Element) lista_campos.get(j); //Se obtienen los valores que estan entre los tags '<campo></campo>' //Se obtiene el valor que esta entre los tags '<nombre></nombre>' String nombre = campo.getChildTextTrim("name"); //Se obtiene el valor que esta entre los tags '<tipo></tipo>' String tname = campo.getChildTextTrim("toponymName"); //Se obtiene el valor que esta entre los tags '<valor></valor>' String lat = campo.getChildTextTrim("lat"); String lng = campo.getChildTextTrim("lng"); System.out.println("\t" + nombre + "\t\t" + tname + "\t\t" + lat + "\t\t" + lng); } } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } return listeAlign1; }
From source file:net.instantcom.mm7.MM7Error.java
License:Open Source License
@Override public void load(Element element) { Element body = element.getChild("Body", MM7Message.ENVELOPE); Element e = (Element) body.getChildren().get(0); this.faultCode = e.getChildTextTrim("faultcode"); this.faultMessage = e.getChildTextTrim("faultstring"); try {// w w w . j a va2 s . c om Element detail; if (element.getNamespace("") != null) { detail = (Element) e.getChild("detail", element.getNamespace("")).getChildren().get(0); } else { detail = (Element) e.getChild("detail").getChildren().get(0); } String message = detail.getName(); // Instantiate correct status type Class<?> clazz = Class.forName("net.instantcom.mm7." + message); this.response = (MM7Response) clazz.newInstance(); this.response.load(element); } catch (Throwable t) { // Ignored XMLOutputter outp = new XMLOutputter(); String s = outp.outputString(element); System.err.println("Failed to instantiate a correct response type" + s); t.printStackTrace(); } }
From source file:net.siegmar.japtproxy.misc.Configuration.java
License:Open Source License
/** * Initialize the configuration with the given config file. * * @param configFile the config file./* w w w . ja v a2s.c o m*/ * @throws InitializationException is thrown if the configuration is erroneous. */ public Configuration(final File configFile) throws InitializationException { try { final SAXBuilder sax = new SAXBuilder(); final Document doc = sax.build(configFile); final Element rootElement = doc.getRootElement(); cacheDir = new File(rootElement.getChildTextTrim("cache-dir")); httpProxy = rootElement.getChildTextTrim("http-proxy"); final String maxVersionsString = rootElement.getChildTextTrim("max-versions"); maxVersions = NumberUtils.createInteger(maxVersionsString); // support remap definitions // Syntax in config file: /* <remaps> <remap from="sourcehost" to="targethost"/> </remaps> */ final List<Element> remapElements = rootElement.getChild("remaps").getChildren(); for (final Element e : remapElements) { final String from = e.getAttributeValue("from"); final String to = e.getAttributeValue("to"); if (from == null || to == null) { LOG.debug("from or to missing from remap config element"); throw new InitializationException( "Error reading configuration. Remap does not contain from and/or to attribute"); } if (remaps.containsKey(from)) { LOG.debug("Mapping for remap {} already present in config file", from); throw new InitializationException( "Error reading configuration. Duplicate remap config for from: " + from); } LOG.debug("Added remap: {} -> {}", from, to); remaps.put(from, to); } /* final List<Element> backends = rootElement.getChild("backends").getChildren(); // disable backend config for (final Element e : backends) { final List<Element> confUrls = e.getChildren(); if (confUrls == null || confUrls.isEmpty()) { continue; } final String name = e.getAttributeValue("name"); final String type = e.getAttributeValue("type"); if (type == null) { throw new InitializationException("type attribute is missing for backend '" + name + "'"); } final String dir = e.getAttributeValue("dir"); final Backend backend = new Backend(BackendType.valueOf(type.toUpperCase(Locale.ENGLISH))); final File backendDirectory = new File(cacheDir, StringUtils.defaultIfEmpty(dir, name)); FileUtils.forceMkdir(backendDirectory); backend.setDirectory(backendDirectory); for (final Element confUrl : confUrls) { backend.addUrl(new URL(confUrl.getTextTrim())); } backendSystems.put(name, backend); } */ } catch (final IOException | JDOMException e) { throw new InitializationException("Error reading configuration", e); } LOG.debug("Initialized configuration: {}", this); }
From source file:odml.core.Reader.java
License:Open Source License
/** * Parses property and creates the odMLProperty representation of it. * //ww w . j ava2s . co m * @param domProperty - {@link Element}: the Element to parse. (should be a property element) * @return {@link Property} the {@link Property} representation of this domElement */ private Property parseProperty(Element domProperty) { String name; name = domProperty.getChildTextTrim("name"); String dependency; String dependencyValue; String definition; URL mapURL = null; String temp = domProperty.getChildText("mapping"); if (temp != null && !temp.isEmpty() && !temp.endsWith("?")) { try { mapURL = new URL(temp); } catch (Exception e) { System.out.println("odml.core.Reader.parseProperty.mappingURL handling: \n" + " \t> tried to form URL out of: '" + domProperty.getChildText("mapping") + "'\n\t= mapURL of Property named: " + name + e.getMessage()); } } definition = domProperty.getChildText("definition"); dependency = domProperty.getChildText("dependency"); dependencyValue = domProperty.getChildText("dependencyValue"); Vector<Value> tmpValues = new Vector<Value>(); for (Element element : domProperty.getChildren("value")) { tmpValues.add(parseValue(element)); } Property property; try { property = new Property(name, tmpValues, definition, dependency, dependencyValue, mapURL); } catch (Exception e) { System.out.println("odml.core.Reader.parseProperty: create new prop failed. " + e.getMessage()); property = null; } return property; }
From source file:open.dolphin.adm10.rest.AbstractResource.java
protected void startIcon(StringBuilder sb, Element current) { String name = current.getChildTextTrim("name"); if (name != null) { debug(name);/*from w w w.j av a2 s . c o m*/ } }
From source file:org.esa.beam.occci.ModisL1aScanner.java
License:Open Source License
private static double[] getValues(Element element) { int numValues = Integer.parseInt(element.getChildTextTrim("NUM_VAL")); Element valueElement = element.getChild("VALUE"); List<Element> children = valueElement.getChildren(); if (children.size() != numValues) { String msg = String.format("Error in parsing GRINGPOINT. %d childs, but 'num_val' is %d", children.size(), numValues); throw new IllegalArgumentException(msg); }//from ww w.jav a 2 s . c o m double[] values = new double[numValues]; for (int i = 0; i < values.length; i++) { values[i] = Double.parseDouble(children.get(i).getTextTrim()); } return values; }
From source file:org.graphwalker.Util.java
License:Open Source License
private static PathGenerator getGenerator(final FiniteStateMachine machine, final Element generator) throws StopConditionException, GeneratorException, IOException { int generatorType = Keywords.getGenerator(generator.getAttributeValue("TYPE")); PathGenerator generatorObject = getGenerator(generatorType); if (generatorObject instanceof CodeGenerator) { String[] template = { "", "", "" }; String templateFile = generator.getAttributeValue("VALUE"); if (templateFile != null) { template[1] = readFile(Util.getFile(templateFile.trim())); } else {//from www. ja v a 2 s . c om Element templateElement = generator.getChild("TEMPLATE"); if (templateElement != null) { template[0] = templateElement.getChildTextTrim("HEADER"); template[1] = templateElement.getChildTextTrim("BODY"); template[2] = templateElement.getChildTextTrim("FOOTER"); } else { throw new RuntimeException("No Template is specified for the stub generator."); } } ((CodeGenerator) generatorObject).setTemplate(template); } else { StopCondition stopCondition = getCondition(machine, generator.getChildren()); if (stopCondition != null) { generatorObject.setStopCondition(stopCondition); } } return generatorObject; }