Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

In this page you can find the example usage for org.jdom2 Element getChildText.

Prototype

public String getChildText(final String cname) 

Source Link

Document

Returns the textual content of the named child element, or null if there's no such child.

Usage

From source file:persistence.xml.ImportarContatosXML.java

private void importar() throws ClassNotFoundException, IOException, JDOMException, SQLException {
    configuraBarra();/*from  w  ww  .j  a v  a 2  s.c  o  m*/
    int i = 0;
    for (Element e : this.elementosXml) {
        pr.getProgressbar().setValue(++i);
        String nome = e.getChildText("Nome");
        String telefone = e.getChildText("Telefone");
        String uf = new IdentificaUfController(telefone).recuperaUf();
        String opera = new IdentificaOperadoraController(telefone).getOperadora();
        try {
            Pessoa p = new VerificaNonodigController(new Pessoa(nome, telefone, uf, opera))
                    .executarVerificacao();
            if (dao.add(p)) {
                if (p.getOperadora().equals("") || p.getUf().equals("")) {
                    this.incompleto++;
                } else {
                    this.sucesso++;
                }
            }
        } catch (SQLException ex) {
            log.msgFalhaImpExportacao(ex.getMessage(), user);
            Logger.getLogger(PrincipalController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    pr.dispose();
}

From source file:pl.kotcrab.jdialogue.parser.impl.JDOMDialogueParser.java

License:Apache License

@Override
public void startSequence(String name) {
    try {//from  w  w  w .j  av a2 s.  c  o  m
        SAXBuilder builder = new SAXBuilder();
        Document document;

        if (project.isGzipExport())
            document = builder
                    .build(new GZIPInputStream(new FileInputStream(new File(projectPath + name + ".xml"))));
        else
            document = builder.build(new File(projectPath + name + ".xml"));

        Element rootNode = document.getRootElement();

        elementList = rootNode.getChildren();

        Element startNode = rootNode.getChildren("dStart").get(0);
        target = Integer.valueOf(startNode.getChildText("target0"));
    } catch (JDOMException | IOException e) {
        if (e.getMessage().contains("Invalid byte 1 of 1-byte UTF-8 sequence."))
            throw new DialogueParserException("Error decoding file.");

        e.printStackTrace();
    }
}

From source file:pl.kotcrab.jdialogue.parser.impl.JDOMDialogueParser.java

License:Apache License

private Project loadProject(DialogueLoader projectFile) {
    String name = "";
    boolean gzipExport = false;
    ArrayList<PCharacter> characterList = new ArrayList<>();
    HashMap<Integer, Integer> characterMap = new HashMap<>();
    ArrayList<PCallback> callbackList = new ArrayList<>();
    HashMap<Integer, Integer> callbackMap = new HashMap<>();

    try {/*from   w  w  w  .j  av a  2 s .c o  m*/
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(projectFile.getFile());
        Element rootNode = document.getRootElement();

        name = rootNode.getChildText("name");
        gzipExport = Boolean.valueOf(rootNode.getChildText("gzipExport"));

        List<Element> characterElementList = rootNode.getChild("characterList").getChildren();
        for (Element el : characterElementList)
            characterList.add(loadCharacter(el));

        List<Element> callbackElementList = rootNode.getChild("callbackList").getChildren();
        for (Element el : callbackElementList)
            callbackList.add(loadCallback(el));

        List<Element> characterHaspMapElementList = rootNode.getChild("characterMap").getChildren();
        for (Element el : characterHaspMapElementList)
            characterMap.put(Integer.valueOf(el.getChildren().get(0).getText()),
                    Integer.valueOf(el.getChildren().get(1).getText()));

        List<Element> callbackHaspMapElementList = rootNode.getChild("callbackMap").getChildren();
        for (Element el : callbackHaspMapElementList)
            callbackMap.put(Integer.valueOf(el.getChildren().get(0).getText()),
                    Integer.valueOf(el.getChildren().get(1).getText()));

    } catch (JDOMException | IOException e) {
        throw new DialogueParserException("Chould not load project! Is your project.xml file correct?");
    }

    return new Project(name, gzipExport, characterList, characterMap, callbackList, callbackMap);
}

From source file:pl.kotcrab.jdialogue.parser.impl.JDOMDialogueParser.java

License:Apache License

private PCallback loadCallback(Element callbackElement) {
    int id = Integer.valueOf(callbackElement.getChildText("id"));
    String name = callbackElement.getChildText("name");

    return new PCallback(id, name);
}

From source file:pl.kotcrab.jdialogue.parser.impl.JDOMDialogueParser.java

License:Apache License

private PCharacter loadCharacter(Element characterElement) {
    int id = Integer.valueOf(characterElement.getChildText("id"));
    String name = characterElement.getChildText("name");
    String textureName = characterElement.getChildText("textureName");

    return new PCharacter(id, name, textureName);
}

From source file:principal.XML.java

public static void main(String[] args) {

    ConexaoBD conexao = new ConexaoBD();
    Cliente cliente = new Cliente();
    Cidade cidade = new Cidade();
    File arquivo_xml = new File("C:\\Users\\labin\\Downloads\\clientes.xml");

    if (arquivo_xml.exists()) {
        SAXBuilder sb = new SAXBuilder();
        Document d;//from   ww  w  .  jav a  2  s  .c o  m

        try {

            d = sb.build(arquivo_xml);
            Element cidades = d.getRootElement();
            List cid = cidades.getChildren();
            Iterator i = cid.iterator();
            conexao.abreConexao();

            while (i.hasNext()) {
                Element element = (Element) i.next();

                cidade.setCodigo(Integer.parseInt(element.getAttributeValue("codigo")));
                cidade.setNome(element.getAttributeValue("nome"));
                cidade.setUf(element.getAttributeValue("uf"));

                conexao.insereCidade(cidade);

                List clientes = element.getChildren();
                Iterator cli = clientes.iterator();

                while (cli.hasNext()) {
                    Element client = (Element) cli.next();

                    cliente.setMatricula(Integer.parseInt(client.getChildText("matricula")));
                    cliente.setNome(client.getChildText("nome"));
                    cliente.setData(client.getChildText("nascimento"));
                    cliente.setCodigo_cidade(Integer.parseInt(element.getAttributeValue("codigo")));

                    conexao.insereCliente(cliente);
                }
            }

        } catch (Exception e) {

        }

    }
}

From source file:prog1.WeatherReading.java

/**
 * This method reads in the data from an intermediate node that was read
 * into from an XML data file. If there are missing data elements then
 * empty values are used./*  w  w w  . j a v a 2s.co m*/
 * 
 * @param node An XML element tree from a data file.
 * @param currDayStats Stores the daily statistics.
 */
public void ReadData(Element node, DailyStats currDayStats) {
    //Get date from current reading
    String date = node.getChildText("date");
    if (date != null) {
        date = date.trim();
    }
    int firstSlash = date.indexOf("/");
    int secondSlash = date.lastIndexOf("/");
    this.month = Integer.parseInt(date.substring(0, firstSlash));
    this.day = Integer.parseInt(date.substring(firstSlash + 1, secondSlash));
    this.year = Integer.parseInt(date.substring(secondSlash + 1)) + 2000;

    //Attempt to read in time value
    try {
        this.time = node.getChildText("time").trim();

        int colon = this.time.indexOf(":");
        this.minute = Integer.parseInt(this.time.substring(colon + 1, colon + 3));
        this.hour = Integer.parseInt(this.time.substring(0, colon));

        //Adjust for 12 o'clock
        if (this.time.charAt(colon + 3) == 'P' && hour != 12)
            this.hour += 12;
        if (this.time.charAt(colon + 3) == 'A' && hour == 12)
            this.hour -= 12;
    } catch (Exception e) {
        //If failure, set time to empty string
        this.time = "";
    }

    //Attempt to read in temperature value
    try {
        this.temperature = Double.parseDouble(node.getChildText("temperature"));
    } catch (Exception e) {
        //If failure, set temperature to invalid number
        this.temperature = INVALID_DATA;
    }

    //Attempt to read in humidity value
    try {
        this.humidity = Double.parseDouble(node.getChildText("humidity"));
    } catch (Exception e) {
        //If failure, set humidity to invalid number
        this.humidity = INVALID_DATA;
    }

    //Attempt to read in barometer value
    try {
        this.barometer = Double.parseDouble(node.getChildText("barometer"));
    } catch (Exception e) {
        //If failure, set barometer to invalid number
        this.barometer = INVALID_DATA;
    }

    //Attempt to read in windSpeed value
    try {
        this.windSpeed = Double.parseDouble(node.getChildText("windspeed"));
    } catch (Exception e) {
        //If failure, set windSpeed to invalid number
        this.windSpeed = INVALID_DATA;
    }

    //Attempt to read in windDirection value
    try {
        this.windDirection = node.getChildText("winddirection").trim();
    } catch (Exception e) {
        //If failure, set windDirection to empty string
        this.windDirection = "";
    }

    //Attempt to read in windGust value
    try {
        this.windGust = Double.parseDouble(node.getChildText("windgust"));
    } catch (Exception e) {
        //If failure, set windGust to invalid number
        this.windGust = INVALID_DATA;
    }

    //Attempt to read in windChill value
    try {
        this.windChill = Double.parseDouble(node.getChildText("windchill"));
    } catch (Exception e) {
        //If failure, set windChill to invalid number
        this.windChill = INVALID_DATA;
    }

    //Attempt to read in heatIndex value
    try {
        this.heatIndex = Double.parseDouble(node.getChildText("heatindex"));
    } catch (Exception e) {
        //If failure, set heatIndex to invalid number
        this.heatIndex = INVALID_DATA;
    }

    //Attempt to read in uvIndex value
    try {
        this.uvIndex = Double.parseDouble(node.getChildText("uvindex"));
    } catch (Exception e) {
        //If failure, set uvIndex to invalid number
        this.uvIndex = INVALID_DATA;
    }

    //Attempt to read in rainFall value
    try {
        this.rainFall = Double.parseDouble(node.getChildText("rainfall"));
    } catch (Exception e) {
        //If failure, set rainFall to invalid number
        this.rainFall = INVALID_DATA;
    }
}

From source file:rezeptsuperpos.Ingredient.java

License:Open Source License

public Ingredient(Element element) {
    this.name = element.getChildText("name");
    this.alias = MyElement.tryGetList(element, "alias", this);
    this.density = MyElement.tryGetDouble(element, "density");
    this.calSpec = MyElement.tryGetDouble(element, "calSpec");
    this.fatSpec = MyElement.tryGetDouble(element, "fatSpec");
    this.carbSpec = MyElement.tryGetDouble(element, "carbSpec");
    this.protSpec = MyElement.tryGetDouble(element, "protSpec");
    this.measure = MyElement.tryGetDouble(element, "measure");
    this.measureInGram = MyElement.tryGetDouble(element, "measure_in_gram");
    this.measureUnit = MyElement.tryGetString(element, "measureUnit");
    this.weightPerPiece = MyElement.tryGetDouble(element, "weightPerPiece");
    if (weightPerPiece > 0) {
        Convert.setSpecialUnit(name, weightPerPiece);
        for (String aliasName : alias)
            Convert.setSpecialUnit(aliasName.trim(), weightPerPiece);
    }//from w  w  w  .  j  a v  a  2  s  .co m
}

From source file:rezeptsuperpos.JDom.java

License:Open Source License

public void listElements(Element topElement, String listName, String[] listElemName) {

    List<Element> list = topElement.getChildren(listName);
    for (int i = 0; i < list.size(); i++) {
        System.out.println("SubElement " + i);
        Element node = (Element) list.get(i);
        for (String nodeChildName : listElemName) {
            System.out.println("nodeChildName : " + node.getChildText(nodeChildName));
        }//from ww  w .  j  ava 2s.  co m
    }

}

From source file:rezeptsuperpos.MyElement.java

License:Open Source License

public static String tryGetString(Element element, String attrName) {
    String retVal = "";
    try {//from w w w .  j a va 2  s. c  om
        retVal = element.getChildText(attrName);
    } catch (Exception ex) {
        //ignore, return zero
    }
    return retVal;
}