Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

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

Prototype

public List<Element> getChildren() 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element, as Element objects.

Usage

From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java

License:Apache License

/**
 * ear  Applications //from w ww.j ava 2s .  co m
 * (type : war - Web, jar - EJB)
 * 
 * @param rootData
 * @param upload
 * @param type
 * @return
 * @throws Exception
 */
public static List<Element> setChildDeployData(PDFMetadataDefinition rootData, Upload upload, String type)
        throws Exception {

    List<Element> childs = new ArrayList<Element>();
    List<Element> childs2;
    Iterator iterator = null;
    if (type.equals("war")) {
        iterator = rootData.getWarDefinitionMap().entrySet().iterator();
    } else if (type.equals("jar")) {
        iterator = rootData.getJarDefinitionMap().entrySet().iterator();
    }

    Element section;
    File childXml = null;
    while (iterator.hasNext()) {
        childs2 = new ArrayList<Element>();
        Entry entry = (Entry) iterator.next();
        AnalyzeDefinition data = (AnalyzeDefinition) entry.getValue();

        if (type.equals("war")) {
            childXml = new File(PDFDocGenerator.class.getResource("/xml/war_application.xml").getFile());
        } else if (type.equals("jar")) {
            childXml = new File(PDFDocGenerator.class.getResource("/xml/jar_application.xml").getFile());
        }

        org.jdom2.Document chapterDoc = new SAXBuilder().build(childXml);

        Element root = chapterDoc.getRootElement();

        section = new Element("section");
        section.setAttribute("title", String.valueOf(entry.getKey()));

        for (Element e : root.getChildren()) {
            childs2.add(e.clone());
        }

        for (Element e : childs2) {
            section.addContent(e);
        }
        setDynamicSection(section, data, upload);

        childs.add(section);
    }

    return childs;
}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * Element Mapping//from  www.  ja  v  a 2  s .c o m
 * 
 * @param section section ?
 * @param e element 
 * @return Section
 * @throws Exception
 */
public static Section setElement(PdfWriter writer, Section section, Element e) throws Exception {

    for (org.jdom2.Element e1 : e.getChildren()) {

        if (e1.getName().equals("section")) {
            //  section?   
            setSectionElement(writer, section, e1);

        } else if (e1.getName().equals("text")) {

            /* ? text ?
               attribute : padding -  padding  */
            if (e1.getAttributeValue("padding") != null) {
                Paragraph text = getDefault(e1.getText());
                text.setIndentationLeft(
                        text.getIndentationLeft() + Float.parseFloat(e1.getAttributeValue("padding")));

                section.add(text);
            } else {
                section.add(getDefault(e1.getText()));
            }

        } else if (e1.getName().equals("table")) {
            // ?
            setTable(section, e1);

        } else if (e1.getName().equals("textR")) {
            //?? ? text ?
            section.add(getDefaultRed(e1.getText(), Font.ITALIC));

        } else if (e1.getName().equals("textP")) {
            //? ? text ?
            section.add(getDefaultPoint(e1.getText()));

        } else if (e1.getName().equals("box")) {
            //text box ?
            setBox(section, e1);

        } else if (e1.getName().equals("boxB")) {
            //? ? text box ?
            setBoxB(section, e1);

        } else if (e1.getName().equals("boxW")) {
            //text box ?
            setBoxW(section, e1);

        } else if (e1.getName().equals("list")) {
            //? ?
            setList(section, e1);

        } else if (e1.getName().equals("img")) {
            //? ?
            setImage(section, e1);
        } else if (e1.getName().equals("chart")) {
            // ?
            setChart(writer, section, e1);
        }
    }

    return section;

}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * //from   w  w w  .j a  v a2s. c  o  m
 *  box 
 *
 * @param section box  section ?
 * @param e box   element
 * @throws Exception
 */
public static void setBox(Section section, Element e) throws Exception {

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(1);
    t.setSpacingAfter(12);

    if (e.getAttributeValue("width") != null)
        t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width")));

    PdfPCell cell = new PdfPCell();
    if (e.getAttributeValue("option") != null) {

        ColumnText col = new ColumnText(null);
        for (Element e1 : e.getChildren()) {
            if (e1.getAttributeValue("type").equals("red"))
                col.addText(new Phrase(e1.getText(), fnBoxRed));
            else
                col.addText(new Phrase(e1.getText(), fnBox));
        }
        cell.setColumn(col);

    } else {
        cell.setPhrase(new Phrase(e.getText(), fnBox));
    }

    cell.setPaddingLeft(10);
    cell.setLeading(0.0F, 1.8F);
    cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(new BaseColor(238, 236, 225));

    t.addCell(cell);

    section.add(t);

}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * /*from w  w w . ja  va2 s  .  c  o m*/
 * box (Backgroud : Black)
 *
 * @param section box  section ?
 * @param e box   element
 * @throws Exception
 */
public static void setBoxB(Section section, Element e) throws Exception {

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(1);
    t.setSpacingAfter(12);

    if (e.getAttributeValue("width") != null)
        t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width")));

    PdfPCell cell = new PdfPCell();
    if (e.getAttributeValue("option") != null) {

        ColumnText col = new ColumnText(null);
        for (Element e1 : e.getChildren()) {
            if (e1.getAttributeValue("type").equals("red"))
                col.addText(new Phrase(e1.getText(), fnBoxRed));
            else
                col.addText(new Phrase(e1.getText(), fnBoxWhite));
        }
        cell.setColumn(col);

    } else {
        cell.setPhrase(new Phrase(e.getText(), fnBoxWhite));
    }

    cell.setPaddingLeft(10);
    cell.setLeading(0.0F, 1.8F);
    cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(new BaseColor(0, 0, 0));

    t.addCell(cell);

    section.add(t);

}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * /*ww  w. java2 s  . com*/
 * box (Backgroud : White)
 *
 * @param section box  section ?
 * @param e box   element
 * @throws Exception
 */
public static void setBoxW(Section section, Element e) throws Exception {

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(1);
    t.setSpacingAfter(12);

    if (e.getAttributeValue("width") != null)
        t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width")));

    PdfPCell cell = new PdfPCell();
    if (e.getAttributeValue("option") != null) {

        ColumnText col = new ColumnText(null);
        for (Element e1 : e.getChildren()) {
            if (e1.getAttributeValue("type").equals("red"))
                col.addText(new Phrase(e1.getText(), fnBoxRed));
            else
                col.addText(new Phrase(e1.getText(), fnBoxBlack));
        }
        cell.setColumn(col);

    } else {
        cell.setPhrase(new Phrase(e.getText(), fnBoxBlack));
    }

    cell.setPaddingLeft(10);
    cell.setLeading(0.0F, 1.8F);
    cell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(new BaseColor(255, 255, 255));

    t.addCell(cell);

    section.add(t);

}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * /*from  w  ww.  j a v a 2s  . c  om*/
 *  list 
 *
 * @param section list  section ?
 * @param e list   element
 * @throws Exception
 */
public static void setList(Section section, Element e) throws Exception {
    List list = new List(false, 15);
    list.setIndentationLeft(23);
    for (Element e1 : e.getChildren()) {
        ListItem item = new ListItem(e1.getText(), fnNormal);

        if (e1.getChild("url") != null) {
            item.add(getUrl(e1.getChild("url")));
        }

        item.setMultipliedLeading(1.8F);
        list.add(item);
    }
    list.getFirstItem().setSpacingBefore(-14);
    list.getLastItem().setSpacingAfter(14);

    section.add(list);
}

From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java

License:Apache License

/**
 * //  ww w.  j  a v  a 2 s. com
 * chart 
 *
 * @param section chart   section ?
 * @param e chart   element
 * @throws Exception
 */
public static void setChart(PdfWriter writer, Section section, Element e) throws Exception {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Element e1 : e.getChildren()) {
        if (!e1.getChild("column").getText().equals(FileType.DIRECTORY.toString())
                && !e1.getChild("column").getText().equals(FileType.SUM.toString())) {
            dataset.setValue(Integer.parseInt(e1.getChild("value").getText()), e.getAttributeValue("title"),
                    e1.getChild("column").getText());
        }
    }

    JFreeChart chart = ChartFactory.createBarChart3D(e.getAttributeValue("title"), "", "", dataset,
            PlotOrientation.VERTICAL, false, true, false);

    CategoryPlot plot = chart.getCategoryPlot();
    java.awt.Font labelFont = chart.getCategoryPlot().getDomainAxis().getLabelFont();
    plot.getDomainAxis().setLabelFont(new java.awt.Font(labelFont.getName(), Font.NORMAL, 6));
    plot.getDomainAxis().setTickLabelFont(new java.awt.Font(labelFont.getName(), Font.NORMAL, 6));

    PdfContentByte cb = writer.getDirectContent();
    PdfTemplate bar = cb.createTemplate(500, 150);
    Graphics2D g2d2 = new PdfGraphics2D(bar, 500, 150);
    Rectangle2D r2d2 = new Rectangle2D.Double(0, 0, 500, 150);
    chart.draw(g2d2, r2d2);
    g2d2.dispose();

    Image image = Image.getInstance(bar);
    image.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
    section.add(image);
}

From source file:com.bc.ceres.binio.binx.BinX.java

License:Open Source License

private Type parseArrayFixed(Element typeElement) throws BinXException {
    Element arrayTypeElement = getChild(typeElement, 0, true);
    Element dimElement = getChild(typeElement, "dim", 1, true);

    if (!dimElement.getChildren().isEmpty()) {
        // todo - implement multi-dimensional arrays (rq - 2008-11-27)
        throw new BinXException(MessageFormat.format(
                "Element ''{0}'': Multi-dimensional arrays not yet implemented", typeElement.getName()));
    }// w w w .j av a 2s  .c o m

    final Type arrayType = parseAnyType(arrayTypeElement);
    final int indexFrom = getAttributeIntValue(dimElement, "indexFrom", 0);
    if (indexFrom != 0) {
        throw new BinXException(
                MessageFormat.format("Element ''{0}'': Attribute 'indexFrom' other than zero not supported.",
                        typeElement.getName()));
    }
    final int indexTo = getAttributeIntValue(dimElement, "indexTo");

    return SEQUENCE(arrayType, indexTo + 1);
}

From source file:com.bc.fiduceo.reader.airs.AIRS_L1B_Reader.java

License:Open Source License

static String getElementValue(Element element, String attribute) {
    if (element.getName().equals(attribute)) {
        return element.getChild("VALUE").getValue();
    }/* w  w  w .  j  a va2 s  .c  o m*/
    for (Element subElement : element.getChildren()) {
        if (subElement.getName().equals(attribute)) {
            return subElement.getChild("VALUE").getValue();
        } else {
            final String elementValue = getElementValue(subElement, attribute);
            if (StringUtils.isNotNullAndNotEmpty(elementValue)) {
                return elementValue;
            }
        }
    }
    return null;
}

From source file:com.bennavetta.util.tycho.impl.DefaultWrapperGenerator.java

License:Apache License

private void writeModules(List<String> modules, File pomFile) throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();
    Document pom = builder.build(pomFile);
    Namespace pomNs = pom.getRootElement().getNamespace();
    Element modulesElem = pom.getRootElement().getChild("modules", pomNs);
    if (modulesElem == null) {
        modulesElem = new Element("modules", pomNs);
        pom.getRootElement().addContent(modulesElem);
    }/*from  w  w w.j av  a  2s . c  o m*/
    for (String module : modules) {
        boolean exists = false;
        for (Element existingModule : modulesElem.getChildren()) {
            if (existingModule.getTextTrim().equals(module)) {

                exists = true;
                break;
            }
        }
        if (!exists) {
            Element moduleElem = new Element("module", pomNs);
            moduleElem.setText(module);
            modulesElem.addContent(moduleElem);
        }
    }
    XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat().setIndent("\t"));
    try (FileOutputStream out = new FileOutputStream(pomFile)) {
        xout.output(pom, out);
    }
}