Example usage for org.jdom2.input SAXBuilder build

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

Introduction

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

Prototype

@Override
public Document build(final String systemId) throws JDOMException, IOException 

Source Link

Document

This builds a document from the supplied URI.

Usage

From source file:io.wcm.maven.plugins.i18n.readers.XmlI18nReader.java

License:Apache License

@Override
public Map<String, String> read(File sourceFile) throws IOException {
    try {/* ww  w  . ja  v  a2s  .c  om*/
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(sourceFile);
        Map<String, String> map = new HashMap<String, String>();
        parseXml(doc.getRootElement(), map, "");
        return map;
    } catch (JDOMException ex) {
        throw new IOException("Unable to read XML from " + sourceFile.getAbsolutePath(), ex);
    }
}

From source file:isjexecact.AppSettings.java

/** 
  * Carrega os valores do arquivo de configurao para AppSeting ambiente.
  */*from  w w w .  j a va  2  s.  co  m*/
  * @throws org.jdom2.JDOMException
  * @throws java.io.IOException
  */

public void loadDefaultSetings() throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    //Document doc = builder.build("c:/TMPGED/teste.xml");
    Document doc = builder.build(appFileName);

    Element xmllei = doc.getRootElement();
    List<Element> lista = xmllei.getChildren();

    for (Element e : lista) {
        setValue(e.getAttributeValue("id"), e.getChildText("valor"));
        //              System.out.println("Chave: "+ e.getAttributeValue("id"));
        //              System.out.println("Valor: " + e.getChildText("valor"));        
    }

}

From source file:it.cnr.ilc.clavius.controller.ProofReaderController.java

public void loadLetter() {
    String token, lemma, morpho, sentence = "";
    res.clear();/*www . j a va  2s .  c o  m*/
    InputStream currLetterStream = null;
    SAXBuilder builder = new SAXBuilder();
    setCurrSentence("");
    setDis(true);

    try {
        currLetterStream = new FileInputStream(
                HandleConstants.getWorkDir() + "Letter" + HandleConstants.getLetterRif() + "_anOUT.xml");
        Document document = (Document) builder.build(currLetterStream);
        getDocumentTei().setAnalysis(document);
        Element rootNode = document.getRootElement();
        List sentenceList = rootNode.getChildren("sentence");
        setCurrLetterSize(sentenceList.size());
        Element sentenceNode = (Element) sentenceList.get(0);
        setCurrSentenceNumber(0);
        List tokenList = sentenceNode.getChildren("token");
        for (int i = 0; i < tokenList.size(); i++) {
            Element tokenNode = (Element) tokenList.get(i);
            token = tokenNode.getAttributeValue("form");
            lemma = tokenNode.getAttributeValue("lemma");
            morpho = tokenNode.getAttributeValue("morphoCode");
            sentence = sentence + " " + token;
            setMorphoElement(token, lemma, morpho);
        }
        setCurrSentence(sentence);
        setCountsentence("1/" + getCurrLetterSize());
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    } finally {
        try {
            currLetterStream.close();
        } catch (IOException ioe) {
            System.out.println(ioe.getMessage());
        }

    }
}

From source file:it.intecs.pisa.openCatalogue.openSearch.OpenSearchHandler.java

License:Open Source License

private ArrayList prepareDataForVelocity(String id) throws XPathFactoryConfigurationException, XPathException,
        XPathExpressionException, IOException, SAXException, JDOMException {
    ArrayList metadataList = new ArrayList();
    SAXBuilder builder;
    org.jdom2.Document root = null;
    Map metadata = new HashMap();
    builder = new SAXBuilder();
    root = builder.build(this.repository.getAbsolutePath() + "/" + id + ".xml");

    metadata.put(METADATA_DOCUMENT, root);
    metadata.put(IDENTIFIER, id);/*from   ww w. j ava2  s .co m*/
    // load the metadata and add it to the array
    metadataList.add(metadata);
    return metadataList;
}

From source file:it.intecs.pisa.openCatalogue.solr.ingester.Ingester.java

@Override
public void setConfiguration(AbstractFilesystem configDirectory)
        throws SAXException, IOException, SaxonApiException, Exception {
    super.setConfiguration(configDirectory);

    configDocument = new SaxonDocument(configDirectory.get(configuration).getInputStream());

    sensorType = (!"".equals((String) configDocument
            .evaluatePath(XPATH_SENSOR_TYPE + SLASH + TAG_INDEX_FIELD_NAME, XPathConstants.STRING))
                    ? (DOLLAR + (String) configDocument.evaluatePath(
                            XPATH_SENSOR_TYPE + SLASH + TAG_INDEX_FIELD_NAME, XPathConstants.STRING))
                    : (String) configDocument.evaluatePath(XPATH_SENSOR_TYPE + SLASH + TAG_DEFAULT_VALUE,
                            XPathConstants.STRING));

    dateTimeFormat = !""
            .equals((String) configDocument.evaluatePath(XPATH_DATE_TIME_FORMAT, XPathConstants.STRING))
                    ? ((String) configDocument.evaluatePath(XPATH_DATE_TIME_FORMAT, XPathConstants.STRING))
                    : DEFAULT_DATE_TIME_FORMAT;

    elements_separator = (String) configDocument.evaluatePath(XPATH_SEPARATOR, XPathConstants.STRING);

    SAXBuilder saxBuilder = new SAXBuilder();
    org.jdom2.Document doc = saxBuilder.build(configDirectory.get(configuration).getInputStream());

    Element rootElement = doc.getRootElement();
    defaultMap = new HashMap();
    generateDefaultMap(rootElement, defaultMap);
}

From source file:it.intecs.pisa.openCatalogue.solr.ingester.Ingester.java

protected org.jdom2.Document generateMetadata(Map metadataMap, String key, HashMap<String, String> queryHeaders)
        throws IOException, SaxonApiException, XPathFactoryConfigurationException, JDOMException {
    //debug/*from  ww w . j  a v a 2 s .c  o m*/
    /*        List<String> keys = new ArrayList<String>(metadataMap.keySet());
            Collections.sort(keys);
            for (String keyString: keys) {
    System.out.println(keyString + ": " + metadataMap.get(keyString));
            }*/
    //debug

    VelocityContext context = new VelocityContext();
    context.put(VELOCITY_DATE, new DateTool());
    context.put(VELOCITY_METADATA_LIST, metadataMap);
    context.put("coordinates", new CoordinatesUtil());
    context.put(VELOCITY_PERIOD_START, this.period_start);
    context.put(VELOCITY_PERIOD_END, this.period_end);
    context.put("KEY", key);

    if (queryHeaders != null) {
        context.put("queryValues", queryHeaders);
    }
    StringWriter swOut = new StringWriter();
    String sType = sensorType.startsWith(DOLLAR) ? ((String) metadataMap.get(sensorType.substring(1)))
            : sensorType;
    getTemplate(sType).merge(context, swOut);

    SAXBuilder builder;
    builder = new SAXBuilder();
    org.jdom2.Document metadata = builder.build(new ByteArrayInputStream(swOut.toString().getBytes()));

    //SaxonDocument metadata = new SaxonDocument(swOut.toString());
    swOut.close();
    return metadata;
}

From source file:it.intecs.pisa.openCatalogue.solr.ingester.OEMIngester.java

@Override
protected Document[] parse(AbstractFilesystem indexFile, HashMap<String, String> queryHeaders) {
    try {//from   w  w w  .  jav  a  2 s  .  com
        SAXBuilder builder = new SAXBuilder();

        Document document = builder.build(indexFile.getInputStream());

        return new Document[] { document };
    } catch (Exception e) {
        return new Document[0];
    }
}

From source file:javaapplication1.LeerXml.java

public void cargarXml() {
    //Se crea un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File("archivo.xml");
    try {//from  w  w  w . j  a  va  2 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("dimension");
        List list_dobles = rootNode.getChildren("dobles");
        List list_triples = rootNode.getChildren("triples");
        List list_diccionario = rootNode.getChildren("diccionario");
        //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);
            System.out.println("Dimension: " + tabla.getText());
            dimension = Integer.parseInt(tabla.getText());
            m = new Matriz(dimension, dimension);
        }
        for (int i = 0; i < list_dobles.size(); i++) {
            //Se obtiene el elemento 'tabla'
            Element tabla = (Element) list_dobles.get(i);
            //Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
            //String nombreTabla = tabla.getAttributeValue("nombre");

            //System.out.println("Tabla: " + nombreTabla);
            //Se obtiene la lista de hijos del tag 'tabla'
            List lista_campos = tabla.getChildren();

            //System.out.println("\tNombre\t\tTipo\t\tValor");
            //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 x = campo.getChildTextTrim("x");

                //Se obtiene el valor que esta entre los tags '<tipo></tipo>'
                String y = campo.getChildTextTrim("y");
                m.item(Integer.parseInt(x) - 1, Integer.parseInt(y) - 1).datos = 2;
                System.out.println("Puntos Dobles en la posicion X:" + x + " Y: " + y);
            }
        }
        for (int i = 0; i < list_triples.size(); i++) {
            //Se obtiene el elemento 'tabla'
            Element tabla = (Element) list_triples.get(i);
            //Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
            //String nombreTabla = tabla.getAttributeValue("nombre");

            //System.out.println("Tabla: " + nombreTabla);
            //Se obtiene la lista de hijos del tag 'tabla'
            List lista_campos = tabla.getChildren();

            //System.out.println("\tNombre\t\tTipo\t\tValor");
            //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 x = campo.getChildTextTrim("x");

                //Se obtiene el valor que esta entre los tags '<tipo></tipo>'
                String y = campo.getChildTextTrim("y");
                m.item(Integer.parseInt(x) - 1, Integer.parseInt(y) - 1).datos = 3;
                System.out.println("Puntos Triples en la posicion X:" + x + " Y: " + y);
            }
        }

        for (int i = 0; i < list_diccionario.size(); i++) {
            //Se obtiene el elemento 'tabla'
            Element tabla = (Element) list_diccionario.get(i);
            //Se obtiene el atributo 'nombre' que esta en el tag 'tabla'
            //String nombreTabla = tabla.getAttributeValue("nombre");

            //System.out.println("Tabla: " + nombreTabla);
            //Se obtiene la lista de hijos del tag 'tabla'
            List lista_campos = tabla.getChildren();

            //System.out.println("\tNombre\t\tTipo\t\tValor");
            //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);
                System.out.println("Palabra: " + campo.getText() + " tamano lista " + diccionario.getsize());
                diccionario.insertarAlFinal(campo.getText());
            }
        }
    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    }
}

From source file:javaapplication5.JavaApplication5.java

public static Boolean checkRemitente(String from) throws JDOMException, IOException {
    boolean resultado = false;
    //Se crea un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();
    //Traigo el XML de remitentes validos
    File xmlFile = new File(
            "C:\\Users\\Matias\\Documents\\NetBeansProjects\\Repo\\JavaApplication5\\src\\javaapplication5\\remitentes.xml");

    //Se crea el documento a traves del archivo
    Document document = (Document) builder.build(xmlFile);

    //Se obtiene la raiz 'remitentes'
    Element rootNode = document.getRootElement();

    //Se obtiene la lista de hijos de la raiz 'remitentes'
    List list = rootNode.getChildren();

    //Se recorre la lista de hijos de 'remitentes'
    for (int i = 0; i < list.size(); i++) {
        //por cada remitente
        Element remitente = (Element) list.get(i);
        String rem = remitente.getText();
        //si el remitente q me vino del mail esta en el XML pone en true la variable resultado
        if (from.equals(rem)) {
            resultado = true;//from   w  w w  . j av a 2 s  . c o  m
            return (resultado);

        }
    }
    return resultado;
}

From source file:jcodecollector.io.PackageManager.java

License:Apache License

public static ArrayList<Snippet> readPackage(File file) {
    ArrayList<Snippet> array = new ArrayList<Snippet>();
    Element root = null;/*from  w  w  w  .  ja va 2  s.c  o m*/

    try {
        SAXBuilder builder = new SAXBuilder();
        root = builder.build(file).getRootElement();
    } catch (Exception ex) {
        return null;
    }

    @SuppressWarnings("unchecked")
    Iterator<Element> iterator = root.getChildren("snippet").iterator();
    while (iterator.hasNext()) {
        Element e = iterator.next();

        String category = e.getChildTextTrim("category");
        String name = e.getChildTextTrim("name");
        String syntax = e.getChildTextTrim("syntax");
        String code = e.getChildTextTrim("code");
        String comment = e.getChildTextTrim("comment");

        @SuppressWarnings("unchecked")
        List<Element> tagElements = e.getChildren("tag");
        String[] tags = new String[tagElements.size()];
        for (int i = 0; i < tags.length; i++) {
            tags[i] = tagElements.get(i).getTextTrim();
        }

        Snippet snippet = new Snippet(-1, category, name, tags, code, comment, syntax, false);
        array.add(snippet);
    }

    return array;
}