Example usage for org.jfree.chart ChartUtilities writeChartAsPNG

List of usage examples for org.jfree.chart ChartUtilities writeChartAsPNG

Introduction

In this page you can find the example usage for org.jfree.chart ChartUtilities writeChartAsPNG.

Prototype

public static void writeChartAsPNG(OutputStream out, JFreeChart chart, int width, int height)
        throws IOException 

Source Link

Document

Writes a chart to an output stream in PNG format.

Usage

From source file:com.afunms.report.abstraction.ExcelReport1.java

/**
 * @author HONGLI oracleword/*w w  w  . j ava  2  s.  c om*/
 * @param filename
 * @throws DocumentException
 * @throws IOException
 */
public void createReportOracleCldDoc(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        RtfWriter2.getInstance(document, new FileOutputStream(filename));
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String typename = (String) reportHash.get("typename");
        String runstr = (String) reportHash.get("runstr");
        String grade = (String) reportHash.get("grade");
        String pingnow = (String) reportHash.get("pingnow");
        String pingmin = (String) reportHash.get("pingmin");
        String pingconavg = (String) reportHash.get("pingconavg");
        DBVo vo = (DBVo) reportHash.get("vo");
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        // 
        Table dbTable = new Table(5);
        float[] cellWidths = { 220f, 220f, 220f, 220f, 220f };
        dbTable.setWidths(cellWidths);
        dbTable.setWidth(100); //  90%
        dbTable.setAlignment(Element.ALIGN_CENTER);// 
        dbTable.setAutoFillEmptyCells(true); // 
        dbTable.setBorderWidth(1); // 
        dbTable.setBorderColor(new Color(0, 125, 255)); // 
        dbTable.setPadding(2);// 
        dbTable.setSpacing(0);// 
        dbTable.setBorder(2);// 
        dbTable.endHeaders();
        Cell dbCell = null;
        dbCell = new Cell(new Phrase("", titleFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("IP", titleFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(vo.getDbName(), contextFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(ip, contextFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(typename, contextFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(runstr, contextFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(grade, contextFont));
        dbCell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        dbCell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbTable.addCell(dbCell);

        Table aTable = new Table(3);
        float[] widths = { 220f, 220f, 220f };
        aTable.setWidths(widths);
        aTable.setWidth(100); //  90%
        aTable.setAlignment(Element.ALIGN_CENTER);// 
        aTable.setAutoFillEmptyCells(true); // 
        aTable.setBorderWidth(1); // 
        aTable.setBorderColor(new Color(0, 125, 255)); // 
        aTable.setPadding(2);// 
        aTable.setSpacing(0);// 
        aTable.setBorder(2);// 
        aTable.endHeaders();
        Cell cell = null;
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingnow + "%", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingmin + "%", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingconavg + "%", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        // 
        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        img.setAbsolutePosition(0, 0);
        img.setAlignment(Image.LEFT);// 
        document.add(dbTable);
        document.add(aTable);
        document.add(img);
        document.add(new Paragraph("\n"));

        //  
        Table dbInfoTable = new Table(6);
        float[] dbInfoWidths = { 220f, 220f, 220f, 220f, 220f, 220f };
        dbInfoTable.setWidths(dbInfoWidths);
        dbInfoTable.setWidth(100); //  90%
        dbInfoTable.setAlignment(Element.ALIGN_CENTER);// 
        dbInfoTable.setAutoFillEmptyCells(true); // 
        dbInfoTable.setBorderWidth(1); // 
        dbInfoTable.setBorderColor(new Color(0, 125, 255)); // 
        dbInfoTable.setPadding(2);// 
        dbInfoTable.setSpacing(0);// 
        dbInfoTable.setBorder(2);// 
        cell = new Cell(new Phrase("", titleFont));
        cell.setColspan(6);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        String buffercache = "0";// 
        String dictionarycache = "0";// 
        String librarycache = "0";// 
        String pctmemorysorts = "0";// 
        String pctbufgets = "0";// 10
        String opencurstr = "0";// 
        Hashtable memPerfValue = (Hashtable) reportHash.get("memPerfValue");
        Hashtable memValue = (Hashtable) reportHash.get("memValue");
        Hashtable cursors = (Hashtable) reportHash.get("cursors");
        if (cursors == null) {
            cursors = new Hashtable();
        }
        if (memPerfValue == null)
            memPerfValue = new Hashtable();
        if (memPerfValue != null) {
            if (memPerfValue.containsKey("buffercache") && memPerfValue.get("buffercache") != null) {
                buffercache = (String) memPerfValue.get("buffercache") + "%";
            }
            if (memPerfValue.containsKey("dictionarycache") && memPerfValue.get("dictionarycache") != null) {
                dictionarycache = (String) memPerfValue.get("dictionarycache") + "%";
            }
            if (memPerfValue.containsKey("librarycache") && memPerfValue.get("librarycache") != null) {
                librarycache = (String) memPerfValue.get("librarycache") + "%";
            }
            if (memPerfValue.containsKey("pctmemorysorts") && memPerfValue.get("pctmemorysorts") != null) {
                pctmemorysorts = (String) memPerfValue.get("pctmemorysorts") + "%";
            }
            if (memPerfValue.containsKey("pctbufgets") && memPerfValue.get("pctbufgets") != null) {
                pctbufgets = (String) memPerfValue.get("pctbufgets") + "%";
            }
            if (cursors.containsKey("opencur") && cursors.get("opencur") != null) {
                opencurstr = (String) cursors.get("opencur");
            }
        }
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("10", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(buffercache, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(dictionarycache, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(librarycache, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(pctmemorysorts, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(pctbufgets, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(opencurstr, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        dbInfoTable.addCell(cell);
        document.add(dbInfoTable);

        // 
        String[] sysItem1 = { "shared_pool", "large_pool", "DEFAULT_buffer_cache", "java_pool" };
        String[] sysItemch1 = { "", "", "", "Java" };
        String[] sysItem2 = { "aggregate_PGA_target_parameter", "total_PGA_allocated",
                "maximum_PGA_allocated" };
        String[] sysItemch2 = { "PGA", "PGA", "PGA" };
        Table ncTable = new Table(7);
        float[] ncWidths = { 220f, 220f, 220f, 220f, 220f, 220f, 220f };
        // HONGLI MODIFY END1
        ncTable.setWidths(ncWidths);
        ncTable.setWidth(100); //  90%
        ncTable.setAlignment(Element.ALIGN_CENTER);// 
        ncTable.setAutoFillEmptyCells(true); // 
        ncTable.setBorderWidth(1); // 
        ncTable.setBorderColor(new Color(0, 125, 255)); // 
        ncTable.setPadding(2);// 
        ncTable.setSpacing(0);// 
        ncTable.setBorder(2);// 
        cell = new Cell(new Phrase("", titleFont));
        cell.setColspan(7);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch2[0], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch2[1], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch2[2], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch1[0], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch1[1], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch1[2], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch1[3], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem2[0]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem2[1]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem2[2]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem1[0]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem1[1]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem1[2]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem1[3]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        document.add(ncTable);

        // HONGLI MODIFY START1 
        Table aTable1 = new Table(11);
        float[] width = { 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f };
        // HONGLI MODIFY END1
        aTable1.setWidths(width);
        aTable1.setWidth(100); //  90%
        aTable1.setAlignment(Element.ALIGN_CENTER);// 
        aTable1.setAutoFillEmptyCells(true); // 
        aTable1.setBorderWidth(1); // 
        aTable1.setBorderColor(new Color(0, 125, 255)); // 
        aTable1.setPadding(2);// 
        aTable1.setSpacing(0);// 
        aTable1.setBorder(2);// 
        cell = new Cell(new Phrase("", titleFont));
        cell.setColspan(11);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        // HONGLI ADD START1
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        // HONGLI ADD END1

        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        // aTable1.endHeaders();

        // 
        Vector tableinfo_v = (Vector) reportHash.get("tableinfo_v");

        // HONGLI ADD START2
        Hashtable dbio = (Hashtable) reportHash.get("dbio");
        // HONGLI ADD END2

        int row = 0;
        for (int i = 0; i < tableinfo_v.size(); i++) {
            Hashtable ht = (Hashtable) tableinfo_v.get(i);
            String _filename = ht.get("file_name").toString();
            String tablespace = ht.get("tablespace").toString();
            String size = ht.get("size_mb").toString();
            String free = ht.get("free_mb").toString();
            String percent = ht.get("percent_free").toString();
            String status = ht.get("status").toString();

            // HONGLI ADD START3
            String pyr = "";
            String pbr = "";
            String pyw = "";
            String pbw = "";
            if (dbio.containsKey(_filename)) {
                Hashtable iodetail = (Hashtable) dbio.get(_filename);
                if (iodetail != null && iodetail.size() > 0) {
                    pyr = (String) iodetail.get("pyr");
                    pbr = (String) iodetail.get("pbr");
                    pyw = (String) iodetail.get("pyw");
                    pbw = (String) iodetail.get("pbw");
                }
            }
            // HONGLI ADD END3

            row = i + 1;
            String rowStr = "" + row;
            cell = new Cell(new Phrase(rowStr, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(_filename, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(tablespace, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(size, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(free, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(percent, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);

            // HONGLI ADD START4
            cell = new Cell(new Phrase(pyr, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(pbr, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(pyw, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(pbw, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            // HONGLI ADD END4

            cell = new Cell(new Phrase(status, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);

        }
        document.add(aTable1);

        //    
        Table evenInfoTable = new Table(2);
        float[] evenInfoWidths = { 220f, 220f };
        evenInfoTable.setWidths(evenInfoWidths);
        evenInfoTable.setWidth(100); //  90%
        evenInfoTable.setAlignment(Element.ALIGN_CENTER);// 
        evenInfoTable.setAutoFillEmptyCells(true); // 
        evenInfoTable.setBorderWidth(1); // 
        evenInfoTable.setBorderColor(new Color(0, 125, 255)); // 
        evenInfoTable.setPadding(2);// 
        evenInfoTable.setSpacing(0);// 
        evenInfoTable.setBorder(2);// 
        String downnum = (String) reportHash.get("downnum");
        String count = String.valueOf(reportHash.get("count"));
        cell = new Cell(new Phrase("", titleFont));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase(downnum, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        evenInfoTable.addCell(cell);
        cell = new Cell(new Phrase(count, contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        evenInfoTable.addCell(cell);
        document.add(evenInfoTable);

        addEventListToDoc(document, titleFont, contextFont);

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        document.close();
    } catch (Exception e) {
        // SysLogger.error("Error in ExcelReport.createReport()",e);
        SysLogger.error("", e);
    }

}

From source file:com.afunms.report.abstraction.ExcelReport1.java

/**
 * @author HONGLI oraclepdf// w w w  .  ja v a 2  s.co  m
 * @param filename
 * @throws DocumentException
 * @throws IOException
 */
public void createReportOracleCldPdf(String filename, String type) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        if ("pdf".equals(type)) {
            PdfWriter.getInstance(document, new FileOutputStream(filename));
        } else {
            RtfWriter2.getInstance(document, new FileOutputStream(filename));
        }
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String typename = (String) reportHash.get("typename");
        String runstr = (String) reportHash.get("runstr");
        String grade = (String) reportHash.get("grade");
        String pingnow = (String) reportHash.get("pingnow");
        String pingmin = (String) reportHash.get("pingmin");
        String pingconavg = (String) reportHash.get("pingconavg");
        DBVo vo = (DBVo) reportHash.get("vo");
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        document.add(new Paragraph("\n"));
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        // 
        Table dbTable = new Table(5);
        this.setTableFormat(dbTable);
        Cell dbCell = null;
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("IP", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(dbCell, true);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(vo.getDbName(), contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(ip, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(typename, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(runstr, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);
        dbCell = new Cell(new Phrase(grade, contextFont));
        this.setCellFormat(dbCell, false);
        dbTable.addCell(dbCell);

        Table aTable = new Table(3);
        this.setTableFormat(aTable);
        // float[] widths = { 220f, 220f, 220f };
        // aTable.setWidths(widths);
        // aTable.setWidthPercentage(100);
        Cell cell = null;
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingnow + "%", contextFont));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingmin + "%", contextFont));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);
        cell = new Cell(new Phrase(pingconavg + "%", contextFont));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);

        // 
        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        // img.setAbsolutePosition(0, 0);
        img.scalePercent(76);
        img.setAlignment(Image.MIDDLE);// 
        document.add(dbTable);
        document.add(new Paragraph("\n"));
        document.add(aTable);
        document.add(img);
        document.add(new Paragraph("\n"));

        //  
        Table dbInfoTable = new Table(6);
        this.setTableFormat(dbInfoTable);
        // float[] dbInfoWidths = { 220f, 220f, 220f, 220f, 220f, 220f };
        // dbInfoTable.setWidths(dbInfoWidths);
        // dbInfoTable.setWidthPercentage(100);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        cell.setColspan(6);
        dbInfoTable.addCell(cell);
        String buffercache = "0";// 
        String dictionarycache = "0";// 
        String librarycache = "0";// 
        String pctmemorysorts = "0";// 
        String pctbufgets = "0";// 10
        String opencurstr = "0";// 
        Hashtable memPerfValue = (Hashtable) reportHash.get("memPerfValue");
        Hashtable memValue = (Hashtable) reportHash.get("memValue");
        Hashtable cursors = (Hashtable) reportHash.get("cursors");
        if (cursors == null) {
            cursors = new Hashtable();
        }
        if (memPerfValue == null)
            memPerfValue = new Hashtable();
        if (memPerfValue != null) {
            if (memPerfValue.containsKey("buffercache") && memPerfValue.get("buffercache") != null) {
                buffercache = (String) memPerfValue.get("buffercache") + "%";
            }
            if (memPerfValue.containsKey("dictionarycache") && memPerfValue.get("dictionarycache") != null) {
                dictionarycache = (String) memPerfValue.get("dictionarycache") + "%";
            }
            if (memPerfValue.containsKey("librarycache") && memPerfValue.get("librarycache") != null) {
                librarycache = (String) memPerfValue.get("librarycache") + "%";
            }
            if (memPerfValue.containsKey("pctmemorysorts") && memPerfValue.get("pctmemorysorts") != null) {
                pctmemorysorts = (String) memPerfValue.get("pctmemorysorts") + "%";
            }
            if (memPerfValue.containsKey("pctbufgets") && memPerfValue.get("pctbufgets") != null) {
                pctbufgets = (String) memPerfValue.get("pctbufgets") + "%";
            }
            if (cursors.containsKey("opencur") && cursors.get("opencur") != null) {
                opencurstr = (String) cursors.get("opencur");
            }
        }
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase("10", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(" ", titleFont));
        this.setCellFormat(cell, true);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(buffercache, contextFont));
        this.setCellFormat(cell, false);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(dictionarycache, contextFont));
        this.setCellFormat(cell, false);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(librarycache, contextFont));
        this.setCellFormat(cell, false);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(pctmemorysorts, contextFont));
        this.setCellFormat(cell, false);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(pctbufgets, contextFont));
        this.setCellFormat(cell, false);
        dbInfoTable.addCell(cell);
        cell = new Cell(new Phrase(opencurstr, contextFont));
        this.setCellFormat(cell, false);
        dbInfoTable.addCell(cell);
        document.add(dbInfoTable);
        document.add(new Paragraph("\n"));

        // 
        String[] sysItem1 = { "shared_pool", "large_pool", "DEFAULT_buffer_cache", "java_pool" };
        String[] sysItemch1 = { "", "", "", "Java" };
        String[] sysItem2 = { "aggregate_PGA_target_parameter", "total_PGA_allocated",
                "maximum_PGA_allocated" };
        String[] sysItemch2 = { "PGA", "PGA", "PGA" };
        Table ncTable = new Table(7);
        this.setTableFormat(ncTable);
        // float[] ncWidths = { 220f, 220f, 220f, 220f, 220f, 220f, 220f };
        // HONGLI MODIFY END1
        // ncTable.setWidths(ncWidths);
        // ncTable.setWidthPercentage(100);
        cell = new Cell(new Phrase("", titleFont));
        cell.setColspan(7);
        this.setCellFormat(cell, true);
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch2[0], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch2[1], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch2[2], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch1[0], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch1[1], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch1[2], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(sysItemch1[3], titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem2[0]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem2[1]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem2[2]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem1[0]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem1[1]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem1[2]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        cell = new Cell(new Phrase(memValue.get(sysItem1[3]) + "MB", contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        ncTable.addCell(cell);
        document.add(ncTable);
        document.add(new Paragraph("\n"));

        // HONGLI MODIFY START1 
        Table aTable1 = new Table(11);
        float[] arg0 = { 10f, 20f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f, 10f };
        aTable1.setWidths(arg0);
        this.setTableFormat(aTable1);
        cell = new Cell(new Phrase("", titleFont));
        cell.setColspan(11);
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        // HONGLI ADD START1
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        // HONGLI ADD END1

        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        // aTable1.endHeaders();

        // 
        Vector tableinfo_v = (Vector) reportHash.get("tableinfo_v");

        // HONGLI ADD START2
        Hashtable dbio = (Hashtable) reportHash.get("dbio");
        // HONGLI ADD END2

        int row = 0;
        for (int i = 0; i < tableinfo_v.size(); i++) {
            Hashtable ht = (Hashtable) tableinfo_v.get(i);
            String _filename = ht.get("file_name").toString();
            String tablespace = ht.get("tablespace").toString();
            String size = ht.get("size_mb").toString();
            String free = ht.get("free_mb").toString();
            String percent = ht.get("percent_free").toString();
            String status = ht.get("status").toString();

            // HONGLI ADD START3
            String pyr = "";
            String pbr = "";
            String pyw = "";
            String pbw = "";
            if (dbio.containsKey(_filename)) {
                Hashtable iodetail = (Hashtable) dbio.get(_filename);
                if (iodetail != null && iodetail.size() > 0) {
                    pyr = (String) iodetail.get("pyr");
                    pbr = (String) iodetail.get("pbr");
                    pyw = (String) iodetail.get("pyw");
                    pbw = (String) iodetail.get("pbw");
                }
            }
            // HONGLI ADD END3

            row = i + 1;
            String rowStr = "" + row;
            cell = new Cell(new Phrase(rowStr, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(_filename, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(tablespace, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(size, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(free, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(percent, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);

            // HONGLI ADD START4
            cell = new Cell(new Phrase(pyr, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(pbr, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(pyw, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase(pbw, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            // HONGLI ADD END4

            cell = new Cell(new Phrase(status, contextFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);

        }
        document.add(aTable1);

        // 
        document.add(new Paragraph("\n"));
        Table eventTable = new Table(2);
        this.setTableFormat(eventTable);
        cell = new Cell(new Phrase("", titleFont));
        cell.setColspan(2);
        this.setCellFormat(cell, true);
        eventTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        eventTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        eventTable.addCell(cell);
        cell = new Cell(new Phrase((String) reportHash.get("downnum"), contextFont));
        this.setCellFormat(cell, false);
        eventTable.addCell(cell);
        cell = new Cell(new Phrase(reportHash.get("count") + "", contextFont));
        this.setCellFormat(cell, false);
        eventTable.addCell(cell);
        document.add(eventTable);

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        document.add(new Paragraph("\n"));
        // 
        addEventLisToPdf(document);
        document.close();
    } catch (Exception e) {
        // SysLogger.error("Error in ExcelReport.createReport()",e);
        SysLogger.error("", e);
    }

}

From source file:com.afunms.report.abstraction.ExcelReport1.java

/**
 * @author HONGLI oracleexcel/* w  ww.j  a v a 2s  .  com*/
 * @param filename
 * @throws DocumentException
 * @throws IOException
 */
public void createReportOracleCldExcel(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;
        return;
    }
    WritableWorkbook wb = null;
    try {
        fileName = ResourceCenter.getInstance().getSysPath() + filename;
        wb = Workbook.createWorkbook(new File(fileName));

        String[] sysItem1 = { "shared_pool", "large_pool", "DEFAULT_buffer_cache", "java_pool" };
        String[] sysItemch1 = { "", "", "", "Java" };
        String[] sysItem2 = { "aggregate_PGA_target_parameter", "total_PGA_allocated",
                "maximum_PGA_allocated" };
        String[] sysItemch2 = { "PGA", "PGA", "PGA" };
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        WritableSheet sheet = wb.createSheet(hostname + "", 0);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");
        String typename = (String) reportHash.get("typename");
        String runstr = (String) reportHash.get("runstr");
        String grade = (String) reportHash.get("grade");
        String pingnow = (String) reportHash.get("pingnow");
        String pingmin = (String) reportHash.get("pingmin");
        String pingconavg = (String) reportHash.get("pingconavg");
        DBVo vo = (DBVo) reportHash.get("vo");
        String buffercache = "0";// 
        String dictionarycache = "0";// 
        String librarycache = "0";// 
        String pctmemorysorts = "0";// 
        String pctbufgets = "0";// 10
        String opencurstr = "0";// 
        Hashtable memPerfValue = (Hashtable) reportHash.get("memPerfValue");
        Hashtable memValue = (Hashtable) reportHash.get("memValue");
        Hashtable cursors = (Hashtable) reportHash.get("cursors");
        if (cursors == null) {
            cursors = new Hashtable();
        }
        if (memPerfValue == null)
            memPerfValue = new Hashtable();
        if (memPerfValue != null) {
            if (memPerfValue.containsKey("buffercache") && memPerfValue.get("buffercache") != null) {
                buffercache = (String) memPerfValue.get("buffercache") + "%";
            }
            if (memPerfValue.containsKey("dictionarycache") && memPerfValue.get("dictionarycache") != null) {
                dictionarycache = (String) memPerfValue.get("dictionarycache") + "%";
            }
            if (memPerfValue.containsKey("librarycache") && memPerfValue.get("librarycache") != null) {
                librarycache = (String) memPerfValue.get("librarycache") + "%";
            }
            if (memPerfValue.containsKey("pctmemorysorts") && memPerfValue.get("pctmemorysorts") != null) {
                pctmemorysorts = (String) memPerfValue.get("pctmemorysorts") + "%";
            }
            if (memPerfValue.containsKey("pctbufgets") && memPerfValue.get("pctbufgets") != null) {
                pctbufgets = (String) memPerfValue.get("pctbufgets") + "%";
            }
            if (cursors.containsKey("opencur") && cursors.get("opencur") != null) {
                opencurstr = (String) cursors.get("opencur");
            }
        }

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        // WritableFont labelFont = new
        // WritableFont(WritableFont.createFont(""), 12,
        // WritableFont.BOLD, false);
        // WritableCellFormat labelFormat = new
        // WritableCellFormat(labelFont);
        //
        // WritableCellFormat _labelFormat = new WritableCellFormat();
        // _labelFormat.setBackground(jxl.format.Colour.GRAY_25);
        //
        // WritableCellFormat p_labelFormat = new WritableCellFormat();
        // p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE);
        //
        // WritableCellFormat b_labelFormat = new WritableCellFormat();
        // b_labelFormat.setBackground(jxl.format.Colour.GRAY_50);

        Label tmpLabel = null;
        tmpLabel = new Label(0, 0, hostname + "", labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp(), labelFormat1);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 2, ": " + starttime + "  " + totime, labelFormat1);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, 0, 10, 0);
        sheet.mergeCells(0, 1, 10, 1);
        sheet.mergeCells(0, 2, 10, 2);
        // ip
        tmpLabel = new Label(0, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 4, "IP", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(6, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(8, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, 4, 1, 4);
        sheet.mergeCells(2, 4, 3, 4);
        sheet.mergeCells(4, 4, 5, 4);
        sheet.mergeCells(6, 4, 7, 4);
        sheet.mergeCells(8, 4, 10, 4);
        tmpLabel = new Label(0, 5, vo.getDbName(), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 5, ip, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, 5, typename, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(6, 5, runstr, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(8, 5, grade, p_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, 5, 1, 5);
        sheet.mergeCells(2, 5, 3, 5);
        sheet.mergeCells(4, 5, 5, 5);
        sheet.mergeCells(6, 5, 7, 5);
        sheet.mergeCells(8, 5, 10, 5);

        // 
        tmpLabel = new Label(0, 7, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 7, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(6, 7, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, 7, 2, 7);
        sheet.mergeCells(3, 7, 5, 7);
        sheet.mergeCells(6, 7, 10, 7);
        tmpLabel = new Label(0, 8, pingnow + "%", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 8, pingmin + "%", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(6, 8, pingconavg + "%", p_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, 8, 2, 8);
        sheet.mergeCells(3, 8, 5, 8);
        sheet.mergeCells(6, 8, 10, 8);

        // 
        File file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip
                + "ConnectUtilization" + ".png");
        // sheet,0,0,5,1,,,
        // allRow = allRow+2;
        sheet.addImage(new WritableImage(0, 9, 11, 8, file));
        // allRow = allRow+7;
        int row = 17;

        // 
        tmpLabel = new Label(0, row, "   ", labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(7, row, "10", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(9, row, " ", b_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(1, row, 2, row);
        sheet.mergeCells(3, row, 4, row);
        sheet.mergeCells(5, row, 6, row);
        sheet.mergeCells(7, row, 8, row);
        sheet.mergeCells(9, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, buffercache, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, dictionarycache, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, row, librarycache, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, pctmemorysorts, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(7, row, pctbufgets, p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(9, row, opencurstr, p_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(1, row, 2, row);
        sheet.mergeCells(3, row, 4, row);
        sheet.mergeCells(5, row, 6, row);
        sheet.mergeCells(7, row, 8, row);
        sheet.mergeCells(9, row, 10, row);

        // 
        row = row + 2;
        tmpLabel = new Label(0, row, "", labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, sysItemch2[0], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, sysItemch2[1], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, row, sysItemch2[2], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, row, sysItemch1[0], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, sysItemch1[1], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(7, row, sysItemch1[2], b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(9, row, sysItemch1[3], b_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(3, row, 4, row);
        sheet.mergeCells(5, row, 6, row);
        sheet.mergeCells(7, row, 8, row);
        sheet.mergeCells(9, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, memValue.get(sysItem2[0]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, memValue.get(sysItem2[1]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, row, memValue.get(sysItem2[2]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, row, memValue.get(sysItem1[0]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, memValue.get(sysItem1[1]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(7, row, memValue.get(sysItem1[2]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(9, row, memValue.get(sysItem1[3]) + "MB", p_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(3, row, 4, row);
        sheet.mergeCells(5, row, 6, row);
        sheet.mergeCells(7, row, 8, row);
        sheet.mergeCells(9, row, 10, row);

        // 
        row = row + 2;
        tmpLabel = new Label(0, row, "", labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, row, "MB", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, row, "MB", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);

        // HONGLI ADD START1
        tmpLabel = new Label(6, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(7, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(8, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(9, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        // HONGLI ADD END1

        // HONGLI MODIFY START1
        tmpLabel = new Label(10, row, "", b_labelFormat);
        // HONGLI MODIFY END1

        sheet.addCell(tmpLabel);

        // 
        row = row++;
        Vector tableinfo_v = (Vector) reportHash.get("tableinfo_v");

        // HONGLI ADD START2
        Hashtable dbio = (Hashtable) reportHash.get("dbio");
        // HONGLI ADD END2

        for (int i = 0; i < tableinfo_v.size(); i++) {
            p_labelFormat = super.colorChange(i);
            Hashtable ht = (Hashtable) tableinfo_v.get(i);
            String _filename = ht.get("file_name").toString();
            String tablespace = ht.get("tablespace").toString();
            String size = ht.get("size_mb").toString();
            String free = ht.get("free_mb").toString();
            String percent = ht.get("percent_free").toString();
            String status = ht.get("status").toString();

            // HONGLI ADD START3
            String pyr = "";
            String pbr = "";
            String pyw = "";
            String pbw = "";
            if (dbio.containsKey(_filename)) {
                Hashtable iodetail = (Hashtable) dbio.get(_filename);
                if (iodetail != null && iodetail.size() > 0) {
                    pyr = (String) iodetail.get("pyr");
                    pbr = (String) iodetail.get("pbr");
                    pyw = (String) iodetail.get("pyw");
                    pbw = (String) iodetail.get("pbw");
                }
            }
            // HONGLI ADD END3

            tmpLabel = new Label(0, row, String.valueOf(i + 1), p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(1, row, _filename, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(2, row, tablespace, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(3, row, size, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(4, row, free, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(5, row, percent, p_labelFormat);
            sheet.addCell(tmpLabel);

            // HONGLI ADD START4
            tmpLabel = new Label(6, row, pyr, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(7, row, pbr, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(8, row, pyw, p_labelFormat);
            sheet.addCell(tmpLabel);
            tmpLabel = new Label(9, row, pbw, p_labelFormat);
            sheet.addCell(tmpLabel);
            // HONGLI ADD END4

            tmpLabel = new Label(10, row, status, p_labelFormat);
            sheet.addCell(tmpLabel);
            row++;

        }
        //    
        row = row + 2;
        tmpLabel = new Label(0, row, "     ", labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, " ", b_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 4, row);
        sheet.mergeCells(5, row, 10, row);
        row++;
        tmpLabel = new Label(0, row, (String) reportHash.get("downnum"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(5, row, reportHash.get("count") + "", p_labelFormat);
        sheet.addCell(tmpLabel);
        sheet.mergeCells(0, row, 4, row);
        sheet.mergeCells(5, row, 10, row);

        // 
        addEventListToExcel(sheet, row);

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray());
            sheet.addImage(wi);
        }
        wb.write();
    } catch (Exception e) {
        SysLogger.error("Error in ExcelReport.createReport()", e);
    } finally {
        try {
            if (wb != null)
                wb.close();
        } catch (Exception e) {
            SysLogger.error("", e);
        }
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

/**
 * MODIFY HONGLI 2010-10-27//from   w w w  .  j ava2s.  co m
 */
public void createReport_oraPDF(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        Font contextFont1 = new Font(bfChinese, 11, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont1);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        document.add(new Paragraph("\n"));
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        PdfPTable aTable = new PdfPTable(3);
        float[] widths = { 220f, 220f, 220f };
        aTable.setWidths(widths);
        aTable.setWidthPercentage(100);
        PdfPCell cell = null;
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("pingnow")));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("pingmax")));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("avgpingcon")));
        this.setCellFormat(cell, false);
        aTable.addCell(cell);

        // 
        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        img.setAlignment(Image.MIDDLE);// 
        img.scalePercent(76);
        document.add(aTable);
        document.add(img);
        document.add(new Paragraph("\n"));
        // HONGLI MODIFY START1
        PdfPTable aTable1 = new PdfPTable(12);
        float[] width = { 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f, 220f };
        // HONGLI MODIFY END1
        aTable1.setWidths(width);
        aTable1.setWidthPercentage(100);
        aTable1.setHeaderRows(1);
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("MB", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("MB", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        // HONGLI ADD START1
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        // HONGLI ADD END1
        cell = new PdfPCell(new Phrase("", titleFont));
        this.setCellFormat(cell, true);
        aTable1.addCell(cell);
        // aTable1.endHeaders();

        // 
        Vector tableinfo_v = (Vector) reportHash.get("tableinfo_v");

        // HONGLI ADD START2
        Hashtable dbio = (Hashtable) reportHash.get("dbio");
        // HONGLI ADD END2

        int row = 0;
        for (int i = 0; i < tableinfo_v.size(); i++) {
            Hashtable ht = (Hashtable) tableinfo_v.get(i);
            String _filename = ht.get("file_name").toString();
            String tablespace = ht.get("tablespace").toString();
            String size = ht.get("size_mb").toString();
            String free = ht.get("free_mb").toString();
            String percent = ht.get("percent_free").toString();
            String status = ht.get("status").toString();

            // HONGLI ADD START3
            String pyr = "";
            String pbr = "";
            String pyw = "";
            String pbw = "";
            if (dbio.containsKey(_filename)) {
                Hashtable iodetail = (Hashtable) dbio.get(_filename);
                if (iodetail != null && iodetail.size() > 0) {
                    pyr = (String) iodetail.get("pyr");
                    pbr = (String) iodetail.get("pbr");
                    pyw = (String) iodetail.get("pyw");
                    pbw = (String) iodetail.get("pbw");
                }
            }
            // HONGLI ADD END3

            aTable1.addCell(new Phrase(""));
            row = i + 1;
            String rowStr = "" + row;
            cell = new PdfPCell(new Phrase(rowStr));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new PdfPCell(new Phrase(_filename));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new PdfPCell(new Phrase(tablespace));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new PdfPCell(new Phrase(size));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new PdfPCell(new Phrase(free));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new PdfPCell(new Phrase(percent));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            // HONGLI ADD START4
            cell = new PdfPCell(new Phrase(pyr));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new PdfPCell(new Phrase(pbr));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new PdfPCell(new Phrase(pyw));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new PdfPCell(new Phrase(pbw));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            // HONGLI ADD END4
            cell = new PdfPCell(new Phrase(status));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);

        }

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        document.add(aTable1);
        document.close();
    } catch (Exception e) {
        // SysLogger.error("Error in ExcelReport.createReport()",e);
        SysLogger.error("", e);
    }

}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_sql(String filename) {
    if (impReport.getTable() == null) {
        fileName = null;//from   w w  w.  ja  va 2s  .co m
        return;
    }
    WritableWorkbook wb = null;
    try {
        // fileName = ResourceCenter.getInstance().getSysPath() +
        // "temp\\dhcnms_report.xls";
        // fileName = CommonAppUtil.getAppName() +
        // "/temp/hostnms_report.xls";
        fileName = ResourceCenter.getInstance().getSysPath() + filename;
        wb = Workbook.createWorkbook(new File(fileName));

        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        WritableSheet sheet = wb.createSheet(hostname + "", 0);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        WritableFont labelFont = new WritableFont(WritableFont.createFont(""), 12, WritableFont.BOLD,
                false);
        WritableCellFormat labelFormat = new WritableCellFormat(labelFont);

        WritableCellFormat _labelFormat = new WritableCellFormat();
        _labelFormat.setBackground(jxl.format.Colour.GRAY_25);

        WritableCellFormat p_labelFormat = new WritableCellFormat();
        p_labelFormat.setBackground(jxl.format.Colour.ICE_BLUE);

        WritableCellFormat b_labelFormat = new WritableCellFormat();
        b_labelFormat.setBackground(jxl.format.Colour.GRAY_50);

        Label tmpLabel = null;
        tmpLabel = new Label(1, 0, hostname + "", labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 2, ": " + starttime + "  " + totime);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(0, 4, "", b_labelFormat);
        sheet.addCell(tmpLabel);

        tmpLabel = new Label(1, 4, "", _labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 4, "", _labelFormat);
        sheet.addCell(tmpLabel);

        tmpLabel = new Label(0, 5, (String) maxping.get("pingnow"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 5, (String) maxping.get("pingmax"), p_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 5, (String) maxping.get("avgpingcon"), p_labelFormat);
        sheet.addCell(tmpLabel);

        // 
        File file = new File(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip
                + "ConnectUtilization" + ".png");
        // sheet,0,0,5,1,,,
        // allRow = allRow+2;
        sheet.addImage(new WritableImage(1, 6, 7, 7, file));
        // allRow = allRow+7;

        tmpLabel = new Label(0, 14, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(1, 14, "", b_labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(2, 14, "MB", _labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(3, 14, "MB", _labelFormat);
        sheet.addCell(tmpLabel);
        tmpLabel = new Label(4, 14, "", _labelFormat);
        sheet.addCell(tmpLabel);
        int row = 14;

        // 
        Hashtable dbValue = (Hashtable) reportHash.get("tableinfo_v");
        Hashtable alldatabase = new Hashtable();
        if (dbValue.get("database") != null)
            alldatabase = (Hashtable) dbValue.get("database");
        Vector names = new Vector();
        if (dbValue.get("names") != null)
            names = (Vector) dbValue.get("names");

        if (alldatabase != null && alldatabase.size() > 0) {
            if (names == null)
                names = new Vector();
            for (int i = 0; i < names.size(); i++) {
                String key = (String) names.get(i);
                if (alldatabase.get(key) == null)
                    continue;
                Hashtable data = (Hashtable) alldatabase.get(key);
                String dbname = data.get("dbname").toString();
                String size = data.get("size").toString();
                String usedsize = "";
                if (data.get("usedsize") != null) {
                    usedsize = data.get("usedsize").toString();
                }
                String usedperc = "";
                if (data.get("usedperc") != null)
                    usedperc = data.get("usedperc").toString();
                row = row + 1;
                tmpLabel = new Label(0, row, i + 1 + "", p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(1, row, dbname, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(2, row, size, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(3, row, usedsize, p_labelFormat);
                sheet.addCell(tmpLabel);
                tmpLabel = new Label(4, row, usedperc, p_labelFormat);
                sheet.addCell(tmpLabel);
            }
        }

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            WritableImage wi = new WritableImage(2, 10000 + 5, 8, 12, baos.toByteArray());
            sheet.addImage(wi);
        }
        wb.write();
    } catch (Exception e) {
        // SysLogger.error("Error in ExcelReport.createReport()",e);
        SysLogger.error("", e);
    } finally {
        try {
            if (wb != null)
                wb.close();
        } catch (Exception e) {
        }
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_sqlDoc(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;/* www.  j  a  va2  s.  c  o  m*/
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        RtfWriter2.getInstance(document, new FileOutputStream(filename));
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        Table aTable = new Table(3);
        float[] widths = { 220f, 220f, 220f };
        aTable.setWidths(widths);
        aTable.setWidth(100); //  90%
        aTable.setAlignment(Element.ALIGN_CENTER);// 
        aTable.setAutoFillEmptyCells(true); // 
        aTable.setBorderWidth(1); // 
        aTable.setBorderColor(new Color(0, 125, 255)); // 
        aTable.setPadding(2);// 
        aTable.setSpacing(0);// 
        aTable.setBorder(2);// 
        aTable.endHeaders();
        Cell cell = null;
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase((String) maxping.get("pingnow"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase((String) maxping.get("pingmax"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase((String) maxping.get("avgpingcon"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        // 

        document.add(aTable);
        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        img.setAlignment(Image.LEFT);//
        document.add(img);

        document.add(new Paragraph("\n"));
        Table aTable1 = new Table(6);
        float[] width = { 220f, 220f, 220f, 220f, 220f, 220f };
        aTable1.setWidths(width);
        aTable1.setWidth(100); //  90%
        aTable1.setAlignment(Element.ALIGN_CENTER);// 
        aTable1.setAutoFillEmptyCells(true); // 
        aTable1.setBorderWidth(1); // 
        aTable1.setBorderColor(new Color(0, 125, 255)); // 
        aTable1.setPadding(2);// 
        aTable1.setSpacing(0);// 
        aTable1.setBorder(2);// 

        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("(%)", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        // aTable1.endHeaders();

        // 
        Hashtable dbValue = (Hashtable) reportHash.get("tableinfo_v");
        Hashtable alldatabase = new Hashtable();
        if (dbValue.get("database") != null)
            alldatabase = (Hashtable) dbValue.get("database");
        Vector names = new Vector();
        if (dbValue.get("names") != null)
            names = (Vector) dbValue.get("names");

        if (alldatabase != null && alldatabase.size() > 0) {
            if (names == null)
                names = new Vector();
            int row = 1;
            for (int i = 0; i < names.size(); i++) {
                String key = (String) names.get(i);
                if (alldatabase.get(key) == null)
                    continue;
                Hashtable data = (Hashtable) alldatabase.get(key);
                String dbname = data.get("dbname").toString();
                String size = data.get("size").toString();
                String usedsize = "";
                if (data.get("usedsize") != null) {
                    usedsize = data.get("usedsize").toString();
                }
                String usedperc = "";
                if (data.get("usedperc") != null)
                    usedperc = data.get("usedperc").toString();
                cell = new Cell(new Phrase(""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(row + "", titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(dbname, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(size, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(usedsize, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(usedperc, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                row++;

            }
        }

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        document.add(aTable1);
        document.close();
    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_sqlPDF(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;//from   w  w w  .  j  ava  2s . c  om
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        document.add(new Paragraph("\n"));
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        PdfPTable aTable = new PdfPTable(3);
        float[] widths = { 220f, 220f, 220f };
        aTable.setWidths(widths);
        aTable.setWidthPercentage(100);
        PdfPCell cell = null;
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("pingnow")));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("pingmax")));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("avgpingcon")));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        img.setAlignment(Image.LEFT);//
        //  document.add(aTable);
        img.scalePercent(76);
        document.add(aTable);
        document.add(img);

        document.add(new Paragraph("\n"));
        PdfPTable aTable1 = new PdfPTable(6);
        float[] width = { 220f, 220f, 220f, 220f, 220f, 220f };
        aTable1.setWidths(width);
        aTable1.setWidthPercentage(100);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("(%)", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        // aTable1.endHeaders();

        // 
        Hashtable dbValue = (Hashtable) reportHash.get("tableinfo_v");
        Hashtable alldatabase = new Hashtable();
        if (dbValue.get("database") != null)
            alldatabase = (Hashtable) dbValue.get("database");
        Vector names = new Vector();
        if (dbValue.get("names") != null)
            names = (Vector) dbValue.get("names");

        if (alldatabase != null && alldatabase.size() > 0) {
            if (names == null)
                names = new Vector();
            int row = 1;
            for (int i = 0; i < names.size(); i++) {
                String key = (String) names.get(i);
                if (alldatabase.get(key) == null)
                    continue;
                Hashtable data = (Hashtable) alldatabase.get(key);
                String dbname = data.get("dbname").toString();
                String size = data.get("size").toString();
                String usedsize = "";
                if (data.get("usedsize") != null) {
                    usedsize = data.get("usedsize").toString();
                }
                String usedperc = "";
                if (data.get("usedperc") != null)
                    usedperc = data.get("usedperc").toString();
                cell = new PdfPCell(new Phrase(""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(row + ""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(dbname));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(size));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(usedsize));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(usedperc));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                row++;

            }
        }

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        document.add(aTable1);
        document.close();
    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_sybDoc(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;/* w  ww.j a va 2 s .c om*/
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        RtfWriter2.getInstance(document, new FileOutputStream(filename));
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        Table aTable = new Table(3);
        float[] widths = { 220f, 220f, 220f };
        aTable.setWidths(widths);
        aTable.setWidth(100); //  90%
        aTable.setAlignment(Element.ALIGN_CENTER);// 
        aTable.setAutoFillEmptyCells(true); // 
        aTable.setBorderWidth(1); // 
        aTable.setBorderColor(new Color(0, 125, 255)); // 
        aTable.setPadding(2);// 
        aTable.setSpacing(0);// 
        aTable.setBorder(2);// 
        aTable.endHeaders();
        Cell cell = null;
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell("");
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase((String) maxping.get("pingmax"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase((String) maxping.get("avgpingcon"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        // 
        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        img.setAbsolutePosition(0, 0);
        img.setAlignment(Image.LEFT);// 
        document.add(aTable);
        document.add(img);
        document.add(new Paragraph("\n"));
        Table aTable1 = new Table(6);
        float[] width = { 220f, 220f, 220f, 220f, 220f, 220f };
        aTable1.setWidths(width);
        aTable1.setWidth(100); //  90%
        aTable1.setAlignment(Element.ALIGN_CENTER);// 
        aTable1.setAutoFillEmptyCells(true); // 
        aTable1.setBorderWidth(1); // 
        aTable1.setBorderColor(new Color(0, 125, 255)); // 
        aTable1.setPadding(2);// 
        aTable1.setSpacing(0);// 
        aTable1.setBorder(2);// 

        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new Cell(new Phrase("(%)", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        // aTable1.endHeaders();

        // 
        SybaseVO sysbaseVO = (SybaseVO) reportHash.get("sysbaseVO");
        if (sysbaseVO == null)
            sysbaseVO = new SybaseVO();
        List dbsizelist = (List) sysbaseVO.getDbInfo();
        int row = 1;
        if (dbsizelist != null && dbsizelist.size() > 0) {
            for (int i = 0; i < dbsizelist.size(); i++) {

                TablesVO tablesVO = (TablesVO) dbsizelist.get(i);
                String dbname = tablesVO.getDb_name();
                String dbsize = tablesVO.getDb_size();
                String freesize = tablesVO.getDb_freesize();
                String userdperc = tablesVO.getDb_usedperc();
                cell = new Cell(new Phrase(""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(row + "", titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(dbname, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(dbsize, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(freesize, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(userdperc, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                row = row + 1;

            }
        }

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        document.add(aTable1);
        document.close();
    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_sybPDF(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;//ww  w  . j  a v a2 s .c  o m
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        document.add(new Paragraph("\n"));
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        PdfPTable aTable = new PdfPTable(3);
        float[] widths = { 220f, 220f, 220f };
        aTable.setWidths(widths);
        aTable.setWidthPercentage(100);
        PdfPCell cell = null;
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase(""));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("pingmax")));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new PdfPCell(new Phrase((String) maxping.get("avgpingcon")));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        // 
        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        img.setAlignment(Image.LEFT);// 
        img.scalePercent(76);
        document.add(aTable);
        document.add(img);
        document.add(new Paragraph("\n"));
        PdfPTable aTable1 = new PdfPTable(6);
        float[] width = { 220f, 220f, 220f, 220f, 220f, 220f };
        aTable1.setWidths(width);
        aTable1.setWidthPercentage(100);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("MB", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        cell = new PdfPCell(new Phrase("(%)", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable1.addCell(cell);
        // aTable1.endHeaders();

        // 
        SybaseVO sysbaseVO = (SybaseVO) reportHash.get("sysbaseVO");
        if (sysbaseVO == null)
            sysbaseVO = new SybaseVO();
        List dbsizelist = (List) sysbaseVO.getDbInfo();
        int row = 1;
        if (dbsizelist != null && dbsizelist.size() > 0) {
            for (int i = 0; i < dbsizelist.size(); i++) {

                TablesVO tablesVO = (TablesVO) dbsizelist.get(i);
                String dbname = tablesVO.getDb_name();
                String dbsize = tablesVO.getDb_size();
                String freesize = tablesVO.getDb_freesize();
                String userdperc = tablesVO.getDb_usedperc();
                cell = new PdfPCell(new Phrase(""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(row + ""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(dbname));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(dbsize));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(freesize));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new PdfPCell(new Phrase(userdperc));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                row++;

            }
        }

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        document.add(aTable1);
        document.close();
    } catch (Exception e) {
        // TODO: handle exception
    }
}

From source file:com.afunms.report.abstraction.ExcelReport1.java

public void createReport_db2Doc(String filename) throws DocumentException, IOException {
    if (impReport.getTable() == null) {
        fileName = null;//from ww w.ja  v a2  s  .co m
        return;
    }
    try {
        // 
        Document document = new Document(PageSize.A4);
        // (Writer)document(Writer)
        RtfWriter2.getInstance(document, new FileOutputStream(filename));
        document.open();
        // 
        BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED);
        // 
        Font titleFont = new Font(bfChinese, 12, Font.BOLD);
        // 
        Font contextFont = new Font(bfChinese, 12, Font.NORMAL);
        String hostname = (String) reportHash.get("dbname");
        String servername = (String) reportHash.get("servername");
        String ip = (String) reportHash.get("ip");
        String newip = doip(ip);
        String Ping = (String) reportHash.get("Ping");
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");

        Hashtable maxping = (Hashtable) reportHash.get("ping");
        Hashtable returnhash = (Hashtable) reportHash.get("returnhash");

        Paragraph title = new Paragraph(hostname + "", titleFont);
        // 
        title.setAlignment(Element.ALIGN_CENTER);
        // title.setFont(titleFont);
        document.add(title);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;

        Paragraph context = new Paragraph(contextString, contextFont);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        /*
         * tmpLabel = new Label(0, 1, ":" + impReport.getTimeStamp());
         * sheet.addCell(tmpLabel); tmpLabel = new Label(0, 2, ": " +
         * starttime + "  " + totime);
         */
        Table aTable = new Table(3);
        float[] widths = { 220f, 220f, 220f };
        aTable.setWidths(widths);
        aTable.setWidth(100); //  90%
        aTable.setAlignment(Element.ALIGN_CENTER);// 
        aTable.setAutoFillEmptyCells(true); // 
        aTable.setBorderWidth(1); // 
        aTable.setBorderColor(new Color(0, 125, 255)); // 
        aTable.setPadding(2);// 
        aTable.setSpacing(0);// 
        aTable.setBorder(2);// 
        aTable.endHeaders();
        Cell cell = null;

        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase("", titleFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell("");
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase((String) maxping.get("pingmax"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        cell = new Cell(new Phrase((String) maxping.get("avgpingcon"), contextFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);

        // 

        Image img = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "ConnectUtilization" + ".png");
        img.setAbsolutePosition(0, 0);
        img.setAlignment(Image.LEFT);//
        //  document.add(aTable);

        document.add(aTable);
        document.add(img);

        document.add(new Paragraph("\n"));

        Enumeration dbs = returnhash.keys();
        // List retList = new ArrayList();
        List retList = new ArrayList();
        Paragraph context1 = null;
        Table aTable1 = null;
        while (dbs.hasMoreElements()) {
            aTable1 = new Table(6);
            float[] width = { 220f, 220f, 220f, 220f, 220f, 220f };
            aTable1.setWidths(width);
            aTable1.setWidth(100); //  90%
            aTable1.setAlignment(Element.ALIGN_CENTER);// 
            aTable1.setAutoFillEmptyCells(true); // 
            aTable1.setBorderWidth(1); // 
            aTable1.setBorderColor(new Color(0, 125, 255)); // 
            aTable1.setPadding(2);// 
            aTable1.setSpacing(0);// 
            aTable1.setBorder(2);// 
            String obj = (String) dbs.nextElement();
            retList = (List) returnhash.get(obj);
            String contextString1 = "DB2:" + obj + "(" + "IP:" + ip + ")";

            context1 = new Paragraph(contextString1, contextFont);
            // 
            context1.setAlignment(Element.ALIGN_LEFT);
            // context.setFont(contextFont);
            // 
            context1.setSpacingBefore(5);
            // 
            context1.setFirstLineIndent(5);

            cell = new Cell(new Phrase("", titleFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase("", titleFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase("", titleFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase("MB", titleFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase("MB", titleFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            cell = new Cell(new Phrase("(%)", titleFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
            aTable1.addCell(cell);
            // aTable1.endHeaders();

            // 
            /*
             * Hashtable tableinfo_v = (Hashtable)
             * reportHash.get("tableinfo_v");
             * 
             * String[] dbs1 = servername.split(","); for (int i = 0; i <
             * tableinfo_v.size(); i++) { List list = (List)
             * tableinfo_v.get(dbs1[i]); for (int k = 0; k < list.size();
             * k++) {
             * 
             * row = row + 1; Hashtable ht = (Hashtable) list.get(k); if (ht ==
             * null) continue; String spacename = ""; if
             * (ht.get("tablespace_name") != null) spacename =
             * ht.get("tablespace_name").toString(); String size = ""; if
             * (ht.get("totalspac") != null) size =
             * ht.get("totalspac").toString(); String free = ""; if
             * (ht.get("usablespac") != null) free =
             * ht.get("usablespac").toString(); String percent = "---"; if
             * (ht.get("usableper") != null) percent =
             * ht.get("usableper").toString();
             */
            for (int i = 0; i < retList.size(); i++) {
                Hashtable ht = (Hashtable) retList.get(i);
                if (ht == null)
                    continue;
                String spacename = "";
                if (ht.get("tablespace_name") != null)
                    spacename = ht.get("tablespace_name").toString();
                String size = "";
                if (ht.get("totalspac") != null)
                    size = ht.get("totalspac").toString();
                String free = "";
                if (ht.get("usablespac") != null)
                    free = ht.get("usablespac").toString();
                String percent = "";
                if (ht.get("usableper") != null)
                    percent = ht.get("usableper").toString();
                cell = new Cell(new Phrase(""));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(i + 1 + "", titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(spacename, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(size, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(free, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);
                cell = new Cell(new Phrase(percent, titleFont));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
                aTable1.addCell(cell);

            }
            document.add(context1);
            document.add(aTable1);
        }

        if (impReport.getChart() != null) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ChartUtilities.writeChartAsPNG(baos, impReport.getChart().getChart(),
                        impReport.getChart().getWidth(), impReport.getChart().getHeight());
            } catch (IOException ioe) {
            }
            Image img1 = Image.getInstance(baos.toByteArray());
            img1.setAbsolutePosition(0, 0);
            img1.setAlignment(Image.MIDDLE);// 

            document.add(img1);
        }

        document.close();
    } catch (Exception e) {
        // TODO: handle exception
    }
}