Example usage for org.jdom2.input SAXBuilder SAXBuilder

List of usage examples for org.jdom2.input SAXBuilder SAXBuilder

Introduction

In this page you can find the example usage for org.jdom2.input SAXBuilder SAXBuilder.

Prototype

public SAXBuilder() 

Source Link

Document

Creates a new JAXP-based SAXBuilder.

Usage

From source file:Contabilidad.QUALITAS.java

private void b_xmlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_xmlActionPerformed
    // TODO add your handling code here:
    if (t_folio_factura.getText().compareTo("") != 0 && t_uuid_factura.getText().compareTo("") != 0) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {//from w ww .j a va2  s.  c  om
            session.beginTransaction().begin();
            String ruta = "";
            try {
                ruta = "";
                FileReader f = new FileReader("config.txt");
                BufferedReader b = new BufferedReader(f);
                if ((ruta = b.readLine()) == null)
                    ruta = "";
                b.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            Configuracion config = (Configuracion) session.get(Configuracion.class, 1);
            if (t_xml.getText().compareTo("") == 0)
                t_xml.setText(config.getRfc() + "_" + t_serie_factura.getText() + "_"
                        + t_folio_factura.getText() + "_" + t_rfc.getText() + ".xml");
            File xml = new File(ruta + "xml-timbrados/" + t_xml.getText());
            if (xml.exists())//existe en nuestro directorio
            {
                org.jdom2.Document documentJDOM = new SAXBuilder()
                        .build(ruta + "xml-timbrados/" + t_xml.getText());
                XPathExpression<org.jdom2.Element> xPathExpression = XPathFactory.instance()
                        .compile("/hibernate-configuration/session-factory/property", Filters.element());
                documentJDOM.getContent().remove("documentJDOM");

                Desktop.getDesktop().open(xml);
            } else//descargar el archivo del SAP
            {
                factura = (Factura) session.get(Factura.class, factura.getIdFactura());
                RequestTransaction rq = new RequestTransaction();
                rq.setRequestor(config.getRequestor());//Lo proporcionar MySuite
                rq.setTransaction("GET_DOCUMENT");//Tipo de Transaccion
                rq.setCountry("MX");//Codigo de pais
                rq.setUser(config.getRequestor());//igual que Requestor
                rq.setUserName(config.getUsuario_1());//Country.Entity.nombre_usuario
                rq.setEntity(config.getRfc());
                rq.setData1(t_serie_factura.getText());//serie del documento.
                rq.setData2(t_folio_factura.getText());//folio
                rq.setData3("PDF XML");//documentos
                abrir = "xml";
                llamarSoapDocumento(rq);
            }
        } catch (Exception e) {
            if (session != null)
                if (session.isConnected())
                    session.close();
            JOptionPane.showMessageDialog(null, "Error al consultar la base de datos");
        } finally {
            if (session != null)
                if (session.isOpen())
                    session.close();
        }
    } else {
        JOptionPane.showMessageDialog(null,
                "Debes generar comprobante primero para tratar de recuperar los datos del SAP");
    }
}

From source file:controller.MobilePartnerController.java

public Map<String, Object> getConfiguredOverrides() throws Exception {

    Map<String, Object> configOverrides = new HashMap<>();
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File(DIR + "\\dbconf.xml");
    Document document = (Document) builder.build(xmlFile);
    Element rootNode = document.getRootElement();

    List<Element> list = rootNode.getChildren();

    for (Element element : list) {
        configOverrides.put(element.getAttributeValue("name"), element.getText());
    }//from  www  .  j  av  a2  s .c o  m

    return configOverrides;
}

From source file:converter.ConverterBean.java

private void init() throws MalformedURLException, JDOMException, IOException {
    if (isInit) {
        return;/*from w  w  w.  ja  v  a 2s  .c  o m*/
    }
    this.isInit = true;

    SAXBuilder sxb = new SAXBuilder();

    {
        URL url = new URL("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
        Document document = sxb.build(url);
        racine = document.getRootElement();
        Namespace ns = Namespace.getNamespace("http://www.ecb.int/vocabulary/2002-08-01/eurofxref");
        racine = racine.getChild("Cube", ns);
        racine = racine.getChild("Cube", ns);
    }

    {
        URL url = new URL("http://www.currency-iso.org/dam/downloads/lists/list_one.xml");
        Document document = sxb.build(url);
        racineMore = document.getRootElement();
        racineMore = racineMore.getChild("CcyTbl");
    }
}

From source file:core.ComponenXml.java

public ComponenXml() {
    this.builder = new SAXBuilder();
    this.file = null;
    this.document = null;
    this.rootNode = null;
    xml = new Xml();
}

From source file:core.ComponenXml.java

public ComponenXml(File f) {
    this.builder = new SAXBuilder();
    this.file = f;
    this.document = null;
    this.rootNode = null;
    xml = new Xml();
}

From source file:core.ValidXml.java

@Override
public boolean validEstructura(File xml_file) {
    try {//from   w  w w.j  a  v  a  2  s  .  c o m
        SAXBuilder builder = new SAXBuilder();
        Document document = (Document) builder.build(xml_file);
        Element rootNode = document.getRootElement();
        List list = (List) rootNode.getChildren();
        Xml xml = new Xml();
        for (Object object : list) {
            Element ob = (Element) object;
            System.out.println(ob.getName());
            if (ob.getName().equalsIgnoreCase("autor")) {
                try {
                    xml.getAutor().setNombre(ob.getChild("nombre").getText());
                } catch (NullPointerException r) {
                    xml.getAutor().setNombre("");
                }
                try {
                    xml.getAutor().setDescripcion(ob.getChild("descripcion").getText());
                } catch (NullPointerException r) {
                    xml.getAutor().setDescripcion("");
                }
                try {
                    xml.getAutor().setVersion(ob.getChild("version").getText());
                } catch (NullPointerException r) {
                    xml.getAutor().setVersion("");
                }
            } else if (ob.getName().equalsIgnoreCase("cuerpo")) {
                try {
                    Element tipo = ob.getChild("tipo");
                    xml.getCuerpo().setColumnas(Integer.parseInt(tipo.getAttribute("columnas").getValue()));
                    xml.getCuerpo().setTipo_datos(tipo.getAttribute("tipodatocolumna").getValue().split(","));
                } catch (NullPointerException r) {
                    xml.getCuerpo().setColumnas(0);
                    xml.getCuerpo().setTipo_datos(new String[] {});
                } catch (NumberFormatException n) {
                    xml.getCuerpo().setColumnas(0);
                    xml.getCuerpo().setTipo_datos(new String[] {});
                }
                try {
                    Element tipo = ob.getChild("claseprincipal");
                    xml.getCuerpo().setMain(ob.getChild("claseprincipal").getValue());
                } catch (NullPointerException r) {
                    xml.getCuerpo().setMain("");
                }
                ArrayList<String> parametros = new ArrayList<>();
                try {
                    System.out.println("***************  " + ob.getChild("parametro"));
                    Element param = ob.getChild("parametro");
                    for (Element e : param.getChildren()) {
                        System.out.println(e.getName());
                        try {
                            System.out.println(e.getName());
                            parametros.add(e.getName());
                        } catch (NullPointerException r) {
                            System.err.println("Se exploto");
                        }
                    }
                } catch (NullPointerException r) {

                } finally {
                    xml.getCuerpo().setParametros(parametros);
                }
            }

        }
        boolean respuesta = true;
        if (!xml.getAutor().getNombre().equals("")) {
            return false;
        } else if (xml.getCuerpo().getTipo_datos().length == 0) {
            return false;
        } else if (xml.getCuerpo().getParametros().size() == 0) {
            return false;
        }
    } catch (JDOMException ex) {
        Logger.getLogger(ValidXml.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ValidXml.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
    }
    return true;
}

From source file:core.xml.java

/**
 * @param args the command line arguments
 *///from   w  w  w .  j  av a2 s .  c  o  m
public static void main(String[] args) throws JDOMException {
    // TODO code application logic here
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File("/home/dark/Escritorio/Desde-Java/estructura.xml");
    System.err.println(xmlFile);
    System.err.println(xmlFile.exists());
    try {
        Document document = (Document) builder.build(xmlFile);
        Element rootNode = document.getRootElement();
        List list = (List) rootNode.getChildren("configuracion");
        extraerInformacion(list);
        System.err.println(descripcion);
        System.err.println(atributos);
        System.out.println(num_columnas);
        System.err.println(parametros);
        System.err.println(cabecera);

    } catch (IOException io) {
        System.err.println("Se exploto 1");
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.err.println("Se exploto 2");
        System.out.println(jdomex.getMessage());
    }
}

From source file:count_dep.AlanRitter.java

public void ACE2Alan() throws JDOMException, IOException {
    Properties props = new Properties();
    props.put("annotators", "tokenize, ssplit");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    File corpus = new File("D:\\LDC2006D06\\LDC2006D06\\Data\\LDC2006T06_Original\\data\\English\\nw\\fp1");
    File[] listFiles = corpus.listFiles();
    for (File f : listFiles) {
        if (f.getName().endsWith(".sgm")) {
            PrintStream ps = new PrintStream(new FileOutputStream("D:\\ACEAlan\\" + f.getName()));
            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(f);
            Element foo = doc.getRootElement();
            String text = foo.getChild("BODY").getChild("TEXT").getText();
            Annotation document = new Annotation(text);
            pipeline.annotate(document);
            List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
            for (CoreMap cm : sentences) {
                String str = cm.toString();
                String str2 = str.replace('\n', ' ');
                ps.println(str2);//from ww w  . j  a  v a  2 s  .c o m
            }
            ps.close();
        }
    }

}

From source file:count_dep.CountParagraph.java

public static LinkedList<String> GetSentences(File documentfile, StanfordCoreNLP pipeline)
        throws JDOMException, IOException {
    LinkedList<String> sentencelist = new LinkedList<>();
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(documentfile);
    Element foo = doc.getRootElement();
    String text = foo.getChild("BODY").getChild("TEXT").getText();
    int titleend = text.indexOf("\n\n");
    text = text.substring(titleend + 1).replace("\n\n", ".  ");

    Annotation document = new Annotation(text);

    // run all Annotators on this text
    pipeline.annotate(document);//w w  w  .j  a v  a2s. c o  m

    // these are all the sentences in this document
    // a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);

    for (CoreMap cm : sentences) {
        sentencelist.add(cm.toString());
    }

    return sentencelist;
}

From source file:count_dep.CountParagraph.java

private LinkedList<String> GetParagraphs(File documentfile) throws JDOMException, IOException {
    LinkedList<String> paralist = new LinkedList<>();
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(documentfile);
    Element foo = doc.getRootElement();
    String text = foo.getChild("BODY").getChild("TEXT").getText();
    String[] split = text.split("\n\n");
    for (int i = 0; i < split.length; i++) {
        paralist.add(split[i]);//from  w  w w.j a  v  a2s  . c o  m
    }
    return paralist;
}