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:Model.ConsultarXML.java
/*** * Metodo para solicitar la informacion de una etiqueta en especfico * @param Documento documento que se inspecionar * @param Variable variabel dentro de la etiqueta que se buscar si se desea el texto entre la etiqueta se coloca Null * @param indice indice donde se encuentra la informacion * @param Ruta si se requiere se coloca la ruta para llegar a la informacin requerida sino se coloca null * @return// w w w . j a va2 s . c o m * @throws JDOMException */ public static String InformacionEtiqueta(String Documento, String Variable, int indice, String Ruta) throws JDOMException, IOException, Exception { //Se crea un SAXBuilder para poder parsear el archivo String Respuesta = ""; String[] rut; SAXBuilder builder = new SAXBuilder(); if (!Ruta.equals("")) rut = Ruta.split(Util.SEPARADOR_DIRECTORIO); else rut = new String[0]; org.jdom2.Element rootNode; File xmlFile = new File(Documento); //Se crea el documento a traves del archivo org.jdom2.Document document = (org.jdom2.Document) builder.build(xmlFile); //Se obtiene la raiz 'tables' rootNode = document.getRootElement(); for (int i = 0; i < rut.length; i++) rootNode = elementoNodo(rut[i], rootNode.getChildren()); //Se obtiene la lista de hijos de la raiz 'tables' List list = rootNode.getChildren(); //Se obtiene el elemento 'tabla' org.jdom2.Element tabla = (org.jdom2.Element) list.get(indice); if (!Variable.equals("")) { if (Variable.equals(Util.ETIQUETA_NOMBRE)) Respuesta = tabla.getName(); else Respuesta = tabla.getAttributeValue(Variable); } else Respuesta = tabla.getText(); return Respuesta; }
From source file:model.data.manager.Manager.java
License:Open Source License
@Override public void recovery(String path) { if (path == null || path.isEmpty()) path = VARIABLES.ManagerFilePath; SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(path); boolean recovered = true; try {/* ww w . ja v a 2 s. c om*/ Document document = (Document) builder.build(xmlFile); Element root = document.getRootElement(); Element usersElement = root.getChild("users"); for (Element e : usersElement.getChildren()) { userManager.addUser(new User(e)); } Element itemsElement = root.getChild("items"); for (Element e : itemsElement.getChildren()) { itemManager.addItem(new Item(e)); } Element messagesElement = root.getChild("messages"); for (Element e : messagesElement.getChildren()) { messageManager.addMessage(new UserMessage(e)); } Element conversationsElement = root.getChild("ReceivedMessages"); for (Element e : conversationsElement.getChildren()) { messageManager.addConversations(new Conversations(e)); } Element favoritesElement = root.getChild("favorites"); for (Element e : favoritesElement.getChildren()) { favoriteManager.addFavorites(new Favorites(e), false); } Element dealsElement = root.getChild("deals"); for (Element e : dealsElement.getChildren()) { String owner = e.getChild("owner").getText(); if (!contratManager.containsUser(owner) && userManager.userExists(owner)) contratManager.getDeals().put(owner, new ArrayList<Contrat>()); if (e.getChild(Contrat.class.getName()) != null) contratManager.addDeal(owner, new Contrat(e.getChild(Contrat.class.getName()))); } } catch (FileNotFoundException e) { recovered = Printer.printError(this, "recovery", "File \"" + path + "\" doesn't exist"); } catch (IOException e) { recovered = Printer.printError(this, "recovery", "IOException\n\t" + e.toString()); } catch (JDOMException e) { recovered = Printer.printError(this, "recovery", "JDOMException\n\tFile \"" + path + "\" is empty"); xmlFile.delete(); } finally { if (recovered) Printer.printInfo(this, "recovery", "Local data recovered"); } }
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 {/*from www. j a v a2 s . c o m*/ //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:Model.ServidorXMLFIle.java
public static boolean saveUserInServerDataBase(String Hora, String Nombre, String Cantidad, String Protocolo) { Document doc;/* ww w. j a va2s . co m*/ Element root, newChild; SAXBuilder builder = new SAXBuilder(); try { doc = builder.build(UtilCliente.USERS_XML_PATH); root = doc.getRootElement(); newChild = new Element(UtilCliente.SERVER_TAG); newChild.setAttribute(UtilCliente.HORA_TAG, Hora); newChild.setAttribute(UtilCliente.NOMBRE_TAG, Nombre); newChild.setAttribute(UtilCliente.CANTIDAD_TAG, Cantidad); newChild.setAttribute(UtilCliente.PRIMITIVA_TAG, Protocolo); root.addContent(newChild); try { Format format = Format.getPrettyFormat(); XMLOutputter out = new XMLOutputter(format); FileOutputStream file = new FileOutputStream(UtilCliente.USERS_XML_PATH); out.output(doc, file); file.flush(); file.close(); } catch (Exception e) { e.printStackTrace(); } } catch (JDOMParseException e) { System.out.println(UtilCliente.ERROR_XML_EMPTY_FILE); e.printStackTrace(); } catch (JDOMException e) { System.out.println(UtilCliente.ERROR_XML_PROCESSING_FILE); e.printStackTrace(); } catch (IOException e) { System.out.println(UtilCliente.ERROR_XML_PROCESSING_FILE); e.printStackTrace(); } return true; }
From source file:modelo.ArchivoXmlUsuario.java
private ArchivoXmlUsuario(String rutaArchivo) throws JDOMException, IOException { SAXBuilder saxB = new SAXBuilder(); saxB.setIgnoringElementContentWhitespace(true); this.documento = saxB.build(rutaArchivo); this.raiz = this.documento.getRootElement(); this.ruta = rutaArchivo; }
From source file:Modelo.CrearXml.java
public void leerArchivoXml() { SAXBuilder builder = new SAXBuilder(); File xmlFile = new File("empleadoC.xml"); try {// w w w .ja v a 2 s .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("empleado"); //Se recorre la lista de hijos de 'tables' for (int i = 0; i < list.size(); i++) { Element tabla = (Element) list.get(i); String nombre = tabla.getChildText("nombre"); System.out.println("nombre:" + nombre); String id = tabla.getAttributeValue("id"); System.out.println("id:" + id); String telefono = tabla.getChildText("telefono"); System.out.println("telefono:" + telefono); String numContrato = tabla.getChildText("numContrato"); System.out.println("numContrato:" + numContrato); String actividad = tabla.getChildText("actividad"); System.out.println("actividad:" + actividad); } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } }
From source file:Modelo.FormularioD2XML.java
public void abrirArchivo() throws IOException { try {/* w w w . j av a 2 s . co m*/ SAXBuilder sAXBuilder = new SAXBuilder(); sAXBuilder.setIgnoringElementContentWhitespace(true); documento = sAXBuilder.build(ruta); raiz = documento.getRootElement(); } catch (JDOMException ex) { System.out.println("error"); } }
From source file:Modelo.ProductorXMLFIle.java
public static boolean saveUserInServerDataBase(String Hora, String Nombre, String Cantidad) { Document doc;// ww w .j a v a 2 s .c o m Element root, newChild; SAXBuilder builder = new SAXBuilder(); try { doc = builder.build(UtilProductor.USERS_XML_PATH); root = doc.getRootElement(); newChild = new Element(UtilProductor.SERVER_TAG); newChild.setAttribute(UtilProductor.HORA_TAG, Hora); newChild.setAttribute(UtilProductor.NOMBRE_TAG, Nombre); newChild.setAttribute(UtilProductor.CANTIDAD_TAG, Cantidad); root.addContent(newChild); try { Format format = Format.getPrettyFormat(); XMLOutputter out = new XMLOutputter(format); FileOutputStream file = new FileOutputStream(UtilProductor.USERS_XML_PATH); out.output(doc, file); file.flush(); file.close(); } catch (Exception e) { e.printStackTrace(); } } catch (JDOMParseException e) { System.out.println(UtilProductor.ERROR_XML_EMPTY_FILE); e.printStackTrace(); } catch (JDOMException e) { System.out.println(UtilProductor.ERROR_XML_PROCESSING_FILE); e.printStackTrace(); } catch (IOException e) { System.out.println(UtilProductor.ERROR_XML_PROCESSING_FILE); e.printStackTrace(); } return true; }
From source file:modelo.RegistroCitaXML.java
public void abrirArchivo() { try {/*w w w . ja v a2 s . c o m*/ SAXBuilder sAXBuilder = new SAXBuilder(); sAXBuilder.setIgnoringElementContentWhitespace(true); documento = sAXBuilder.build(ruta); raiz = documento.getRootElement(); } catch (JDOMException | IOException ex) { System.out.println("error"); } }
From source file:Modelo.RegistroEmpleado.java
private RegistroEmpleado(String path) { try {/*from ww w .j a v a 2 s .c o m*/ SAXBuilder saxb = new SAXBuilder(); saxb.setIgnoringElementContentWhitespace(true); this.document = saxb.build(path); this.path = path; this.root = document.getRootElement(); } catch (JDOMException ex) { Logger.getLogger(RegistroEmpleado.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(RegistroEmpleado.class.getName()).log(Level.SEVERE, null, ex); } }