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:LectorXml.CargarXML.java
public void cargarDiccionario(String ruta) { //se cra un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); File ArchivoXml = new File(ruta); try {//from ww w .ja v a2 s . co m //se crea el docuemento a traves del archio Document documento = (Document) builder.build(ArchivoXml); //se obtiene la raiz scrabble Element raiz = documento.getRootElement(); //se obtiene la lista de hijos de la raiz List list = raiz.getChildren("diccionario"); //si lista tiene un elemento lo obtiene if (list.size() == 1) { //se obtiene el elemento diccionario Element diccionario = (Element) list.get(0); // se obtiene los elementos de diccionario qe son palabras List list_palabras = diccionario.getChildren(); for (int x = 0; x < list_palabras.size(); x++) { Element palabra = (Element) list_palabras.get(x); System.out.println("" + palabra.getTextTrim()); } } else if (list.size() == 0) { JOptionPane.showMessageDialog(null, "No existe ninguna dimension del tablero"); } else { JOptionPane.showMessageDialog(null, "Revise su archivo de entrada"); } } catch (IOException io) { JOptionPane.showMessageDialog(null, io.getMessage()); } catch (JDOMException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } }
From source file:LectorXml.CargarXML.java
public void cargarCasilla(String ruta) { //se cra un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); File ArchivoXml = new File(ruta); try {/*from ww w . j a v a2s .c o m*/ //se crea el docuemento a traves del archio Document documento = (Document) builder.build(ArchivoXml); //se obtiene la raiz scrabble Element raiz = documento.getRootElement(); //se obtiene la lista de hijos de la raiz List list = raiz.getChildren("dobles"); //si lista tiene un elemento lo obtiene if (list.size() == 1) { Element dobles = (Element) list.get(0); // se obtiene los elementos de diccionarioque son casillas List list_casilla = dobles.getChildren(); for (int x = 0; x < list_casilla.size(); x++) { Element casilla = (Element) list_casilla.get(x); System.out.println("x: " + casilla.getChildTextTrim("x")); System.out.println("y: " + casilla.getChildTextTrim("y")); } } else if (list.size() == 0) { JOptionPane.showMessageDialog(null, "No existe ninguna dimension del tablero"); } else { JOptionPane.showMessageDialog(null, "Revise su archivo de entrada"); } } catch (IOException io) { JOptionPane.showMessageDialog(null, io.getMessage()); } catch (JDOMException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } }
From source file:Lectura.Archivo.java
public void leerXML(String path) { SAXBuilder builder = new SAXBuilder(); File xml = new File(path); try {/*from w w w.j av a2 s . c om*/ Document doc = (Document) builder.build(xml); Element nodoRaiz = doc.getRootElement(); List dimensions = nodoRaiz.getChildren("dimension"); Element elemento = (Element) dimensions.get(0); dimension = elemento.getValue(); List dobles = nodoRaiz.getChildren("dobles"); Element doble = (Element) dobles.get(0); List casillas = doble.getChildren("casilla"); for (int i = 0; i < casillas.size(); i++) { Dimension dim; int x; int y; Element casilla = (Element) casillas.get(i); List posx = casilla.getChildren("x"); Element xx = (Element) posx.get(0); x = Integer.parseInt(xx.getValue()); List posy = casilla.getChildren("y"); Element yy = (Element) posy.get(0); y = Integer.parseInt(yy.getValue()); dim = new Dimension(x, y); listaCasillaDobles.add(dim); } List triples = nodoRaiz.getChildren("triples"); Element triple = (Element) triples.get(0); List casillas_t = triple.getChildren("casilla"); for (int i = 0; i < casillas_t.size(); i++) { Dimension dim; int x; int y; Element casilla_t = (Element) casillas_t.get(i); List posx = casilla_t.getChildren("x"); Element xx = (Element) posx.get(0); x = Integer.parseInt(xx.getValue()); List posy = casilla_t.getChildren("y"); Element yy = (Element) posy.get(0); y = Integer.parseInt(yy.getValue()); dim = new Dimension(x, y); listaCasillasTriples.add(dim); } List dic = nodoRaiz.getChildren("diccionario"); Element word = (Element) dic.get(0); List palabras = word.getChildren("palabra"); for (int i = 0; i < palabras.size(); i++) { Element palabra = (Element) palabras.get(i); getDiccionario().add(palabra.getValue()); } // } catch (Exception e) { } }
From source file:lu.list.itis.dkd.aig.util.DocumentConverter.java
License:Apache License
/** * Helper method to build a {@link Document} from an provided XML string. * * @param xml// w w w. j av a 2 s . c o m * The XML to build the document from. * @return The created {@link Document} instance. * @throws TemplateParseException * Thrown when conversion of the string to a document fails. */ @SuppressWarnings("null") public static Document convertStringToDocument(final String xml) throws TemplateParseException { final SAXBuilder saxBuilder = new SAXBuilder(); try { Document document = saxBuilder.build(new StringReader(xml)); return saxBuilder.build(new StringReader(removeTrailingEmptyElements(document))); } catch (final JDOMException e) { throw new TemplateParseException("The provided XML contains errors and cannot be parsed!", e); //$NON-NLS-1$ } catch (final IOException e) { throw new TemplateParseException("An I/O error occured during parsing!", e); //$NON-NLS-1$ } }
From source file:lu.list.itis.dkd.aig.util.DocumentConverter.java
License:Apache License
/** * Method used to build a {@link Document} from a provided input stream. * * @param inputStream/* w ww . j a va 2s .co m*/ * The stream to read the document from. * @return The created {@link Document} instance. * @throws TemplateParseException * Thrown when conversion of the stream contents to document * fails. */ @SuppressWarnings("null") public static Document convertStreamToDocument(final InputStream inputStream) throws TemplateParseException { final SAXBuilder saxBuilder = new SAXBuilder(); saxBuilder.setIgnoringElementContentWhitespace(true); try { return saxBuilder.build(new InputStreamReader(inputStream)); } catch (final JDOMException e) { throw new TemplateParseException("The provided XML contains errors and cannot be parsed!", e); //$NON-NLS-1$ } catch (final IOException e) { throw new TemplateParseException("An I/O error occured during parsing!", e); //$NON-NLS-1$ } }
From source file:lu.list.itis.dkd.assess.opennlp.util.Wrapper.java
License:Apache License
public static Document getDocument(String xml) throws IOException { Document doc = null;//from w ww .j av a 2s. com final SAXBuilder saxBuilder = new SAXBuilder(); try { doc = saxBuilder.build(new StringReader(xml)); } catch (JDOMException e) { logger.log(Level.SEVERE, "Problem creating document", e); e.printStackTrace(); } return doc; }
From source file:mailserverapp.MailServerApp.java
private void readConfigFile() { SAXBuilder saxBuilder = new SAXBuilder(); File file = new File("usr/config.xml"); try {/*w w w.j a v a 2s . c om*/ // converted file to document object Document document = saxBuilder.build(file); // get root node from xml Element rootNode = document.getRootElement(); String defaultPort = rootNode.getChild("default_port").getValue(); String directory = rootNode.getChild("directory").getValue(); System.out.println("Configuration file - Default port: " + defaultPort); System.out.println("Configuration file - Saved directory: " + directory); jTextFieldPort.setText(defaultPort); this.port = Integer.parseInt(defaultPort); } catch (JDOMException | IOException e) { } }
From source file:mailtorrentreceiver.MailTorrentReceiver.java
public static void retriveParms() { //Recupero l'xml di configurazione SAXBuilder builder = new SAXBuilder(); Element rootElement;/*from www.j av a 2 s. c om*/ 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:main.Var.java
License:Open Source License
private static void XMLLoad(String ruta) { try {/* ww w. j a v a 2s . com*/ con = new Conexion(); conFtp = new ConexionFtp(); SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(ruta); Document document = (Document) builder.build(xmlFile); Element config = document.getRootElement(); Element conexion = config.getChild("conexion"); con.setDireccion(conexion.getChildText("db-host")); con.setPuerto(conexion.getChildText("db-port")); con.setUsuario(conexion.getChildText("db-username")); con.setPass(conexion.getChildText("db-password")); Element ftp = config.getChild("ftp"); conFtp.setHost(ftp.getChildText("ftp-host")); conFtp.setPort(Integer.parseInt(ftp.getChildText("ftp-port"))); conFtp.setUser(ftp.getChildText("ftp-user")); conFtp.setPass(ftp.getChildText("ftp-pass")); Element admin = config.getChild("modoAdmin"); String activo = admin.getChildText("activo"); modoAdmin = activo.equals("true"); String pass = admin.getChildText("password"); passwordAdmin = pass; String limit = admin.getChildText("query-limit"); queryLimit = limit; } catch (JDOMException | IOException ex) { Logger.getLogger(Var.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:main.Var.java
License:Open Source License
private static void XMLSave(String ruta) { try {/*from www . j av a 2 s .co m*/ Element ele; SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(ruta); Document document = (Document) builder.build(xmlFile); Element config = document.getRootElement(); Element conexion = config.getChild("conexion"); ele = conexion.getChild("db-host"); ele.setText(con.getDireccion()); ele = conexion.getChild("db-port"); ele.setText(con.getPuerto()); ele = conexion.getChild("db-username"); ele.setText(con.getUsuario()); ele = conexion.getChild("db-password"); ele.setText(con.getPass()); Element ftp = config.getChild("ftp"); ele = ftp.getChild("ftp-host"); ele.setText(conFtp.getHost()); ele = ftp.getChild("ftp-port"); ele.setText(Integer.toString(conFtp.getPort())); ele = ftp.getChild("ftp-user"); ele.setText(conFtp.getUser()); ele = ftp.getChild("ftp-pass"); ele.setText(conFtp.getPass()); Element admin = config.getChild("modoAdmin"); ele = admin.getChild("activo"); if (modoAdmin) { ele.setText("true"); } else { ele.setText("false"); } ele = admin.getChild("password"); ele.setText(passwordAdmin); ele = admin.getChild("query-limit"); ele.setText(queryLimit); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try { outputter.output(document, new FileOutputStream(configFile)); } catch (Exception e) { e.getMessage(); } } catch (JDOMException | IOException ex) { Logger.getLogger(Var.class.getName()).log(Level.SEVERE, null, ex); } }