Example usage for com.lowagie.text Paragraph Paragraph

List of usage examples for com.lowagie.text Paragraph Paragraph

Introduction

In this page you can find the example usage for com.lowagie.text Paragraph Paragraph.

Prototype

public Paragraph(float leading, String string) 

Source Link

Document

Constructs a Paragraph with a certain String and a certain leading.

Usage

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsName(Airport airport, Document document) {
    // FIRST ROW//from w  w w .j a v a2  s. c  o  m
    // AIRPORT NAME     DATE        FLIGHTGEAR

    notifyAction("createSheetsName");

    PdfPTable table = new PdfPTable(3);
    {

        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
        Paragraph p = new Paragraph(airport.getName().toUpperCase(), font);

        PdfPCell cell = new PdfPCell(p);
        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        //cell.setColspan(3);
        table.addCell(cell);
    }

    {

        DateFormat dateFormat = new SimpleDateFormat("dd MMM yy", Locale.US);
        Date date = new Date();
        String dateString = dateFormat.format(date).toUpperCase();

        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8,
                com.lowagie.text.Font.NORMAL);
        PdfPCell cell = new PdfPCell(new Paragraph(dateString, font));
        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
    }

    {
        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.COURIER,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
        PdfPCell cell = new PdfPCell(new Paragraph("FLIGHTGEAR", font));
        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
    }

    float[] widths2 = { 2f, 1f, 1f };
    try {
        table.setWidths(widths2);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsAircraftTypes(Airport airport, Document document) {
    // AIRPORT NAME     Aircrafts pictures
    notifyAction("createSheetsAircraftTypes");
    PdfPTable table = new PdfPTable(2);
    {//  w w  w  . j  av a 2s. c  om

        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.NORMAL);
        Paragraph p = new Paragraph(airport.getId(), font);

        PdfPCell cell = new PdfPCell(p);
        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);

        table.addCell(cell);
    }

    {
        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.COURIER,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
        PdfPCell cell = new PdfPCell(new Paragraph("FLIGHTGEAR", font));
        cell.setBorderWidth(borderWidth);
        //cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsFreqs(Airport airport, Document document) {
    // FREQs Nearest Navaid
    notifyAction("createSheetsFreqs");
    PdfPTable table = new PdfPTable(2);
    {/*from ww  w .jav a 2  s  .com*/
        PdfPCell cell = new PdfPCell();

        cell.setVerticalAlignment(Element.ALIGN_TOP);

        {
            if (_airport.getAtises().size() > 0) {
                String freq = "";
                for (final Atis atis : _airport.getAtises()) {
                    freq = freq + new Double(atis.getFreq()).toString() + " ";
                }

                Paragraph p = createTinyParagraph("ATIS ", freq);
                cell.addElement(p);
            }
        }

        {

            String[] reqs = { "50", "51", "52", "53", "54", "55", "56" };
            for (String req : reqs) {

                List<ATCFreq> tempFreqs = _airport.getATCFreqs(req);
                if (tempFreqs.size() > 0) {
                    String freq = "";
                    for (final ATCFreq tower : tempFreqs) {
                        freq = freq + tower.getFreq() + " ";
                    }

                    Paragraph p = createTinyParagraph(ATCFreq.typeNames.get(req) + " ", freq);
                    cell.addElement(p);

                }
            }

        }

        //cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setBorderWidth(borderWidth);
        cell.setVerticalAlignment(Element.ALIGN_TOP);

        table.addCell(cell);
    }

    {
        PdfPCell cell = new PdfPCell();
        {
            Paragraph p = new Paragraph("Nearest Navaid:", new com.lowagie.text.Font(
                    com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL));
            cell.addElement(p);
        }

        {
            Paragraph p = new Paragraph(getNEarestBeaconString(airport), new com.lowagie.text.Font(
                    com.lowagie.text.Font.TIMES_ROMAN, 10, com.lowagie.text.Font.NORMAL));
            cell.addElement(p);
        }

        cell.setBorderWidth(borderWidth);
        //cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsRunways(Airport airport, Document document) {
    notifyAction("createSheetsRunways");

    PdfPTable table = new PdfPTable(6);

    // titles//from   w  w  w .j  a v  a  2  s. c  om
    com.lowagie.text.Font fontTitle = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8,
            com.lowagie.text.Font.NORMAL);
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidthThin);
        cell.setBorderWidthLeft(borderWidth);
        Paragraph p = new Paragraph("RWY N" + degrees, fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);
    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidthThin);
        cell.setBorderWidthLeft(borderWidthThin);
        Paragraph p = new Paragraph("Dimension (ft) - Surface", fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);
    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidthThin);
        cell.setBorderWidthLeft(borderWidthThin);
        Paragraph p = new Paragraph("TORA (ft)", fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);
    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidthThin);
        cell.setBorderWidthLeft(borderWidthThin);
        Paragraph p = new Paragraph("LDA (ft)", fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);
    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidthThin);
        cell.setBorderWidthLeft(borderWidthThin);
        Paragraph p = new Paragraph("Strength", fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);

    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setBorderWidthTop(borderWidth);
        cell.setBorderWidthBottom(borderWidthThin);
        cell.setBorderWidthRight(borderWidth);
        cell.setBorderWidthLeft(borderWidthThin);
        Paragraph p = new Paragraph("Lights", fontTitle);
        p.setLeading((p.leading() / 2) + 2);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        table.addCell(cell);
    }

    // data
    com.lowagie.text.Font fontData = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 10,
            com.lowagie.text.Font.NORMAL);
    int rc = 0;
    for (final Runway runway : airport.getRunways()) {
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidth);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            cell.setBorderWidthRight(borderWidthThin);
            Paragraph p = new Paragraph(runway.getNumber() + "\r\n" + runway.getOppositeNumber(), fontData);
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            cell.addElement(p);
            table.addCell(cell);
        }
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidthThin);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            cell.setBorderWidthRight(borderWidthThin);
            String runwayLength = new Integer(runway.getLength()).toString() + " x "
                    + new Integer(runway.getWidth()).toString() + " " + runway.getSurfaceName();
            Paragraph p = new Paragraph(runwayLength, fontData);
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            cell.addElement(p);
            table.addCell(cell);

        }
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidthThin);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            cell.setBorderWidthRight(borderWidthThin);
            Paragraph p = new Paragraph(runway.getLength() + "\r\n" + runway.getLength(), fontData);
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            cell.addElement(p);
            table.addCell(cell);
        }
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidthThin);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            cell.setBorderWidthRight(borderWidthThin);
            Paragraph p = new Paragraph((runway.getLength() - runway.getDisplacement()) + "\r\n"
                    + (runway.getLength() - runway.getDisplacementOpposite()), fontData);
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            cell.addElement(p);
            table.addCell(cell);
        }
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidthThin);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            cell.setBorderWidthRight(borderWidthThin);
            Paragraph p = new Paragraph("to do...", fontData);
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            cell.addElement(p);
            table.addCell(cell);
        }
        {
            PdfPCell cell = new PdfPCell();
            cell.setVerticalAlignment(Element.ALIGN_CENTER);
            cell.setBorderWidthLeft(borderWidthThin);
            cell.setBorderWidthRight(borderWidth);
            if (rc < airport.getRunways().size() - 1) {
                // thin bottom if not last runway
                cell.setBorderWidthBottom(borderWidthThin);
            } else {
                cell.setBorderWidthBottom(borderWidth);
            }
            Paragraph p = new Paragraph();
            p.setLeading((p.leading() / 2) + 2);
            p.setAlignment(Element.ALIGN_CENTER);
            try {
                if (runway.hasALSF_I(true) || runway.hasALSF_I(false) || runway.hasALSF_II(true)
                        || runway.hasALSF_II(false) || runway.hasPapi(true) || runway.hasPapi(false)
                        || runway.hasSALSF(true) || runway.hasSALSF(false) || runway.hasSSLP(true)
                        || runway.hasSSLP(false) || runway.hasVasi(true) || runway.hasVasi(false)) {
                    p.add(new Chunk(Image.getInstance(getClass().getResource(Main.imgFolder + "light.png")), 0,
                            0));
                } else {
                    p.add(new Chunk("--", fontData));
                }
            } catch (BadElementException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            }
            cell.addElement(p);
            table.addCell(cell);
        }

        rc++;

    }

    float[] widths2 = { 1f, 2f, 1f, 1f, 2f, 1f };
    try {
        table.setWidths(widths2);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheets2Name(Airport airport, Document document) {
    // FIRST ROW//from  w ww .  j a va2 s.  c  o m
    // AIRPORT NAME     DATE        FLIGHTGEAR

    notifyAction("createSheets2Name");

    PdfPTable table = new PdfPTable(3);

    {
        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.COURIER,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
        PdfPCell cell = new PdfPCell(new Paragraph("FLIGHTGEAR", font));
        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        //cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
    }

    {
        DateFormat dateFormat = new SimpleDateFormat("dd MMM yy", Locale.US);
        Date date = new Date();
        String dateString = dateFormat.format(date).toUpperCase();

        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8,
                com.lowagie.text.Font.NORMAL);
        PdfPCell cell = new PdfPCell(new Paragraph(dateString, font));
        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
    }

    {

        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
        Paragraph p = new Paragraph(airport.getName().toUpperCase(), font);

        PdfPCell cell = new PdfPCell(p);
        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        //cell.setColspan(3);
        table.addCell(cell);
    }

    float[] widths2 = { 1f, 1f, 2f };
    try {
        table.setWidths(widths2);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheets2Freqs(Airport airport, Document document) {
    // FREQs Nearest Navaid
    notifyAction("createSheets2Freqs");
    PdfPTable table = new PdfPTable(2);
    {/* ww  w .  ja v  a2s .c o  m*/
        PdfPCell cell = new PdfPCell();
        {
            Paragraph p = new Paragraph("Within Airspace:", new com.lowagie.text.Font(
                    com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL));
            cell.addElement(p);
        }

        cell.setBorderWidth(borderWidth);

        cell.setBorderWidthBottom(borderWidthThin);

        //cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
    }

    {
        PdfPCell cell = new PdfPCell();

        com.lowagie.text.Font fontBold = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.NORMAL);

        {
            Paragraph p = new Paragraph(airport.getId(), fontBold);
            cell.addElement(p);
        }
        {
            Paragraph p = new Paragraph();
            p.add(new Chunk("Elev ", font));

            int feets = (int) (airport.getElevation());
            p.add(new Chunk(new Integer(feets).toString() + "'", fontBold));
            int meters = (int) (feets / FEET_PER_METER);

            p.add(new Chunk("/" + new Integer(meters).toString() + "m", font));

            cell.addElement(p);
        }

        {
            Paragraph p = new Paragraph();
            p.add(new Chunk(airport.getLatitudeString1(airport.getLat(), "N", "S", 2, false) + "\r\n"
                    + airport.getLatitudeString1(airport.getLong(), "W", "E", 3, true), font));

            cell.addElement(p);
        }

        cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);

        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheets2ILS(Airport airport, Document document) {
    // FREQs Nearest Navaid
    notifyAction("createSheets2ILS");
    PdfPTable table = new PdfPTable(2);
    {//w  w  w .j a  v  a2 s. com
        PdfPCell cell = new PdfPCell();
        {
            Paragraph p = new Paragraph("(TWR)", new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8,
                    com.lowagie.text.Font.NORMAL));
            p.setLeading((p.leading() / 2) + 2);
            cell.addElement(p);
        }

        List<ATCFreq> tempFreqsTwr = _airport.getATCFreqs("54");
        List<ATCFreq> tempFreqsGnd = _airport.getATCFreqs("53");
        if (tempFreqsTwr.size() > 0 || tempFreqsGnd.size() > 0) {

            if (tempFreqsTwr.size() > 0) {
                Paragraph p = new Paragraph();
                p.setLeading((p.leading() / 2) + 6);
                Chunk c = new Chunk(airport.getName().toUpperCase() + " APPROACH ", new com.lowagie.text.Font(
                        com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL));
                p.add(c);
                for (final ATCFreq tower : tempFreqsTwr) {
                    Chunk c2 = new Chunk((tower.getFreq() + "        ").substring(0, 9) + " ",
                            new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8,
                                    com.lowagie.text.Font.BOLD));
                    p.add(c2);

                }
                cell.addElement(p);

            }

            if (tempFreqsGnd.size() > 0) {
                Paragraph p = new Paragraph();
                p.setLeading((p.leading() / 2) + 6);
                Chunk c = new Chunk("GROUND ", new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8,
                        com.lowagie.text.Font.NORMAL));
                p.add(c);
                for (final ATCFreq tower : tempFreqsGnd) {
                    Chunk c2 = new Chunk((tower.getFreq() + "        ").substring(0, 9) + " ",
                            new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8,
                                    com.lowagie.text.Font.BOLD));
                    p.add(c2);

                }
                cell.addElement(p);

            }

        }

        cell.setBorderWidth(borderWidth);
        cell.setBorderWidthTop(borderWidthThin);
        cell.setBorderWidthRight(borderWidthThin);

        //cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        table.addCell(cell);
    }

    {
        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.NORMAL);
        PdfPCell cell = new PdfPCell();

        Paragraph p = new Paragraph();
        p.setLeading((p.leading()) + 6);
        Chunk c = new Chunk("ATIS ",
                new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL));
        p.add(c);

        for (final Atis atis : _airport.getAtises()) {
            Chunk c2 = new Chunk((atis.getFreq() + "        ").substring(0, 9) + " ", new com.lowagie.text.Font(
                    com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.BOLD));
            p.add(c2);
        }

        cell.addElement(p);

        /// ILS table
        {
            height1 = 0;
            PdfPTable tableILS = new PdfPTable(4);
            tableILS.setWidthPercentage(100);

            // titles
            com.lowagie.text.Font fontTitle = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8,
                    com.lowagie.text.Font.NORMAL);
            {
                PdfPCell cellTitle = new PdfPCell();
                cellTitle.setVerticalAlignment(Element.ALIGN_CENTER);
                cellTitle.setBorderWidth(borderWidthThin);
                Paragraph pt = new Paragraph("RWY", fontTitle);
                pt.setLeading((pt.leading() / 2) + 2);
                pt.setAlignment(Element.ALIGN_CENTER);
                cellTitle.addElement(pt);
                tableILS.addCell(cellTitle);
            }
            {
                PdfPCell cellTitle = new PdfPCell();
                cellTitle.setVerticalAlignment(Element.ALIGN_CENTER);
                cellTitle.setBorderWidth(borderWidthThin);
                Paragraph pt = new Paragraph("ILS", fontTitle);
                pt.setLeading((pt.leading() / 2) + 2);
                pt.setAlignment(Element.ALIGN_CENTER);
                cellTitle.addElement(pt);
                tableILS.addCell(cellTitle);
            }
            {
                PdfPCell cellTitle = new PdfPCell();
                cellTitle.setVerticalAlignment(Element.ALIGN_CENTER);
                cellTitle.setBorderWidth(borderWidthThin);
                Paragraph pt = new Paragraph("RWY", fontTitle);
                pt.setLeading((pt.leading() / 2) + 2);
                pt.setAlignment(Element.ALIGN_CENTER);
                cellTitle.addElement(pt);
                tableILS.addCell(cellTitle);
            }
            {
                PdfPCell cellTitle = new PdfPCell();
                cellTitle.setVerticalAlignment(Element.ALIGN_CENTER);
                cellTitle.setBorderWidth(borderWidthThin);
                Paragraph pt = new Paragraph("ILS", fontTitle);
                pt.setLeading((pt.leading() / 2) + 2);
                pt.setAlignment(Element.ALIGN_CENTER);
                cellTitle.addElement(pt);
                tableILS.addCell(cellTitle);
            }

            int pos = 0;
            int rs = airport.getRunways().size();
            for (final Runway runway : airport.getRunways()) {
                if (runway.getIlsFreq() != 0) {
                    height1 = height1 + 10;
                    {
                        PdfPCell cellFreq = new PdfPCell();
                        cellFreq.setVerticalAlignment(Element.ALIGN_CENTER);
                        cellFreq.setBorderWidth(borderWidthThin);
                        if (pos > 0) {
                            cellFreq.setBorderWidthTop(0);
                        }
                        if (pos < rs - 1) {
                            cellFreq.setBorderWidthBottom(0);
                        }

                        Paragraph pt = new Paragraph(runway.getNumber(), fontTitle);
                        pt.setLeading((pt.leading() / 2) + 2);
                        pt.setAlignment(Element.ALIGN_CENTER);
                        cellFreq.addElement(pt);
                        tableILS.addCell(cellFreq);
                    }
                    {
                        PdfPCell cellFreq = new PdfPCell();
                        cellFreq.setVerticalAlignment(Element.ALIGN_CENTER);
                        cellFreq.setBorderWidth(borderWidthThin);
                        if (pos > 0) {
                            cellFreq.setBorderWidthTop(0);
                        }
                        if (pos < rs - 1) {
                            cellFreq.setBorderWidthBottom(0);
                        }

                        Paragraph pt = new Paragraph(
                                runway.getIlsFreq() + " " + "... "
                                        + new Integer((int) runway.getHeading()).toString() + degrees,
                                fontTitle);
                        pt.setLeading((pt.leading() / 2) + 2);
                        pt.setAlignment(Element.ALIGN_CENTER);
                        cellFreq.addElement(pt);
                        tableILS.addCell(cellFreq);
                    }
                } /*else {
                  {
                      PdfPCell cellFreq = new PdfPCell();
                      cellFreq.setVerticalAlignment(Element.ALIGN_CENTER);
                      cellFreq.setBorderWidth(borderWidthThin);
                      if (pos>0) {
                          cellFreq.setBorderWidthTop(0);
                      }
                      if (pos<rs-1) {
                          cellFreq.setBorderWidthBottom(0);
                      }
                          
                      Paragraph pt=new Paragraph( "",fontTitle);
                      pt.setLeading((pt.leading()/2)+2);
                      pt.setAlignment(Element.ALIGN_CENTER);
                      cellFreq.addElement(pt);
                      tableILS.addCell(cellFreq);
                  }
                  {
                      PdfPCell cellFreq = new PdfPCell();
                      cellFreq.setVerticalAlignment(Element.ALIGN_CENTER);
                      cellFreq.setBorderWidth(borderWidthThin);
                      if (pos>0) {
                          cellFreq.setBorderWidthTop(0);
                      }
                      if (pos<rs-1) {
                          cellFreq.setBorderWidthBottom(0);
                      }
                          
                      Paragraph pt=new Paragraph( "",fontTitle);
                      pt.setLeading((pt.leading()/2)+2);
                      pt.setAlignment(Element.ALIGN_CENTER);
                      cellFreq.addElement(pt);
                      tableILS.addCell(cellFreq);
                  }
                          
                  }*/

                if (runway.getIlsOppositeFreq() != 0) {
                    {
                        PdfPCell cellFreq = new PdfPCell();
                        cellFreq.setVerticalAlignment(Element.ALIGN_CENTER);
                        cellFreq.setBorderWidth(borderWidthThin);
                        if (pos > 0) {
                            cellFreq.setBorderWidthTop(0);
                        }
                        if (pos < rs - 1) {
                            cellFreq.setBorderWidthBottom(0);
                        }

                        Paragraph pt = new Paragraph(runway.getOppositeNumber(), fontTitle);
                        pt.setLeading((pt.leading() / 2) + 2);
                        pt.setAlignment(Element.ALIGN_CENTER);
                        cellFreq.addElement(pt);
                        tableILS.addCell(cellFreq);
                    }
                    {
                        PdfPCell cellFreq = new PdfPCell();
                        cellFreq.setVerticalAlignment(Element.ALIGN_CENTER);
                        cellFreq.setBorderWidth(borderWidthThin);
                        if (pos > 0) {
                            cellFreq.setBorderWidthTop(0);
                        }
                        if (pos < rs - 1) {
                            cellFreq.setBorderWidthBottom(0);
                        }

                        Paragraph pt = new Paragraph(runway.getIlsOppositeFreq() + " " + "... "
                                + new Integer((int) (runway.getHeading() + 180) % 180).toString() + degrees,
                                fontTitle);
                        pt.setLeading((pt.leading() / 2) + 2);
                        pt.setAlignment(Element.ALIGN_CENTER);
                        cellFreq.addElement(pt);
                        tableILS.addCell(cellFreq);
                    }
                } else {
                    {
                        PdfPCell cellFreq = new PdfPCell();
                        cellFreq.setVerticalAlignment(Element.ALIGN_CENTER);
                        cellFreq.setBorderWidth(borderWidthThin);
                        if (pos > 0) {
                            cellFreq.setBorderWidthTop(0);
                        }
                        if (pos < rs - 1) {
                            cellFreq.setBorderWidthBottom(0);
                        }

                        Paragraph pt = new Paragraph("", fontTitle);
                        pt.setLeading((pt.leading() / 2) + 2);
                        pt.setAlignment(Element.ALIGN_CENTER);
                        cellFreq.addElement(pt);
                        tableILS.addCell(cellFreq);
                    }
                    {
                        PdfPCell cellFreq = new PdfPCell();
                        cellFreq.setVerticalAlignment(Element.ALIGN_CENTER);
                        cellFreq.setBorderWidth(borderWidthThin);
                        if (pos > 0) {
                            cellFreq.setBorderWidthTop(0);
                        }
                        if (pos < rs - 1) {
                            cellFreq.setBorderWidthBottom(0);
                        }

                        Paragraph pt = new Paragraph("", fontTitle);
                        pt.setLeading((pt.leading() / 2) + 2);
                        pt.setAlignment(Element.ALIGN_CENTER);
                        cellFreq.addElement(pt);
                        tableILS.addCell(cellFreq);
                    }

                }

                pos++;

            }

            float[] widths2 = { 1f, 3f, 1f, 3f };
            try {
                tableILS.setWidths(widths2);
            } catch (DocumentException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            }

            cell.addElement(tableILS);
        }

        cell.setBorderWidth(borderWidth);
        cell.setVerticalAlignment(Element.ALIGN_TOP);

        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:be.fedict.eid.tsl.Tsl2PdfExporter.java

License:Open Source License

/**
 * Produce a human readable export of the given tsl to the given file.
 * /*  w ww. j a  v  a  2s.  c o  m*/
 * @param tsl
 *            the TrustServiceList to export
 * @param pdfFile
 *            the file to generate
 * @return
 * @throws IOException
 */
public void humanReadableExport(final TrustServiceList tsl, final File pdfFile) {
    Document document = new Document();
    OutputStream outputStream;
    try {
        outputStream = new FileOutputStream(pdfFile);
    } catch (FileNotFoundException e) {
        throw new RuntimeException("file not found: " + pdfFile.getAbsolutePath(), e);
    }
    try {
        final PdfWriter pdfWriter = PdfWriter.getInstance(document, outputStream);
        pdfWriter.setPDFXConformance(PdfWriter.PDFA1B);

        // title
        final EUCountry country = EUCountry.valueOf(tsl.getSchemeTerritory());
        final String title = country.getShortSrcLangName() + " (" + country.getShortEnglishName()
                + "): Trusted List";

        Phrase footerPhrase = new Phrase("PDF document generated on " + new Date().toString() + ", page ",
                headerFooterFont);
        HeaderFooter footer = new HeaderFooter(footerPhrase, true);
        document.setFooter(footer);

        Phrase headerPhrase = new Phrase(title, headerFooterFont);
        HeaderFooter header = new HeaderFooter(headerPhrase, false);
        document.setHeader(header);

        document.open();
        addTitle(title, title0Font, Paragraph.ALIGN_CENTER, 0, 20, document);

        addLongItem("Scheme name", tsl.getSchemeName(), document);
        addLongItem("Legal Notice", tsl.getLegalNotice(), document);

        // information table
        PdfPTable informationTable = createInfoTable();
        addItemRow("Scheme territory", tsl.getSchemeTerritory(), informationTable);
        addItemRow("Scheme status determination approach",
                substringAfter(tsl.getStatusDeterminationApproach(), "StatusDetn/"), informationTable);
        /*
        final List<String> schemeTypes = new ArrayList<String>();
        for (final String schemeType : tsl.getSchemeTypes()) {
           schemeTypes.add(schemeType);
        }
        */
        final List<String> schemeTypes = new ArrayList<String>();
        List<NonEmptyMultiLangURIType> uris = tsl.getSchemeTypes();
        for (NonEmptyMultiLangURIType uri : uris) {
            schemeTypes.add(uri.getValue());
        }
        addItemRow("Scheme type community rules", schemeTypes, informationTable);

        addItemRow("Issue date", tsl.getListIssueDateTime().toString(), informationTable);
        addItemRow("Next update", tsl.getNextUpdate().toString(), informationTable);
        addItemRow("Historical information period", tsl.getHistoricalInformationPeriod().toString() + " days",
                informationTable);
        addItemRow("Sequence number", tsl.getSequenceNumber().toString(), informationTable);
        addItemRow("Scheme information URIs", tsl.getSchemeInformationUris(), informationTable);

        document.add(informationTable);

        addTitle("Scheme Operator", title1Font, Paragraph.ALIGN_CENTER, 0, 10, document);

        informationTable = createInfoTable();
        addItemRow("Scheme operator name", tsl.getSchemeOperatorName(), informationTable);
        PostalAddressType schemeOperatorPostalAddress = tsl.getSchemeOperatorPostalAddress(Locale.ENGLISH);
        addItemRow("Scheme operator street address", schemeOperatorPostalAddress.getStreetAddress(),
                informationTable);
        addItemRow("Scheme operator postal code", schemeOperatorPostalAddress.getPostalCode(),
                informationTable);
        addItemRow("Scheme operator locality", schemeOperatorPostalAddress.getLocality(), informationTable);
        addItemRow("Scheme operator state", schemeOperatorPostalAddress.getStateOrProvince(), informationTable);
        addItemRow("Scheme operator country", schemeOperatorPostalAddress.getCountryName(), informationTable);

        List<String> schemeOperatorElectronicAddressess = tsl.getSchemeOperatorElectronicAddresses();
        addItemRow("Scheme operator contact", schemeOperatorElectronicAddressess, informationTable);
        document.add(informationTable);

        addTitle("Trust Service Providers", title1Font, Paragraph.ALIGN_CENTER, 10, 2, document);

        List<TrustServiceProvider> trustServiceProviders = tsl.getTrustServiceProviders();
        for (TrustServiceProvider trustServiceProvider : trustServiceProviders) {
            addTitle(trustServiceProvider.getName(), title1Font, Paragraph.ALIGN_LEFT, 10, 2, document);

            PdfPTable providerTable = createInfoTable();
            addItemRow("Service provider trade name", trustServiceProvider.getTradeNames(), providerTable);
            addItemRow("Information URI", trustServiceProvider.getInformationUris(), providerTable);
            PostalAddressType postalAddress = trustServiceProvider.getPostalAddress();
            addItemRow("Service provider street address", postalAddress.getStreetAddress(), providerTable);
            addItemRow("Service provider postal code", postalAddress.getPostalCode(), providerTable);
            addItemRow("Service provider locality", postalAddress.getLocality(), providerTable);
            addItemRow("Service provider state", postalAddress.getStateOrProvince(), providerTable);
            addItemRow("Service provider country", postalAddress.getCountryName(), providerTable);
            document.add(providerTable);

            List<TrustService> trustServices = trustServiceProvider.getTrustServices();
            for (TrustService trustService : trustServices) {
                addTitle(trustService.getName(), title2Font, Paragraph.ALIGN_LEFT, 10, 2, document);
                PdfPTable serviceTable = createInfoTable();
                addItemRow("Type", substringAfter(trustService.getType(), "Svctype/"), serviceTable);
                addItemRow("Status", substringAfter(trustService.getStatus(), "Svcstatus/"), serviceTable);
                addItemRow("Status starting time", trustService.getStatusStartingTime().toString(),
                        serviceTable);
                document.add(serviceTable);

                addTitle("Service digital identity (X509)", title3Font, Paragraph.ALIGN_LEFT, 2, 0, document);
                final X509Certificate certificate = trustService.getServiceDigitalIdentity();
                final PdfPTable serviceIdentityTable = createInfoTable();
                addItemRow("Version", Integer.toString(certificate.getVersion()), serviceIdentityTable);
                addItemRow("Serial number", certificate.getSerialNumber().toString(), serviceIdentityTable);
                addItemRow("Signature algorithm", certificate.getSigAlgName(), serviceIdentityTable);
                addItemRow("Issuer", certificate.getIssuerX500Principal().toString(), serviceIdentityTable);
                addItemRow("Valid from", certificate.getNotBefore().toString(), serviceIdentityTable);
                addItemRow("Valid to", certificate.getNotAfter().toString(), serviceIdentityTable);
                addItemRow("Subject", certificate.getSubjectX500Principal().toString(), serviceIdentityTable);
                addItemRow("Public key", certificate.getPublicKey().toString(), serviceIdentityTable);
                // TODO certificate policies
                addItemRow("Subject key identifier", toHex(getSKId(certificate)), serviceIdentityTable);
                addItemRow("CRL distribution points", getCrlDistributionPoints(certificate),
                        serviceIdentityTable);
                addItemRow("Authority key identifier", toHex(getAKId(certificate)), serviceIdentityTable);
                addItemRow("Key usage", getKeyUsage(certificate), serviceIdentityTable);
                addItemRow("Basic constraints", getBasicConstraints(certificate), serviceIdentityTable);

                byte[] encodedCertificate;
                try {
                    encodedCertificate = certificate.getEncoded();
                } catch (CertificateEncodingException e) {
                    throw new RuntimeException("cert: " + e.getMessage(), e);
                }
                addItemRow("SHA1 Thumbprint", DigestUtils.shaHex(encodedCertificate), serviceIdentityTable);
                addItemRow("SHA256 Thumbprint", DigestUtils.sha256Hex(encodedCertificate),
                        serviceIdentityTable);
                document.add(serviceIdentityTable);

                //add Scheme service definition 
                if (null != trustService.getSchemeServiceDefinitionURI()) {
                    addTitle("Scheme Service Definition URI", title3Font, Paragraph.ALIGN_LEFT, 2, 0, document);
                    final PdfPTable schemeServiceDefinitionURITabel = createInfoTable();
                    for (NonEmptyMultiLangURIType uri : trustService.getSchemeServiceDefinitionURI().getURI()) {
                        addItemRow(uri.getLang(), uri.getValue(), schemeServiceDefinitionURITabel);
                    }
                    document.add(schemeServiceDefinitionURITabel);
                }

                List<ExtensionType> extensions = trustService.getExtensions();
                for (ExtensionType extension : extensions) {
                    printExtension(extension, document);
                }

                addLongMonoItem("The decoded certificate:", certificate.toString(), document);
                addLongMonoItem("The certificate in PEM format:", toPem(certificate), document);

                ServiceHistoryType serviceHistoryType = trustService.getServiceHistoryInstanceType();

                if (null != serviceHistoryType) {

                    for (ServiceHistoryInstanceType serviceHistoryInstanceType : serviceHistoryType
                            .getServiceHistoryInstance()) {
                        PdfPTable serviceHistoryTable = createInfoTable();

                        //Service approval history information
                        addTitle("Service approval history information", title3Font, Paragraph.ALIGN_LEFT, 10,
                                2, document);

                        // service type identifier
                        //5.6.2 Service name
                        InternationalNamesType i18nServiceName = serviceHistoryInstanceType.getServiceName();
                        String servName = TrustServiceListUtils.getValue(i18nServiceName, Locale.ENGLISH);
                        addItemRow("Name", servName, serviceHistoryTable);
                        //5.6.1 Service type identifier
                        addItemRow("Type", substringAfter(serviceHistoryInstanceType.getServiceTypeIdentifier(),
                                "Svctype/"), serviceHistoryTable);
                        addItemRow("Status", serviceHistoryInstanceType.getServiceStatus(),
                                serviceHistoryTable);
                        //5.6.4 Service previous status
                        addItemRow("Previous status", serviceHistoryInstanceType.getServiceStatus(),
                                serviceHistoryTable);
                        //5.6.5 Previous status starting date and time
                        addItemRow(
                                "Previous starting time", new DateTime(serviceHistoryInstanceType
                                        .getStatusStartingTime().toGregorianCalendar()).toString(),
                                serviceHistoryTable);
                        //5.6.3 Service digital identity
                        final X509Certificate previousCertificate = trustService.getServiceDigitalIdentity(
                                serviceHistoryInstanceType.getServiceDigitalIdentity());

                        document.add(serviceHistoryTable);

                        addTitle("Service digital identity (X509)", title4Font, Paragraph.ALIGN_LEFT, 2, 0,
                                document);

                        final PdfPTable serviceIdentityTableHistory = createInfoTable();
                        addItemRow("Version", Integer.toString(previousCertificate.getVersion()),
                                serviceIdentityTableHistory);
                        addItemRow("Serial number", previousCertificate.getSerialNumber().toString(),
                                serviceIdentityTableHistory);
                        addItemRow("Signature algorithm", previousCertificate.getSigAlgName(),
                                serviceIdentityTableHistory);
                        addItemRow("Issuer", previousCertificate.getIssuerX500Principal().toString(),
                                serviceIdentityTableHistory);
                        addItemRow("Valid from", previousCertificate.getNotBefore().toString(),
                                serviceIdentityTableHistory);
                        addItemRow("Valid to", previousCertificate.getNotAfter().toString(),
                                serviceIdentityTableHistory);
                        addItemRow("Subject", previousCertificate.getSubjectX500Principal().toString(),
                                serviceIdentityTableHistory);
                        addItemRow("Public key", previousCertificate.getPublicKey().toString(),
                                serviceIdentityTableHistory);
                        // TODO certificate policies
                        addItemRow("Subject key identifier", toHex(getSKId(previousCertificate)),
                                serviceIdentityTableHistory);
                        addItemRow("CRL distribution points", getCrlDistributionPoints(previousCertificate),
                                serviceIdentityTableHistory);
                        addItemRow("Authority key identifier", toHex(getAKId(previousCertificate)),
                                serviceIdentityTableHistory);
                        addItemRow("Key usage", getKeyUsage(previousCertificate), serviceIdentityTableHistory);
                        addItemRow("Basic constraints", getBasicConstraints(previousCertificate),
                                serviceIdentityTableHistory);

                        byte[] encodedHistoryCertificate;
                        try {
                            encodedHistoryCertificate = previousCertificate.getEncoded();
                        } catch (CertificateEncodingException e) {
                            throw new RuntimeException("cert: " + e.getMessage(), e);
                        }
                        addItemRow("SHA1 Thumbprint", DigestUtils.shaHex(encodedHistoryCertificate),
                                serviceIdentityTableHistory);
                        addItemRow("SHA256 Thumbprint", DigestUtils.sha256Hex(encodedHistoryCertificate),
                                serviceIdentityTableHistory);
                        document.add(serviceIdentityTableHistory);

                        ExtensionsListType previousExtensions = serviceHistoryInstanceType
                                .getServiceInformationExtensions();
                        if (null != previousExtensions) {
                            for (ExtensionType extension : previousExtensions.getExtension()) {
                                printExtension(extension, document);
                            }
                        }

                        addLongMonoItem("The decoded certificate:", previousCertificate.toString(), document);
                        addLongMonoItem("The certificate in PEM format:", toPem(previousCertificate), document);
                    }
                }
            }
        }

        X509Certificate signerCertificate = tsl.verifySignature();
        if (null != signerCertificate) {
            Paragraph tslSignerTitle = new Paragraph("Trusted List Signer", title1Font);
            tslSignerTitle.setAlignment(Paragraph.ALIGN_CENTER);
            document.add(tslSignerTitle);

            final PdfPTable signerTable = createInfoTable();
            addItemRow("Subject", signerCertificate.getSubjectX500Principal().toString(), signerTable);
            addItemRow("Issuer", signerCertificate.getIssuerX500Principal().toString(), signerTable);
            addItemRow("Not before", signerCertificate.getNotBefore().toString(), signerTable);
            addItemRow("Not after", signerCertificate.getNotAfter().toString(), signerTable);
            addItemRow("Serial number", signerCertificate.getSerialNumber().toString(), signerTable);
            addItemRow("Version", Integer.toString(signerCertificate.getVersion()), signerTable);
            byte[] encodedPublicKey = signerCertificate.getPublicKey().getEncoded();
            addItemRow("Public key SHA1 Thumbprint", DigestUtils.shaHex(encodedPublicKey), signerTable);
            addItemRow("Public key SHA256 Thumbprint", DigestUtils.sha256Hex(encodedPublicKey), signerTable);
            document.add(signerTable);

            addLongMonoItem("The decoded certificate:", signerCertificate.toString(), document);
            addLongMonoItem("The certificate in PEM format:", toPem(signerCertificate), document);
            addLongMonoItem("The public key in PEM format:", toPem(signerCertificate.getPublicKey()), document);
        }

        document.close();
    } catch (DocumentException e) {
        throw new RuntimeException("PDF document error: " + e.getMessage(), e);
    } catch (Exception e) {
        throw new RuntimeException("Exception: " + e.getMessage(), e);
    }
}

From source file:be.fedict.eid.tsl.Tsl2PdfExporter.java

License:Open Source License

private void printExtension(ExtensionType extension, Document document) throws DocumentException {

    List<Object> contentList = extension.getContent();
    for (Object content : contentList) {
        LOG.debug("extension content: " + content.getClass().getName());
        if (content instanceof JAXBElement<?>) {
            JAXBElement<?> element = (JAXBElement<?>) content;
            LOG.debug("QName: " + element.getName());
            if (true == ADDITIONAL_SERVICE_INFORMATION_QNAME.equals(element.getName())) {
                addTitle("Extension (critical: " + extension.isCritical() + ")", title3Font,
                        Paragraph.ALIGN_LEFT, 0, 0, document);
                addTitle("Additional service information", title4Font, Paragraph.ALIGN_LEFT, 0, 0, document);
                AdditionalServiceInformationType additionalServiceInformation = (AdditionalServiceInformationType) element
                        .getValue();/*from   w ww.j a v a 2s  . c  o  m*/
                LOG.debug("information value: " + additionalServiceInformation.getInformationValue());
                NonEmptyMultiLangURIType multiLangUri = additionalServiceInformation.getURI();
                LOG.debug("URI : " + multiLangUri.getValue() + " (language: " + multiLangUri.getLang() + ")");
                document.add(new Paragraph(
                        multiLangUri.getValue().substring(
                                multiLangUri.getValue().indexOf("SvcInfoExt/") + "SvcInfoExt/".length()),
                        this.valueFont));
            } else {
                addTitle("Extension (critical: " + extension.isCritical() + ")", title3Font,
                        Paragraph.ALIGN_LEFT, 0, 0, document);
                addTitle("Qualifications", title4Font, Paragraph.ALIGN_LEFT, 0, 0, document);

                LOG.debug("element namespace: " + element.getName());
                LOG.debug("element name: " + element.getScope());
                if ("http://uri.etsi.org/TrstSvc/SvcInfoExt/eSigDir-1999-93-EC-TrustedList/#"
                        .equals(element.getName().getNamespaceURI())
                        && "Qualifications".equals(element.getName().getLocalPart())) {
                    QualificationsType qualifications = (QualificationsType) element.getValue();
                    List<QualificationElementType> qualificationElements = qualifications
                            .getQualificationElement();
                    for (QualificationElementType qualificationElement : qualificationElements) {
                        QualifiersType qualifiers = qualificationElement.getQualifiers();
                        List<QualifierType> qualifierList = qualifiers.getQualifier();
                        for (QualifierType qualifier : qualifierList) {
                            document.add(new Paragraph(
                                    "Qualifier: " + qualifier.getUri().substring(
                                            qualifier.getUri().indexOf("SvcInfoExt/") + "SvcInfoExt/".length()),
                                    this.valueFont));
                        }

                        CriteriaListType criteriaList = qualificationElement.getCriteriaList();
                        String description = criteriaList.getDescription();
                        if (null != description) {
                            document.add(new Paragraph("Criterial List Description", this.labelFont));
                            document.add(new Paragraph(description, this.valueFont));
                        }
                        document.add(new Paragraph("Assert: " + criteriaList.getAssert(), this.valueFont));
                        List<PoliciesListType> policySet = criteriaList.getPolicySet();
                        for (PoliciesListType policiesList : policySet) {
                            List<ObjectIdentifierType> oids = policiesList.getPolicyIdentifier();
                            for (ObjectIdentifierType oid : oids) {
                                document.add(new Paragraph("Policy OID: " + oid.getIdentifier().getValue(),
                                        this.valueFont));
                            }
                        }
                    }
                }

            }

        } else if (content instanceof Element) {
            addTitle("Qualifications", title4Font, Paragraph.ALIGN_LEFT, 0, 0, document);
            Element element = (Element) content;
            LOG.debug("element namespace: " + element.getNamespaceURI());
            LOG.debug("element name: " + element.getLocalName());
            if ("http://uri.etsi.org/TrstSvc/SvcInfoExt/eSigDir-1999-93-EC-TrustedList/#"
                    .equals(element.getNamespaceURI()) && "Qualifications".equals(element.getLocalName())) {
                try {
                    QualificationsType qualifications = unmarshallQualifications(element);
                    List<QualificationElementType> qualificationElements = qualifications
                            .getQualificationElement();
                    for (QualificationElementType qualificationElement : qualificationElements) {
                        QualifiersType qualifiers = qualificationElement.getQualifiers();
                        List<QualifierType> qualifierList = qualifiers.getQualifier();
                        for (QualifierType qualifier : qualifierList) {
                            document.add(new Paragraph(
                                    "Qualifier: " + qualifier.getUri().substring(
                                            qualifier.getUri().indexOf("SvcInfoExt/") + "SvcInfoExt/".length()),
                                    this.valueFont));
                        }

                        CriteriaListType criteriaList = qualificationElement.getCriteriaList();
                        String description = criteriaList.getDescription();
                        if (null != description) {
                            document.add(new Paragraph("Criterial List Description", this.labelFont));
                            document.add(new Paragraph(description, this.valueFont));
                        }
                        document.add(new Paragraph("Assert: " + criteriaList.getAssert(), this.valueFont));
                        List<PoliciesListType> policySet = criteriaList.getPolicySet();
                        for (PoliciesListType policiesList : policySet) {
                            List<ObjectIdentifierType> oids = policiesList.getPolicyIdentifier();
                            for (ObjectIdentifierType oid : oids) {
                                document.add(new Paragraph("Policy OID: " + oid.getIdentifier().getValue(),
                                        this.valueFont));
                            }
                        }
                    }
                } catch (JAXBException e) {
                    LOG.error("JAXB error: " + e.getMessage(), e);
                }
            }
        }
    }
}

From source file:be.fedict.eid.tsl.Tsl2PdfExporter.java

License:Open Source License

protected void addItemRow(final String label, final Iterable<String> values, final PdfPTable table) {
    if (values != null) {
        boolean nonEmpty = false;
        final PdfPCell valueCell = new PdfPCell();
        valueCell.setBorder(0);//from w  ww  . j  av a  2 s.c  om
        for (String s : values) {
            valueCell.addElement(new Paragraph(s, valueFont));
            nonEmpty = true;
        }
        if (nonEmpty) {
            table.addCell(new Phrase(label, labelFont));
            table.addCell(valueCell);
        }
    }
}