Example usage for org.jdom2 Element getName

List of usage examples for org.jdom2 Element getName

Introduction

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

Prototype

public String getName() 

Source Link

Document

Returns the (local) name of the element (without any namespace prefix).

Usage

From source file:com.thoughtworks.go.config.parser.GoConfigClassLoader.java

License:Apache License

public static boolean compare(Element e, Class<?> implementation, ConfigCache configCache) {
    final AttributeAwareConfigTag attributeAwareConfigTag = annotationFor(implementation,
            AttributeAwareConfigTag.class);

    if (attributeAwareConfigTag != null) {
        return compareAttributeAwareConfigTag(e, attributeAwareConfigTag);
    }//  www.  ja  v  a2  s . com

    ConfigTag configTag = configTag(implementation, configCache);
    return configTag.value().equals(e.getName()) && e.getNamespace().getURI().equals(configTag.namespaceURI());
}

From source file:com.thoughtworks.go.config.parser.GoConfigClassLoader.java

License:Apache License

private static boolean compareAttributeAwareConfigTag(Element e,
        AttributeAwareConfigTag attributeAwareConfigTag) {
    return attributeAwareConfigTag.value().equals(e.getName())
            && attributeAwareConfigTag.attributeValue()
                    .equals(e.getAttributeValue(attributeAwareConfigTag.attribute()))
            && e.getNamespace().getURI().equals(attributeAwareConfigTag.namespaceURI());
}

From source file:com.thoughtworks.go.util.ConfigUtil.java

License:Apache License

public boolean atTag(Element e, String tag) {
    return e.getName().equals(tag);
}

From source file:com.ucuenca.dao.BaseXMLDao.java

public Table getTable() throws MalformedURLException, JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    URL url = new URL(path);
    InputStream stream = url.openStream();
    Document document = null;//from   ww  w.j  a v a2 s  .co m
    try {
        document = builder.build(stream);
    } catch (JDOMException e) {

    }
    Table table = new Table_Excel();
    // Get Root Element and name
    Element root = document.getRootElement();
    String rootName = root.getName();

    // Get Second Level Elements, the rows of the data table
    List<Element> items = root.getChildren();

    // Get column names, using the first element
    List<Element> firstItem = items.get(0).getChildren();
    List<Column> columns = new ArrayList<Column>();
    for (Element col : firstItem) {
        Column column = new Column();
        column.setTitle(col.getName());
        column.setStorageFormat(formatColumn(""));//pendiente
        columns.add(column);
    }
    //         Get data and identify type data
    //        for (Element item : items) {
    //            ArrayList<String> row = new ArrayList<String>();
    //            for (Element col : item.getChildren()) {
    //                row.add(col.getText());
    //            }
    //          
    //        }
    return table;
}

From source file:com.webfront.app.utils.PDFImporter.java

public void processSection(Element section) throws ElementNotFoundException {
    String name = section.getName();
    boolean hasEntry = false;
    String contentDesc = (section.getAttribute("content") == null ? "" : section.getAttributeValue("content"));
    int lines = 1;
    int maxLines = 0;
    int linesProcessed = 0;
    boolean endHasBounds = true;
    Element startElement = section.getChild("start");
    Element endElement = section.getChild("end");
    Element dataDefinition = section.getChild("data");
    Element lineDefinition = section.getChild("line");
    Pattern dataPattern = null;//from  w  w w . ja va 2s.  c  o m
    Pattern linePattern = null;
    String transType = (section.getAttribute("type") == null ? "info" : section.getAttributeValue("type"));
    String prevLine = "";
    int nextSection = buffer.size() - 1;
    if (sectionMarks.higher(currentLine) != null) {
        nextSection = (int) sectionMarks.higher(currentLine);
    }

    if (startElement.getAttributeValue("lines") != null) {
        lines = Integer.parseInt(startElement.getAttributeValue("lines"));
        currentLine += lines;
    }
    if (lineDefinition != null) {
        linePattern = Pattern.compile(lineDefinition.getText());
        if (lineDefinition.getAttribute("lines") != null) {
            String l = lineDefinition.getAttributeValue("lines");
            if (!l.equals("+")) {
                maxLines = Integer.parseInt(lineDefinition.getAttributeValue("lines"));
            }
        }
    }
    if (endElement.getAttribute("bounded") != null) {
        String bounds = endElement.getAttributeValue("bounded");
        if (bounds.equals("false")) {
            endHasBounds = false;
        }
    }
    Pattern endPattern = Pattern.compile(endElement.getText());
    while (currentLine < nextSection) {
        prevLine = buffer.get(currentLine - 1);
        String text = buffer.get(currentLine++);
        Matcher lineMatcher = null;
        if (lineDefinition != null) {
            lineMatcher = linePattern.matcher(text);
        }
        Matcher endMatcher = endPattern.matcher(text);
        if (endMatcher.matches()) {
            if (!endHasBounds) {
                currentLine -= 1;
            }
            break;
        } else {
            if (currentLine >= buffer.size()) {
                throw new ElementNotFoundException("Not found");
            }
        }
        if (lineMatcher != null && lineMatcher.matches()) {
            if (!contentDesc.equals("discard")) {
                //                    System.out.println(text);
            }
            hasEntry = false;
            if (dataDefinition != null) {
                LedgerEntry entry = new LedgerEntry();
                for (Element dataLine : dataDefinition.getChildren()) {
                    String tag = dataLine.getAttributeValue("content");
                    String regex = dataLine.getText();
                    Matcher matcher = Pattern.compile(regex).matcher(text);
                    String value = "";
                    if (matcher.find()) {
                        value = matcher.group();
                    }
                    switch (tag) {
                    case "beginningBalance":
                        beginningBalance = Float.parseFloat(value.replaceAll(",", ""));
                        break;
                    case "totalDeposits":
                        value.replaceAll(",", "");
                        totalDeposits = Float.parseFloat(value.replaceAll(",", ""));
                        break;
                    case "totalWithdrawals":
                        value.replaceAll(",", "");
                        totalWithdrawals = Float.parseFloat(value.replaceAll(",", ""));
                        break;
                    case "endingBalance":
                        value.replaceAll(",", "");
                        endingBalance = Float.parseFloat(value.replaceAll(",", ""));
                        break;
                    case "accountNumber":
                        summary.put("accountNumber", value);
                        break;
                    case "periodFrom":
                        summary.put("startDate", value);
                        break;
                    case "periodTo":
                        summary.put("endDate", value);
                        break;
                    case "date":
                        entry.setDate(value);
                        text = matcher.replaceFirst("");
                        break;
                    case "check":
                        entry.setCheckNumber(value);
                        break;
                    case "amount":
                        if (transType.equals("debit")) {
                            value = "-" + value;
                        }
                        entry.setAmount(value);
                        text = matcher.replaceFirst("");
                        if (section.getAttributeValue("content").equals("fees")) {
                            String amt = entry.getAmount();
                            amt = amt.replaceAll("-", "");
                            amt = amt.replaceAll(",", "");
                            totalFees += Float.parseFloat(amt);
                        }
                        break;
                    case "description":
                        entry.setDescription(value);
                        break;
                    }
                }
                if (maxLines > 0 && ++linesProcessed == maxLines) {
                    return;
                }
                if (!contentDesc.equals("dailyBalance") && !contentDesc.endsWith("Info")) {
                    entries.add(entry);
                    hasEntry = true;
                }
            }
        } else {
            if (linePattern.matcher(prevLine).matches() && hasEntry) {
                if (!contentDesc.equals("dailyBalance")) {
                    int lastEntry = entries.size() - 1;
                    LedgerEntry entry = entries.get(lastEntry);
                    entry.setDescription(entry.getDescription() + " " + text);
                    entries.set(lastEntry, entry);
                    hasEntry = false;
                }
            }
        }

    }
}

From source file:Contabilidad.CodeBase64.java

public void limpia(String ruta) {
    try {/*from  w ww  .  j  av  a2s .  c o m*/
        org.jdom2.Document doc = new SAXBuilder().build(ruta);
        Element rootNode = doc.getRootElement();
        List list = rootNode.getContent();
        for (int i = 0; i < list.size(); i++) {
            Content elementos = (Content) list.get(i);
            if (elementos.getCType() == Content.CType.Element) {
                Element aux = (Element) elementos;
                if (aux.getName().compareToIgnoreCase("Addenda") == 0) {
                    List list2 = aux.getContent();
                    for (int j = 0; j < list2.size(); j++) {
                        Content elementos2 = (Content) list2.get(j);
                        if (elementos2.getCType() == Content.CType.Element) {
                            Element aux2 = (Element) elementos2;
                            if (aux2.getName().compareToIgnoreCase("FactDocMX") == 0) {
                                list2.remove(aux2);
                            }
                            if (aux2.getName().compareToIgnoreCase("ECFD") == 0) {
                                Namespace NP = Namespace.getNamespace("", "");
                                aux2.setNamespace(NP);
                                List list3 = aux2.getContent();
                                for (int k = 0; k < list3.size(); k++) {
                                    Content elementos3 = (Content) list3.get(k);
                                    if (elementos3.getCType() == Content.CType.Element) {
                                        Element aux3 = (Element) elementos3;
                                        aux3.setNamespace(NP);
                                        List list4 = aux3.getContent();
                                        for (int l = 0; l < list4.size(); l++) {
                                            Content elementos4 = (Content) list4.get(l);
                                            if (elementos4.getCType() == Content.CType.Element) {
                                                Element aux4 = (Element) elementos4;
                                                aux4.setNamespace(NP);
                                                List list5 = aux4.getContent();
                                                for (int m = 0; m < list5.size(); m++) {
                                                    Content elementos5 = (Content) list5.get(m);
                                                    if (elementos5.getCType() == Content.CType.Element) {
                                                        Element aux5 = (Element) elementos5;
                                                        aux5.setNamespace(NP);
                                                        List list6 = aux5.getContent();
                                                        for (int n = 0; n < list6.size(); n++) {
                                                            Content elementos6 = (Content) list6.get(n);
                                                            if (elementos6
                                                                    .getCType() == Content.CType.Element) {
                                                                Element aux6 = (Element) elementos6;
                                                                aux6.setNamespace(NP);
                                                                List list7 = aux6.getContent();
                                                                for (int p = 0; p < list7.size(); p++) {
                                                                    Content elementos7 = (Content) list7.get(p);
                                                                    if (elementos7
                                                                            .getCType() == Content.CType.Element) {
                                                                        Element aux7 = (Element) elementos7;
                                                                        aux7.setNamespace(NP);
                                                                        List list8 = aux7.getContent();
                                                                        for (int q = 0; q < list8.size(); q++) {
                                                                            Content elementos8 = (Content) list8
                                                                                    .get(q);
                                                                            if (elementos8
                                                                                    .getCType() == Content.CType.Element) {
                                                                                Element aux8 = (Element) elementos8;
                                                                                aux8.setNamespace(NP);
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                List atributos = aux2.getAttributes();
                                for (int a = 0; a < atributos.size(); a++) {
                                    Attribute at = (Attribute) atributos.get(a);
                                    if (at.getName().compareToIgnoreCase("schemaLocation") == 0)
                                        aux2.removeAttribute(at);
                                }
                            }
                        }
                    }
                }
            }
        }
        XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
        try {
            outputter.output(doc, new FileOutputStream(ruta));
        } catch (IOException e) {
            System.out.println(e);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:core.LectorXml.java

@Override
public void readNodeFile() {
    try {//from www.j a  v a  2 s  . c om
        this.setDocument((Document) this.getBuilder().build(this.getFile()));
        this.setRootNode(this.getDocument().getRootElement());
        List list = (List) this.getRootNode().getChildren();

        for (Object object : list) {
            Element ob = (Element) object;
            System.out.println(ob.getName());
            if (ob.getName().equalsIgnoreCase("autor")) {
                try {
                    this.getXml().getAutor().setNombre(ob.getChild("nombre").getText());
                } catch (NullPointerException r) {
                    this.getXml().getAutor().setNombre("");
                }
                try {
                    this.getXml().getAutor().setDescripcion(ob.getChild("descripcion").getText());
                } catch (NullPointerException r) {
                    this.getXml().getAutor().setDescripcion("");
                }
                try {
                    this.getXml().getAutor().setVersion(ob.getChild("version").getText());
                } catch (NullPointerException r) {
                    this.getXml().getAutor().setVersion("");
                }
            } else if (ob.getName().equalsIgnoreCase("cuerpo")) {
                try {
                    Element tipo = ob.getChild("tipo");
                    this.getXml().getCuerpo()
                            .setColumnas(Integer.parseInt(tipo.getAttribute("columnas").getValue()));
                    this.getXml().getCuerpo()
                            .setTipo_datos(tipo.getAttribute("tipodatocolumna").getValue().split(","));
                } catch (NullPointerException r) {
                    this.getXml().getCuerpo().setColumnas(0);
                    this.getXml().getCuerpo().setTipo_datos(new String[] {});
                } catch (NumberFormatException n) {
                    this.getXml().getCuerpo().setColumnas(0);
                    this.getXml().getCuerpo().setTipo_datos(new String[] {});
                }
                try {
                    Element tipo = ob.getChild("claseprincipal");
                    this.getXml().getCuerpo().setMain(ob.getChild("claseprincipal").getValue());
                } catch (NullPointerException r) {
                    this.getXml().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 {
                    this.getXml().getCuerpo().setParametros(parametros);
                }
            }

        }

    } catch (JDOMException ex) {
        Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:core.ListComponenXml.java

@Override
public void readNodeFile() {
    try {/*from  ww w. j a v a2 s .  c om*/
        this.setDocument((Document) this.getBuilder().build(this.getFile()));
        this.setRootNode(this.getDocument().getRootElement());
        List list = (List) this.getRootNode().getChildren();
        for (Object object : list) {
            Element tem = (Element) object;
            this.setXml(new Xml());
            for (Element ob : tem.getChildren()) {
                System.out.println(ob.getName());
                if (ob.getName().equalsIgnoreCase("autor")) {
                    try {
                        this.getXml().getAutor().setNombre(ob.getChild("nombre").getText());
                    } catch (NullPointerException r) {
                        this.getXml().getAutor().setNombre("");
                    }
                    try {
                        this.getXml().getAutor().setDescripcion(ob.getChild("descripcion").getText());
                    } catch (NullPointerException r) {
                        this.getXml().getAutor().setDescripcion("");
                    }
                    try {
                        this.getXml().getAutor().setVersion(ob.getChild("version").getText());
                    } catch (NullPointerException r) {
                        this.getXml().getAutor().setVersion("");
                    }
                } else if (ob.getName().equalsIgnoreCase("status")) {
                    try {
                        this.getXml().getStatus()
                                .setActive(Boolean.valueOf(ob.getAttribute("active").getValue()));
                    } catch (Exception e) {
                        this.getXml().getStatus().setActive(true);
                    }
                } else if (ob.getName().equalsIgnoreCase("cuerpo")) {
                    try {
                        Element tipo = ob.getChild("tipo");
                        this.getXml().getCuerpo()
                                .setColumnas(Integer.parseInt(tipo.getAttribute("columnas").getValue()));
                        this.getXml().getCuerpo()
                                .setTipo_datos(tipo.getAttribute("tipodatocolumna").getValue().split(","));
                    } catch (NullPointerException r) {
                        this.getXml().getCuerpo().setColumnas(0);
                        this.getXml().getCuerpo().setTipo_datos(new String[] {});
                    } catch (NumberFormatException n) {
                        this.getXml().getCuerpo().setColumnas(0);
                        this.getXml().getCuerpo().setTipo_datos(new String[] {});
                    }
                    try {
                        Element tipo = ob.getChild("claseprincipal");
                        this.getXml().getCuerpo().setMain(ob.getChild("claseprincipal").getValue());
                    } catch (NullPointerException r) {
                        this.getXml().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 {
                        this.getXml().getCuerpo().setParametros(parametros);
                    }
                }
            }
            this.getXmls().add(this.getXml());
        }

    } catch (JDOMException ex) {
        Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:core.ListComponenXml.java

@Override
public void readFile(Xml xml) {
    try {/*from   w w w  .  ja v a  2  s  . co  m*/
        this.setDocument((Document) this.getBuilder().build(this.getFile()));
        this.setRootNode(this.getDocument().getRootElement());
        List list = (List) this.getRootNode().getChildren();
        for (Object object : list) {
            Element tem = (Element) object;
            this.setXml(new Xml());
            for (Element ob : tem.getChildren()) {
                System.out.println(ob.getName());
                if (ob.getName().equalsIgnoreCase("autor")) {
                    try {
                        this.getXml().getAutor().setNombre(ob.getChild("nombre").getText());
                    } catch (NullPointerException r) {
                        this.getXml().getAutor().setNombre("");
                    }
                    try {
                        this.getXml().getAutor().setDescripcion(ob.getChild("descripcion").getText());
                    } catch (NullPointerException r) {
                        this.getXml().getAutor().setDescripcion("");
                    }
                    try {
                        this.getXml().getAutor().setVersion(ob.getChild("version").getText());
                    } catch (NullPointerException r) {
                        this.getXml().getAutor().setVersion("");
                    }
                } else if (ob.getName().equalsIgnoreCase("status")) {
                    try {
                        this.getXml().getStatus()
                                .setActive(Boolean.valueOf(ob.getAttribute("active").getValue()));
                    } catch (Exception e) {
                        this.getXml().getStatus().setActive(true);
                    }
                } else if (ob.getName().equalsIgnoreCase("cuerpo")) {
                    try {
                        Element tipo = ob.getChild("tipo");
                        this.getXml().getCuerpo()
                                .setColumnas(Integer.parseInt(tipo.getAttribute("columnas").getValue()));
                        this.getXml().getCuerpo()
                                .setTipo_datos(tipo.getAttribute("tipodatocolumna").getValue().split(","));
                    } catch (NullPointerException r) {
                        this.getXml().getCuerpo().setColumnas(0);
                        this.getXml().getCuerpo().setTipo_datos(new String[] {});
                    } catch (NumberFormatException n) {
                        this.getXml().getCuerpo().setColumnas(0);
                        this.getXml().getCuerpo().setTipo_datos(new String[] {});
                    }
                    try {
                        Element tipo = ob.getChild("claseprincipal");
                        this.getXml().getCuerpo().setMain(ob.getChild("claseprincipal").getValue());
                    } catch (NullPointerException r) {
                        this.getXml().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 {
                        this.getXml().getCuerpo().setParametros(parametros);
                    }
                }
            }
            this.xmls.add(this.getXml());
        }

    } catch (JDOMException ex) {
        Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LectorXml.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:core.ValidXml.java

@Override
public boolean validEstructura(File xml_file) {
    try {//from w  ww.j a  v a2  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;
}