Example usage for org.jdom2 Element getAttributeValue

List of usage examples for org.jdom2 Element getAttributeValue

Introduction

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

Prototype

public String getAttributeValue(final String attname) 

Source Link

Document

This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.

Usage

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

License:Apache License

/**
 * /*from  w w w.j  av a 2 s .c o  m*/
 * PDF File? ?
 * 
 * @param filePath PDF ?? ?? File Path
 *  
 */
public static void createPDF(String filePath, Upload upload, PDFMetadataDefinition data) throws Exception {

    if (data == null)
        return;

    //PDF ? ?
    Document pdf = new Document(PageSize.A4, 50, 50, 70, 65);
    PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(filePath));
    writer.setLinearPageMode();

    //Page Event ?( ? ?, ? ??  event)
    PDFCommonEventHelper event = new PDFCommonEventHelper();
    writer.setPageEvent(event);

    pdf.open();
    int cNum = 1;

    SAXBuilder builder = new SAXBuilder();

    //chapter ? xml 
    File listXml = new File(PDFDocGenerator.class.getResource("/xml/chapter.xml").getFile());
    org.jdom2.Document listDoc = builder.build(listXml);

    for (Element chapterE : listDoc.getRootElement().getChildren()) {

        if (chapterE.getAttributeValue("option") != null) {

            String option = chapterE.getAttributeValue("option");

            //source ?? ?  
            if (option.equals("zip") && data.getZipDefinition() != null) {

                addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data.getZipDefinition(), upload);
                cNum++;

                //deploy ?? ?  
            } else if (option.equals("deploy")
                    && (upload.getDeploySrc() != null && upload.getDeploySrc().getFileItem().getSize() > 0)) {

                addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data.getZipDefinition(), upload);
                cNum++;

                //.ear ?? ?  
            } else if (option.equals("ear") && data.getEarDefinition() != null) {

                addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data, upload);
                cNum++;

                //.war ?? ?  
            } else if (option.equals("war") && data.getEarDefinition() == null
                    && data.getWarDefinitionMap() != null) {
                Iterator iterator = data.getWarDefinitionMap().entrySet().iterator();

                if (iterator.hasNext()) {
                    Entry entry = (Entry) iterator.next();
                    addChapterForDynamic(writer, chapterE, cNum, pdf, builder,
                            (AnalyzeDefinition) entry.getValue(), upload);
                    cNum++;
                }

                //.jar ?? ?  
            } else if (option.equals("jar") && data.getEarDefinition() == null
                    && data.getJarDefinitionMap() != null) {
                Iterator iterator = data.getJarDefinitionMap().entrySet().iterator();

                if (iterator.hasNext()) {
                    Entry entry = (Entry) iterator.next();
                    addChapterForDynamic(writer, chapterE, cNum, pdf, builder,
                            (AnalyzeDefinition) entry.getValue(), upload);
                    cNum++;
                }

                //PDFMetadataDefinition?  data  
            } else if (option.equals("root")) {

                addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data, upload);
                cNum++;

                // was ? ? ? chapter 
            } else if (option.equals(upload.getAfterWas())) {

                addChapter(writer, chapterE, cNum, pdf, builder);
                cNum++;
                //Exception  ? ? chapter 
            } else if (option.equals("exception")) {

                if (data.getExceptionInfoList().size() > 0) {
                    addChapterForDynamic(writer, chapterE, cNum, pdf, builder, data, upload);
                    cNum++;
                }
            }

        } else {
            addChapter(writer, chapterE, cNum, pdf, builder);
            cNum++;
        }
    }

    setLastPageInfo(pdf, writer, cNum);
    setChapterSectionTOC(pdf, writer, event);
    setTitleMainPage(pdf, writer, event, upload);
    pdf.close();
}

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

License:Apache License

/**
 * /*from  w w w  .  jav  a  2  s.com*/
 * ? ??  Chatper Data ? (data class : AnalyzeDefinition)
 * 
 * @param writer
 * @param chapterE
 * @param cNum
 * @param pdf
 * @param builder
 * @param data
 * @param upload
 * @throws Exception
 */
public static void addChapterForDynamic(PdfWriter writer, Element chapterE, int cNum, Document pdf,
        SAXBuilder builder, AnalyzeDefinition data, Upload upload) throws Exception {

    //chapter  xml 
    File chapterXml = new File(PDFDocGenerator.class.getResource(chapterE.getText()).getFile());
    org.jdom2.Document chapterDoc = builder.build(chapterXml);

    Element root = chapterDoc.getRootElement();

    //?? ? ??  setting
    setDynamicSection(root, data, upload);

    //chapter ?
    Chapter chapter = PDFWriterUtil.getChapter(root.getAttributeValue("title"), cNum);

    PDFWriterUtil.setElement(writer, chapter, root);

    pdf.add(chapter);
}

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

License:Apache License

/**
 * ? ??  Chatper Data ? (data class : PDFMetadataDefinition)
 * //w w w.j  av  a  2 s .  c o  m
 * @param writer
 * @param chapterE
 * @param cNum
 * @param pdf
 * @param builder
 * @param data
 * @param upload
 * @throws Exception
 */
public static void addChapterForDynamic(PdfWriter writer, Element chapterE, int cNum, Document pdf,
        SAXBuilder builder, PDFMetadataDefinition data, Upload upload) throws Exception {

    //chapter  xml 
    File chapterXml = new File(PDFDocGenerator.class.getResource(chapterE.getText()).getFile());
    org.jdom2.Document chapterDoc = builder.build(chapterXml);

    Element root = chapterDoc.getRootElement();

    //?? ? ??  setting
    setDynamicSection(root, data, upload);

    //chapter ?
    Chapter chapter = PDFWriterUtil.getChapter(root.getAttributeValue("title"), cNum);

    PDFWriterUtil.setElement(writer, chapter, root);

    pdf.add(chapter);
}

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

License:Apache License

/**
 * /* w  w  w . ja v  a  2 s  .c  om*/
 *  ?
 * 
 * @param writer
 * @param chapterE
 * @param cNum
 * @param pdf
 * @param builder
 * @throws Exception
 */
public static void addChapter(PdfWriter writer, Element chapterE, int cNum, Document pdf, SAXBuilder builder)
        throws Exception {

    //chapter  xml 
    File chapterXml = new File(PDFDocGenerator.class.getResource(chapterE.getText()).getFile());
    org.jdom2.Document chapterDoc = builder.build(chapterXml);

    //chapter ?
    Element root = chapterDoc.getRootElement();
    Chapter chapter = PDFWriterUtil.getChapter(root.getAttributeValue("title"), cNum);

    PDFWriterUtil.setElement(writer, chapter, root);

    pdf.add(chapter);
}

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

License:Apache License

/**
 * //from   w ww.j  a va  2s . co  m
 * Section ? ? Element Mapping
 * 
 * @param parent parent ?
 * @param e element 
 * @return Section
 * @throws Exception
 */
public static Section setSectionElement(PdfWriter writer, Section parent, Element e) throws Exception {

    Section section = getSection(parent, e.getAttributeValue("title"));
    return setElement(writer, section, e);

}

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

License:Apache License

/**
 * Element Mapping//from   ww  w .j av  a 2s.  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  a 2 s  . com
 *  Table 
 *
 * @param section table?  section ?
 * @param e table   element
 * @throws Exception
 */
public static void setTable(Section section, Element e) throws Exception {

    int colSize = Integer.parseInt(e.getAttributeValue("size"));

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

    t.setSpacingAfter(12);
    t.getDefaultCell().setLeading(0.0F, 1.3F);
    t.getDefaultCell().setMinimumHeight(22);
    t.getDefaultCell().setPaddingBottom(8);
    t.getDefaultCell().setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE);

    setTableHeader(e, t, colSize);
    setTableRow(e, t);

    section.add(t);
}

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

License:Apache License

/**
 * /*from   w ww  .ja v a2 s . c  om*/
 *  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 .j av  a  2s  .c om*/
 * 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

/**
 * /*from w ww .  j a  va  2s.co  m*/
 * 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);

}