Example usage for com.lowagie.text Table endHeaders

List of usage examples for com.lowagie.text Table endHeaders

Introduction

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

Prototype

public int endHeaders() 

Source Link

Document

Marks the last row of the table headers.

Usage

From source file:QMSMultiQuoteController.java

License:Open Source License

private int doGenerateCartagePDF(String fileName, MultiQuoteFinalDOB finalDOB, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try { //System.out.println("Starting zone PDF Generation------------------------------>");
        DecimalFormat df = new DecimalFormat("###,###,###,##0.00");
        // Added By Kishore Podili For Multi Zone Codes
        MultiQuoteCartageRates pickQuoteCartageRates = null;
        MultiQuoteCartageRates deliQuoteCartageRates = null;
        ArrayList pickUpQuoteCartageRates = null;
        ArrayList deliveryQuoteCartageRates = null;
        Set pickBreaks = null;/*from   w  ww . ja  v a  2 s. c o m*/
        Set deliBreaks = null;
        Set pickUpZoneCodeSet = null;
        Set deliveryZoneCodeSet = null;
        HashMap pickUpZoneCodeMap = null;
        HashMap deliveryZoneCodeMap = null;
        HashMap pickUpZoneZipMap = null;
        HashMap deliveryZoneZipMap = null;
        ArrayList zipList = null;
        ArrayList pickupWeightBreaks = null;
        ArrayList delWeightBreaks = null;
        Iterator zones = null;
        Iterator breaksSet = null;
        int pickupWeightBreaksSize = 0;
        int delWeightBreaksSize = 0;
        HttpSession session = null;
        MultiQuoteFreightLegSellRates legDestCharges = null;
        ArrayList destLaneCharges = finalDOB.getLegDetails();
        int noOfLanes = destLaneCharges.size();
        MultiQuoteMasterDOB masterDOB = finalDOB.getMasterDOB();

        //Added by Kishore For Multiple Zip and Zone Codes

        Document document = null;
        ByteArrayOutputStream baos = null;
        PdfWriter writer = null;

        MultiQuoteHeader headerDOB = finalDOB.getHeaderDOB();

        ArrayList pickupChargeBasisList = null;
        ArrayList delChargeBasisList = null;
        int pickupChargeBasisSize = 0;
        int delChargeBasisSize = 0;

        for (int dc = 0; dc < noOfLanes; dc++) {
            legDestCharges = (MultiQuoteFreightLegSellRates) destLaneCharges.get(dc);
            //Added by Anil.k kishore for Quote Charges
            //if(!"Charges".equalsIgnoreCase(masterDOB.getQuoteWith())){//END
            //Added By Kishore Podili For CartagePDF Quote Add
            //if((masterDOB.getShipperZipCode()!=null && (masterDOB.getShipperZipCode()[dc]==null || "".equals(masterDOB.getShipperZipCode()[dc])))||( masterDOB.getConsigneeZipCode()!=null && (masterDOB.getConsigneeZipCode()[dc]==null || "".equals(masterDOB.getConsigneeZipCode()[dc]))))
            //{
            //Commented By Kishore Podili
            if ((legDestCharges.getPickZoneZipMap() != null && legDestCharges.getPickZoneZipMap().size() > 0)
                    || (legDestCharges.getDeliveryZoneZipMap() != null
                            && legDestCharges.getDeliveryZoneZipMap().size() > 0)) {

                pickUpQuoteCartageRates = legDestCharges.getPickUpCartageRatesList();

                deliveryQuoteCartageRates = legDestCharges.getDeliveryCartageRatesList();
                //Modified By Kishore For MultiZoneCodes
                pickupWeightBreaks = legDestCharges.getPickupWeightBreaks(); //finalDOB.getPickupWeightBreaks();
                delWeightBreaks = legDestCharges.getDeliveryWeightBreaks(); //finalDOB.getDeliveryWeightBreaks();

                if (pickupWeightBreaks != null)
                    pickupWeightBreaksSize = pickupWeightBreaks.size();
                if (delWeightBreaks != null)
                    delWeightBreaksSize = delWeightBreaks.size();

                pickupChargeBasisList = legDestCharges.getPickupChargeBasisList(); //finalDOB.getPickupWeightBreaks();
                delChargeBasisList = legDestCharges.getDelChargeBasisList(); //finalDOB.getDeliveryWeightBreaks();

                if (pickupChargeBasisList != null)
                    pickupChargeBasisSize = pickupChargeBasisList.size();
                if (delChargeBasisList != null)
                    delChargeBasisSize = delChargeBasisList.size();

                //Commented By Kishroe Podili

                //MultiQuoteHeader    headerDOB   =    finalDOB.getHeaderDOB();

                //MultiQuoteMasterDOB masterDOB  =   finalDOB.getMasterDOB();
                ESupplyDateUtility eSupplyDateUtility = new ESupplyDateUtility();
                ESupplyGlobalParameters loginbean = (ESupplyGlobalParameters) request.getSession()
                        .getAttribute("loginbean");
                eSupplyDateUtility.setPatternWithTime("DD-MONTH-YYYY");
                //eSupplyDateUtility.setPatternWithTime(loginbean.getUserPreferences().getDateFormat());
                //@@ Commented and added by subrahmanyam for the pbn issue 212006 on #26-jul-10
                /*          String[] strDate  = eSupplyDateUtility.getDisplayStringArray(headerDOB.getDateOfQuotation());
                String[] effDate  = eSupplyDateUtility.getDisplayStringArray(headerDOB.getEffDate());
                */
                String[] strDate = null;
                String[] effDate = null;
                if ("View".equalsIgnoreCase(request.getParameter("Operation"))) {
                    if ("PDF".equalsIgnoreCase(request.getParameter("PDF"))) {
                        strDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getModifiedDate());
                        effDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getEffDate());
                    } else {
                        strDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getModifiedDate());
                        effDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getCreatedDate());
                    }

                } else {
                    strDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getDateOfQuotation());
                    effDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getEffDate());

                }

                String[] validDate;
                String validUptoStr = "";
                if (headerDOB.getValidUpto() != null) {
                    validDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getValidUpto());
                    validUptoStr = validDate[0];
                }

                StringBuffer attentionTo = new StringBuffer("");
                if (masterDOB.getCustContactNames() != null) {
                    for (int i = 0; i < masterDOB.getCustContactNames().length; i++) {
                        //Logger.info(FILE_NAME,"masterDOB.getCustContactNames()[i]::"+masterDOB.getCustomerContacts()[i]);
                        attentionTo.append(
                                masterDOB.getCustContactNames()[i] != null ? masterDOB.getCustContactNames()[i]
                                        : "");
                        if (i != (masterDOB.getCustContactNames().length - 1))
                            attentionTo.append(",");
                    }
                }

                String chargeRate = null;

                //System.out.println("After getting data------------------------------>"+pickUpQuoteCartageRates.size());

                //Added By Kishore For MultiZone Codes
                Cell cellCountry;
                Chunk chk;
                if (dc == 0) {

                    //document = new Document(PageSize.A4,54f,54f,68.4f,68.4f);//@@ 36 points represent 0.5 inch  
                    document = new Document(PageSize.A4, 10f, 10f, 20f, 20f); //added by silpa on 27-06-11
                    document.addTitle("Approved Report");
                    document.addSubject("Report PDF");
                    document.addKeywords("Test, Key Words");
                    document.addAuthor("DHL");
                    document.addCreator("Auto Generated through 4S DHL");
                    document.addCreationDate();

                    baos = new ByteArrayOutputStream();
                    writer = PdfWriter.getInstance(document, baos);
                    //added by silpa on 27-06-11
                    document.open();
                    PdfContentByte cb = writer.getDirectContent();
                    cb.rectangle(document.left(), document.bottom(), document.right() - document.left(),
                            document.top() - document.bottom());
                    cb.stroke();//ended

                    int[] widths = { 10, 10, 10, 10, 10, 10, 12, 28 };

                    Table mainT = new Table(8);
                    mainT.setWidth(100);
                    mainT.setWidths(widths);
                    mainT.setBorderColor(Color.white);
                    mainT.setPadding(1);
                    mainT.setSpacing(0);

                    Phrase headingPhrase = new Phrase("",
                            FontFactory.getFont("ARIAL", 12, Font.BOLD, Color.BLACK));
                    Cell cellHeading = new Cell(headingPhrase);
                    cellHeading.setBorderColor(new Color(255, 255, 255));
                    cellHeading.setHorizontalAlignment(cellHeading.ALIGN_CENTER);
                    cellHeading.setColspan(7);
                    mainT.addCell(cellHeading);

                    Cell imageCell = new Cell();
                    java.net.URL url = getServletConfig().getServletContext()
                            .getResource("/images/DHLlogo.gif");
                    Image img0 = Image.getInstance(url);
                    //img0.scalePercent(75);
                    imageCell.add(img0);
                    imageCell.setHorizontalAlignment(imageCell.ALIGN_RIGHT);
                    imageCell.setBorderWidth(0);
                    imageCell.setNoWrap(true);
                    imageCell.setColspan(1);
                    mainT.addCell(imageCell);
                    mainT.setAlignment(mainT.ALIGN_CENTER);
                    document.add(mainT);

                    //pickBreaks = pickQuoteCartageRates.getRates().keySet();
                    //System.out.println("After Heading ----------------pickBreaks----------->");            
                    Table partCountry = new Table(1, 4);
                    partCountry.setBorderWidth(0);
                    partCountry.setWidth(100);
                    partCountry.setBorderColor(Color.black);
                    //partCountry.setBackgroundColor(Color.ORANGE);
                    partCountry.setPadding(1);
                    partCountry.setSpacing(1);
                    partCountry.setAutoFillEmptyCells(true);
                    //partCountry.setTableFitsPage(true);
                    partCountry.setAlignment(partCountry.ALIGN_CENTER);
                    // partCountry.setWidth(100.0f);
                    /*Cell cellCountry;
                    Chunk chk;*/

                    chk = new Chunk("ANNEXURE", FontFactory.getFont("ARIAL", 12, Font.BOLD, Color.BLACK));
                    cellCountry = new Cell(chk);
                    cellCountry.setWidth("100");
                    cellCountry.setBorderWidth(0);
                    cellCountry.setNoWrap(true);
                    cellCountry.setLeading(10.0f);
                    cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                    partCountry.addCell(cellCountry);

                    if ("MY".equalsIgnoreCase(masterDOB.getCountryId())) {
                        chk = new Chunk((headerDOB.getOriginCountry() != null
                                ? headerDOB.getOriginCountry()[dc].toUpperCase()
                                : "")
                                + " TO "
                                + (headerDOB.getDestinationCountry() != null
                                        ? headerDOB.getDestinationCountry()[dc].toUpperCase()
                                        : ""),
                                FontFactory.getFont("ARIAL", 16, Font.BOLD, Color.BLUE));
                        cellCountry = new Cell(chk);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);

                        cellCountry = new Cell("");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setLeading(5.0f);
                        partCountry.addCell(cellCountry);

                        chk = new Chunk(headerDOB.getCustomerName(),
                                FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.BLUE));
                        cellCountry = new Cell(chk);
                        cellCountry.setHeader(true);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);
                        //Logger.info(FILE_NAME,"attentionTo.toString():"+attentionTo.toString());

                        chk = new Chunk("ATTENTION TO: " + toTitleCase(attentionTo.toString()),
                                FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.BLUE));
                        cellCountry = new Cell(chk);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);

                        cellCountry = new Cell("");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setLeading(5.0f);
                        partCountry.addCell(cellCountry);
                    } else {
                        chk = new Chunk((headerDOB.getOriginCountry() != null
                                ? headerDOB.getOriginCountry()[dc].toUpperCase()
                                : "")
                                + " TO "
                                + (headerDOB.getDestinationCountry() != null
                                        ? headerDOB.getDestinationCountry()[dc].toUpperCase()
                                        : ""),
                                FontFactory.getFont("ARIAL", 16, Font.BOLD, Color.RED));
                        cellCountry = new Cell(chk);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);

                        cellCountry = new Cell("");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setLeading(5.0f);
                        partCountry.addCell(cellCountry);

                        chk = new Chunk(headerDOB.getCustomerName(),
                                FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.RED));
                        cellCountry = new Cell(chk);
                        cellCountry.setHeader(true);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);
                        //Logger.info(FILE_NAME,"attentionTo.toString():"+attentionTo.toString());

                        chk = new Chunk("ATTENTION TO: " + toTitleCase(attentionTo.toString()),
                                FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.RED));
                        cellCountry = new Cell(chk);
                        cellCountry.setWidth("100");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setNoWrap(true);
                        cellCountry.setLeading(10.0f);
                        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                        partCountry.addCell(cellCountry);

                        cellCountry = new Cell("");
                        cellCountry.setBorderWidth(0);
                        cellCountry.setLeading(5.0f);
                        partCountry.addCell(cellCountry);
                    }
                    chk = new Chunk("QUOTE REFERENCE: " + masterDOB.getQuoteId(),
                            FontFactory.getFont("ARIAL", 12, Font.BOLD, Color.BLACK));
                    cellCountry = new Cell(chk);
                    cellCountry.setWidth("100");
                    cellCountry.setBorderWidth(0);
                    cellCountry.setNoWrap(true);
                    cellCountry.setLeading(10.0f);
                    cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                    partCountry.addCell(cellCountry);
                    chk = new Chunk("DATE OF QUOTATION: " + strDate[0],
                            FontFactory.getFont("ARIAL", 12, Font.BOLD, Color.BLACK));
                    cellCountry = new Cell(chk);
                    cellCountry.setWidth("100");
                    cellCountry.setBorderWidth(0);
                    cellCountry.setNoWrap(true);
                    cellCountry.setLeading(10.0f);
                    cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
                    partCountry.addCell(cellCountry);

                    document.add(partCountry);

                }

                if (dc > 0) {
                    document.newPage();

                }

                Table partZone = null;
                Cell cellZone;

                if (pickUpQuoteCartageRates != null && pickUpQuoteCartageRates.size() > 0) {
                    /*Set keys = null;            
                    for(int i=0;i<pickUpQuoteCartageRates.size();i++)
                    {              
                      if(i==0)
                      { 
                        pickBreaks = new TreeSet();//@@This is needed as only a new Set Implementation obj supports addAll() 
                      }
                      pickQuoteCartageRates = (QuoteCartageRates) pickUpQuoteCartageRates.get(i);
                      keys = pickQuoteCartageRates.getRates().keySet();
                      pickBreaks.addAll(keys);
                    }*/

                    //if(pickBreaks!=null && pickBreaks.size()>0)
                    //if(pickupWeightBreaks != null && pickupWeightBreaksSize>0)
                    partZone = new Table(pickupWeightBreaksSize + 2);
                    partZone.setOffset(30);
                    partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
                    partZone.setBorderWidth(1);
                    partZone.setBorderColor(Color.black);
                    partZone.setPadding(1);
                    partZone.setSpacing(1);
                    partZone.setAutoFillEmptyCells(true);
                    partZone.setWidth(100);
                    //partZone.setTableFitsPage(true);
                    //@@ Added by subrahmanyam for the enhancement #147062 on 09/12/2008
                    chk = new Chunk("PICKUP CARTAGE RATES AT: " + headerDOB.getOriginLocName()[dc],
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
                    cellZone = new Cell(chk);
                    cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setLeading(10.0f);
                    cellZone.setBackgroundColor(Color.WHITE);
                    cellZone.setColspan(pickupWeightBreaksSize + 2);
                    partZone.addCell(cellZone);
                    //@@ Ended by subrahmanyam for the enhancement #147062 on 09/12/2008
                    chk = new Chunk("PICKUP CARTAGE RATES",
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setLeading(10.0f);
                    cellZone.setBackgroundColor(Color.ORANGE);
                    cellZone.setColspan(pickupWeightBreaksSize + 2);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    //cellZone.setNoWrap(true);
                    cellZone.setLeading(8.0f);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Currency", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setLeading(8.0f);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);
                    //breaksSet = pickBreaks.iterator();  // logger.info("breaksSetbreaksSet::"+breaksSet);
                    /*while(breaksSet.hasNext())
                    {              
                      chk = new Chunk((String)breaksSet.next(),FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                      cellZone = new Cell(chk);              
                      cellZone.setNoWrap(true);
                      cellZone.setHeader(true);
                      partZone.addCell(cellZone);
                    }*/
                    //if(pickupWeightBreaks!=null)
                    //{
                    //logger.info("pickupWeightBreaks"+pickupWeightBreaks);
                    for (int i = 0; i < pickupWeightBreaksSize; i++) {
                        chk = new Chunk((String) pickupWeightBreaks.get(i),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        //cellZone.setNoWrap(true);
                        cellZone.setLeading(8.0f);
                        cellZone.setHeader(true);
                        cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                        partZone.addCell(cellZone);
                    }
                    //}
                    partZone.endHeaders();

                    chk = new Chunk("");
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    // cellZone.setHeader(true);
                    // cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    chk = new Chunk("");
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setHeader(true);
                    //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    for (int i = 0; i < pickupChargeBasisSize; i++) {
                        chk = new Chunk(toTitleCase((String) pickupChargeBasisList.get(i)),
                                FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        //cellZone.setNoWrap(true);
                        cellZone.setLeading(8.0f);
                        cellZone.setHeader(true);
                        //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                        partZone.addCell(cellZone);
                    }

                    int pikupQuoteCartRatSize = pickUpQuoteCartageRates.size();
                    label0: for (int i = 0; i < pikupQuoteCartRatSize; i++) {
                        pickQuoteCartageRates = (MultiQuoteCartageRates) pickUpQuoteCartageRates.get(i); // By Kishore For Multiple Zone Code
                        chk = new Chunk(pickQuoteCartageRates.getZone(),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);            
                        partZone.addCell(cellZone);

                        chk = new Chunk(pickQuoteCartageRates.getCurrency(),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);            
                        partZone.addCell(cellZone);

                        pickUpZoneCodeMap = pickQuoteCartageRates.getRates();

                        /*breaksSet = pickBreaks.iterator();
                        while(breaksSet.hasNext())
                         {
                           String wBreak = (String)breaksSet.next();
                           if(pickUpZoneCodeMap.containsKey(wBreak))
                           {
                            chargeRate = (String)pickUpZoneCodeMap.get(wBreak);
                            chargeRate  = df.format(Double.parseDouble(chargeRate));
                           }
                           else
                           {
                            chargeRate = "--";              
                           }
                          chk = new Chunk(chargeRate,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                          cellZone = new Cell(chk);
                          cellZone.setNoWrap(true);            
                          partZone.addCell(cellZone); 
                         }*/

                        // ------------------------------------------------------  //added by Brahmaiah.R on 31/5/2012 for WPBN issue 304241
                        if (pickupWeightBreaks == null) {
                            continue;
                        }
                        String wBreak = null;
                        int k = 0;
                        do {
                            if (k >= pickupWeightBreaksSize) {
                                continue label0;
                            }
                            wBreak = (String) pickupWeightBreaks.get(k);
                            if (wBreak != null && pickUpZoneCodeMap.containsKey(wBreak)) {
                                chargeRate = (String) pickUpZoneCodeMap.get(wBreak);
                                chargeRate = df.format(Double.parseDouble(chargeRate));
                            } else {
                                chargeRate = "--";
                            }
                            chk = new Chunk(chargeRate, FontFactory.getFont("ARIAL", 8F, 1, Color.BLACK));
                            cellZone = new Cell(chk);
                            cellZone.setLeading(8F);
                            partZone.addCell(cellZone);
                            k++;
                        } while (true);
                    }
                    document.add(partZone);
                }
                if (deliveryQuoteCartageRates != null && deliveryQuoteCartageRates.size() > 0) {
                    /*Set dkeys         = null;
                    for(int i=0;i<deliveryQuoteCartageRates.size();i++)
                    {       
                     if(i==0)
                     { 
                       deliBreaks = new TreeSet();//@@This is needed as only a new Set Implementation obj supports addAll() 
                     }
                     deliQuoteCartageRates = (QuoteCartageRates) deliveryQuoteCartageRates.get(i);
                     dkeys = deliQuoteCartageRates.getRates().keySet();
                     deliBreaks.addAll(dkeys);
                     //System.out.println("Before zone header------------------------------>"+deliBreaks);
                     //System.out.println("Before zone header------------------------------>"+deliBreaks.size());              
                    }*/

                    partZone = new Table(delWeightBreaksSize + 2);
                    partZone.setOffset(30);
                    partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
                    partZone.setBorderWidth(1);
                    partZone.setWidth(100);
                    partZone.setBorderColor(Color.black);
                    partZone.setPadding(1);
                    partZone.setSpacing(1);
                    partZone.setAutoFillEmptyCells(true);
                    //partZone.setTableFitsPage(true);
                    //@@ Added by subrahmanyam for the enhancement #147062 on 08/12/2008
                    chk = new Chunk("DELIVERY CARTAGE RATES AT: " + headerDOB.getDestLocName()[dc],
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
                    cellZone = new Cell(chk);
                    cellZone.setNoWrap(true);
                    cellZone.setLeading(10.0f);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.WHITE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setColspan(delWeightBreaksSize + 2);
                    partZone.addCell(cellZone);
                    //@@ Ended by subrahmanyam for the enhancement #147062 on 08/12/2008
                    chk = new Chunk("DELIVERY CARTAGE RATES",
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setNoWrap(true);
                    cellZone.setLeading(10.0f);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.ORANGE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setColspan(delWeightBreaksSize + 2);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Currency", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    //breaksSet = deliBreaks.iterator();

                    /*while(breaksSet.hasNext())
                    {              
                      String breaks = (String)breaksSet.next();
                            
                      chk = new Chunk(breaks,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                      cellZone = new Cell(chk);              
                      cellZone.setNoWrap(true);
                      cellZone.setHeader(true);
                      partZone.addCell(cellZone);
                    }*/
                    for (int i = 0; i < delWeightBreaksSize; i++) {
                        chk = new Chunk((String) delWeightBreaks.get(i),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);
                        cellZone.setHeader(true);
                        cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                        partZone.addCell(cellZone);
                    }
                    partZone.endHeaders();

                    chk = new Chunk("");
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setHeader(true);
                    //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    chk = new Chunk("");
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setHeader(true);
                    //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);

                    for (int i = 0; i < delChargeBasisSize; i++) {
                        chk = new Chunk(toTitleCase((String) delChargeBasisList.get(i)),
                                FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        //cellZone.setNoWrap(true);
                        cellZone.setLeading(8.0f);
                        cellZone.setHeader(true);
                        //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                        partZone.addCell(cellZone);
                    }

                    int delQuoteCartRtSize = deliveryQuoteCartageRates.size();
                    for (int i = 0; i < delQuoteCartRtSize; i++) {
                        deliQuoteCartageRates = (MultiQuoteCartageRates) deliveryQuoteCartageRates.get(i); // By Kishore For Multiple Zone Code

                        chk = new Chunk(deliQuoteCartageRates.getZone(),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);            
                        partZone.addCell(cellZone);

                        chk = new Chunk(deliQuoteCartageRates.getCurrency(),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);            
                        partZone.addCell(cellZone);
                        // String charge_type=deliQuoteCartageRates.getBuyOrSellRate();  //@@Added by kiran.v

                        deliveryZoneCodeMap = deliQuoteCartageRates.getRates();

                        //breaksSet = deliBreaks.iterator();
                        /*while(breaksSet.hasNext())
                         {
                           String wBreak = (String)breaksSet.next();
                           if(deliveryZoneCodeMap.containsKey(wBreak))
                           {
                            chargeRate = (String)deliveryZoneCodeMap.get(wBreak);  
                            chargeRate  = df.format(Double.parseDouble(chargeRate));
                           }
                           else
                           {
                            chargeRate = "--";              
                           }
                          chk = new Chunk(chargeRate,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                          cellZone = new Cell(chk);
                          cellZone.setNoWrap(true);            
                          partZone.addCell(cellZone); 
                         }*/
                        String wBreak = null;
                        for (int k = 0; k < delWeightBreaksSize; k++) {
                            wBreak = (String) delWeightBreaks.get(k);
                            if (wBreak != null && deliveryZoneCodeMap.containsKey(wBreak)) {
                                chargeRate = (String) deliveryZoneCodeMap.get(wBreak);
                                chargeRate = df.format(Double.parseDouble(chargeRate));
                            } else {
                                chargeRate = "--";
                            }
                            chk = new Chunk(chargeRate,
                                    FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                            cellZone = new Cell(chk);
                            cellZone.setLeading(8.0f);
                            //cellZone.setNoWrap(true);            
                            partZone.addCell(cellZone);
                        }
                    }
                    //System.out.println("After zone header------------------------------>");
                    document.add(partZone);

                }

                pickUpZoneZipMap = legDestCharges.getPickZoneZipMap();
                //@@For Sorting the Zone Codes in an Order.
                List list = new ArrayList();
                Set zoneSet;
                //@@End of Declarations - Sorting
                if (pickUpZoneZipMap != null && pickUpZoneZipMap.size() > 0) {
                    //System.out.println("Before zipCode header--------Set size------->"+pickUpZoneZipMap.keySet().size());
                    //@@Sorting the Zone Codes (as TreeSet implements java.util.SortedSet)
                    list.addAll(pickUpZoneZipMap.keySet());
                    zoneSet = new TreeSet(list);
                    //@@End of Sorting- Added by Yuvraj

                    zones = zoneSet.iterator();

                    partZone = new Table(2);
                    partZone.setOffset(30);
                    partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
                    partZone.setBorderWidth(1);
                    partZone.setBorderColor(Color.black);
                    partZone.setPadding(1);
                    partZone.setSpacing(1);
                    partZone.setWidth(100);
                    //partZone.setAutoFillEmptyCells(true);
                    //partZone.setTableFitsPage(true);
                    //@@ Added by subrahmanyam for the enhancement #147062 on 08/12/2008
                    chk = new Chunk("PICKUP CHARGES AT: " + headerDOB.getOriginLocName()[dc],
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(10.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.WHITE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setColspan(2);
                    partZone.addCell(cellZone);

                    //@@ Ended by subrahmanyam for the enhancement #147062 on  08/12/2008
                    chk = new Chunk("PICKUP ZONE ZIP MAPPING",
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(10.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.ORANGE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setColspan(2);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);
                    chk = new Chunk("Zip Code", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    partZone.addCell(cellZone);
                    partZone.endHeaders();
                    // System.out.println("Before zipCode Body------------------------------>");

                    while (zones.hasNext()) {
                        String zone = (String) zones.next();
                        // System.out.println("zone------------------------------>"+zone);
                        zipList = (ArrayList) pickUpZoneZipMap.get(zone);
                        //System.out.println("zipList--------------------------->"+zipList);
                        int zipListSize = zipList.size();
                        for (int i = 0; i < zipListSize; i++) {
                            //System.out.println("zone for ------------------------------>"+zone);
                            if (zone != null && !zone.equals("null") && zipList.get(i) != null
                                    && !((String) zipList.get(i)).equals("null")) {
                                chk = new Chunk(zone, FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                                cellZone = new Cell(chk);
                                cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                                cellZone.setLeading(8.0f);
                                //cellZone.setNoWrap(true);            
                                partZone.addCell(cellZone);
                                //System.out.println("zipList.get(i)--------------------------->"+(String)zipList.get(i));
                                chk = new Chunk((String) zipList.get(i),
                                        FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                                cellZone = new Cell(chk);
                                cellZone.setLeading(8.0f);
                                cellZone.setNoWrap(true);
                                partZone.addCell(cellZone);
                            }
                        }
                    }
                    document.add(partZone);
                }

                deliveryZoneZipMap = legDestCharges.getDeliveryZoneZipMap();

                list = new ArrayList();
                zoneSet = null;

                if (deliveryZoneZipMap != null && deliveryZoneZipMap.size() > 0) {
                    //System.out.println("Before zipCode header--------Set size------->"+deliveryZoneZipMap.keySet().size());
                    list.addAll(deliveryZoneZipMap.keySet());
                    zoneSet = new TreeSet(list);
                    zones = zoneSet.iterator();

                    partZone = new Table(2);
                    partZone.setOffset(30);
                    partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
                    partZone.setBorderWidth(1);
                    partZone.setBorderColor(Color.black);
                    partZone.setPadding(1);
                    partZone.setSpacing(1);
                    partZone.setWidth(100);
                    //partZone.setAutoFillEmptyCells(true);
                    //partZone.setTableFitsPage(true);
                    //@@ Added by subrahmanyam for the enhancement #147062 on 08/12/2008
                    chk = new Chunk("DELIVERY CHARGES AT: " + headerDOB.getDestLocName()[dc],
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(10.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.WHITE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
                    cellZone.setColspan(2);
                    partZone.addCell(cellZone);
                    //@@ Ended by subrahmanyam for the enhancement #147062 on 08/12/2008 
                    chk = new Chunk("DELIVERY ZONE ZIP MAPPING",
                            FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(10.0f);
                    //cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.ORANGE);
                    cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);

                    cellZone.setColspan(2);
                    partZone.addCell(cellZone);

                    chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);
                    chk = new Chunk("Zip Code", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    cellZone.setNoWrap(true);
                    cellZone.setHeader(true);
                    partZone.addCell(cellZone);
                    partZone.endHeaders();
                    //System.out.println("Before zipCode Body------------------------------>");

                    while (zones.hasNext()) {
                        String zone = (String) zones.next();
                        //System.out.println("zone------------------------------>"+zone);
                        zipList = (ArrayList) deliveryZoneZipMap.get(zone);
                        if (zipList != null) {
                            //System.out.println("zipList--------------------------->"+zipList);
                            //logger.info("zipList--------------------------->"+zipList);
                            int zipListSize = zipList.size();
                            for (int i = 0; i < zipListSize; i++) {
                                //System.out.println("zone for ------------------------------>"+zone);
                                if (zone != null && !zone.equals("null") && zipList.get(i) != null
                                        && !((String) zipList.get(i)).equals("null")) {
                                    chk = new Chunk(zone,
                                            FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                                    cellZone = new Cell(chk);
                                    cellZone.setLeading(8.0f);
                                    cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                                    cellZone.setNoWrap(true);
                                    partZone.addCell(cellZone);
                                    //System.out.println("zipList.get(i)--------------------------->"+(String)zipList.get(i));
                                    chk = new Chunk((String) zipList.get(i),
                                            FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                                    cellZone = new Cell(chk);
                                    cellZone.setLeading(8.0f);
                                    cellZone.setNoWrap(true);
                                    partZone.addCell(cellZone);
                                }
                            }
                        }
                    }
                    document.add(partZone);
                }

                // Commmented by Kishore to move the code after the for loop for Multiple lanes 

                //System.out.println("After zipCode header------------------------------>");

                /*document.close();
                //System.out.println("After     document Close----------------------------------------->");               
                File f = new File("Cartage.pdf");
                FileOutputStream  fileOutputStream= new FileOutputStream(f);
                baos.writeTo(fileOutputStream);
                fileOutputStream.close();//added by sanjay on 20/03/2006
                //@@Added by Kameswari for the WPBN issue-80440
                PdfReader reader = new PdfReader("Cartage.pdf");
                int n = reader.getNumberOfPages();
                File fs = new File(fileName);
                String   space = " ";
                // we create a stamper that will copy the document to a new file
                PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(fs));
                        
                // adding some metadata
                // adding content to each page
                        
                int k = 0;
                PdfContentByte under;
                PdfContentByte over=null;
                BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
                while (k < n) {
                k++;
                   over = stamp.getOverContent(k);
                over.beginText();
                over.setFontAndSize(bf, 8);
                over.setTextMatrix(15, 15);
                over.showText("page " + k+" of "+n);
                        
                if(k>1)
                {
                over.setFontAndSize(bf, 7);
                over.showText("                                                                                                       QUOTE REFERENCE:"+masterDOB.getQuoteId());
                //@@Added by subrahmanyam for the WPBN:146452 on 12/12/2008
                over.endText();
                over.beginText();
                over.showText("                                                                                                                                    CUSTOMER NAME: "+headerDOB.getCustomerName());//subrahmanyam 12/12/2008
                //@@ Ended by subrahmanyam for the WPBM:146452 on 12/12/2008               
                }
                over.endText();
                }
                stamp.close();
                //@@WPBN issue-80440    
                //@@ Commented by subrahmanyam for 146460         
                if("on".equalsIgnoreCase(request.getParameter("print")))
                {
                        
                   request.getSession().setAttribute("CartageOuptutStream",fs);
                }
                //@@ Added by subrahmanyam for  146460                
                        
                 if("on".equalsIgnoreCase(request.getParameter("print"))||"PDF".equalsIgnoreCase(request.getParameter("pdf")))
                {
                           
                   request.getSession().setAttribute("CartageOuptutStream",fs);
                }
                        
                //@@ Ended by subrahmanyam for 146460
                //f.delete();
                baos.close();*/
                //}
            }
            //} //Added by Anil.k   kishore Charges
        }
        //System.out.println("End of generation header------------------------------>");
        //Added By Kishore Podili fpr multiple Zone Codes
        if (document != null) {

            document.close();
            // System.out.println("After document
            // Close----------------------------------------->");
            File f = new File("Cartage.pdf");
            FileOutputStream fileOutputStream = new FileOutputStream(f);
            baos.writeTo(fileOutputStream);
            fileOutputStream.close();// added by sanjay on 20/03/2006
            // @@Added by Kameswari for the WPBN issue-80440
            PdfReader reader = new PdfReader("Cartage.pdf");
            int n = reader.getNumberOfPages();
            File fs = new File(fileName);
            String space = " ";
            // we create a stamper that will copy the document to a new file
            PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(fs));

            // adding some metadata
            // adding content to each page

            int k = 0;
            PdfContentByte under;
            PdfContentByte over = null;
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
            while (k < n) {
                k++;
                over = stamp.getOverContent(k);
                //jyothi
                //over.rectangle(30, 30, 550, 800);
                over.rectangle(document.left(), document.bottom(), document.right() - document.left(),
                        document.top() - document.bottom());
                over.stroke();
                //jyothi
                over.beginText();
                over.setFontAndSize(bf, 8);
                over.setTextMatrix(15, 15);
                over.showText("page " + k + " of " + n);

                if (k > 1) {
                    over.setFontAndSize(bf, 7);
                    over.showText("QUOTE REFERENCE:" + masterDOB.getQuoteId());
                    // @@Added by subrahmanyam for the WPBN:146452 on
                    // 12/12/2008
                    over.endText();
                    over.beginText();
                    over.showText("CUSTOMER NAME: " + headerDOB.getCustomerName());// subrahmanyam
                    // 12/12/2008
                    // @@ Ended by subrahmanyam for the WPBM:146452 on
                    // 12/12/2008
                }
                over.endText();
            }
            stamp.close();
            // @@WPBN issue-80440
            // @@ Commented by subrahmanyam for 146460
            /*
             * if("on".equalsIgnoreCase(request.getParameter("print"))) {
             * 
             * request.getSession().setAttribute("CartageOuptutStream",fs); }
             */
            // @@ Added by subrahmanyam for 146460
            if ("on".equalsIgnoreCase(request.getParameter("print"))
                    || "PDF".equalsIgnoreCase(request.getParameter("pdf"))) {

                request.getSession().setAttribute("CartageOuptutStream", fs);
            }

            // @@ Ended by subrahmanyam for 146460
            // f.delete();
            baos.close();

            // Added by Kishore Podili For Cartage PDF Attachement in the MAIL.  
            FileInputStream fis = new FileInputStream(fileName);
            // PdfReader preader = new PdfReader()
            ArrayList attachmentDOBList = finalDOB.getAttachmentDOBList();

            if (attachmentDOBList == null)
                attachmentDOBList = new ArrayList();

            MultiQuoteAttachmentDOB attachementDOB = new MultiQuoteAttachmentDOB();
            attachementDOB.setFileName(fileName);
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            attachementDOB.setPdfFile(buffer);

            attachmentDOBList.add(attachementDOB);
            finalDOB.setAttachmentDOBList(attachmentDOBList);
            fis.close();
        }

        // System.out.println("End of generation
        // header------------------------------>");
    } catch (Exception e) {
        e.printStackTrace();
        //Logger.error(FILE_NAME,"Error while generating the PDF"+e.toString());
        logger.error(FILE_NAME + "Error while generating the PDF" + e.toString());
        throw new Exception("Error while generating PDF format");
    }
    return 1;
}

From source file:FirstPdf.java

private static void createTable(Section subCatPart) throws BadElementException {
    Table t = new Table(3, 2);
    t.setBorderColor(Color.GRAY);
    t.setPadding(4);/*from ww  w. j a v a2s  . co m*/
    t.setSpacing(4);
    t.setBorderWidth(1);
    Cell c1 = new Cell("Table Header 1");
    c1.setHeader(true);
    t.addCell(c1);
    c1 = new Cell("Table Header 2");
    t.addCell(c1);
    c1 = new Cell("Table Header 3");
    t.addCell(c1);
    t.endHeaders();
    t.addCell("1.0");
    t.addCell("1.1");
    t.addCell("1.2");
    t.addCell("2.1");
    t.addCell("2.2");
    t.addCell("2.3");
    subCatPart.add(t);
}

From source file:QMSQuoteController.java

License:Open Source License

private int doGenerateCartagePDF(String fileName, QuoteFinalDOB finalDOB, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try { //System.out.println("Starting zone PDF Generation------------------------------>");
        DecimalFormat df = new DecimalFormat("###,###,###,##0.00");
        QuoteCartageRates pickQuoteCartageRates = null;
        QuoteCartageRates deliQuoteCartageRates = null;
        ArrayList pickUpQuoteCartageRates = null;
        ArrayList deliveryQuoteCartageRates = null;
        Set pickBreaks = null;//from  w  w  w  .  java 2s  .  c  o m
        Set deliBreaks = null;
        Set pickUpZoneCodeSet = null;
        Set deliveryZoneCodeSet = null;
        HashMap pickUpZoneCodeMap = null;
        HashMap deliveryZoneCodeMap = null;
        HashMap pickUpZoneZipMap = null;
        HashMap deliveryZoneZipMap = null;
        ArrayList zipList = null;
        ArrayList pickupWeightBreaks = null;
        ArrayList delWeightBreaks = null;
        Iterator zones = null;
        Iterator breaksSet = null;
        int pickupWeightBreaksSize = 0;
        int delWeightBreaksSize = 0;
        HttpSession session = null;

        // Added by Kishore Podili For Charge Basis in the CartagePDF
        ArrayList pickupChargeBasisList = null;
        ArrayList delChargeBasisList = null;
        int pickupChargeBasisSize = 0;
        int delChargeBasisSize = 0;

        pickupChargeBasisList = finalDOB.getPickupChargeBasisList();
        delChargeBasisList = finalDOB.getDelChargeBasisList();

        if (pickupChargeBasisList != null)
            pickupChargeBasisSize = pickupChargeBasisList.size();
        if (delChargeBasisList != null)
            delChargeBasisSize = delChargeBasisList.size();

        //End Of Kishore Podili For Charge Basis in the CartagePDF

        pickUpQuoteCartageRates = finalDOB.getPickUpCartageRatesList();

        deliveryQuoteCartageRates = finalDOB.getDeliveryCartageRatesList();
        pickupWeightBreaks = finalDOB.getPickupWeightBreaks();
        // ArrayList pickupWeightBreaksFOr = finalDOB.getOriginChargesList();
        delWeightBreaks = finalDOB.getDeliveryWeightBreaks();

        if (pickupWeightBreaks != null)
            pickupWeightBreaksSize = pickupWeightBreaks.size();
        if (delWeightBreaks != null)
            delWeightBreaksSize = delWeightBreaks.size();

        QuoteHeader headerDOB = finalDOB.getHeaderDOB();
        QuoteMasterDOB masterDOB = finalDOB.getMasterDOB();
        ESupplyDateUtility eSupplyDateUtility = new ESupplyDateUtility();
        ESupplyGlobalParameters loginbean = (ESupplyGlobalParameters) request.getSession()
                .getAttribute("loginbean");
        eSupplyDateUtility.setPatternWithTime("DD-MONTH-YYYY");
        //eSupplyDateUtility.setPatternWithTime(loginbean.getUserPreferences().getDateFormat());
        //@@ Commented and added by subrahmanyam for the pbn issue 212006 on #26-jul-10
        /*          String[] strDate  = eSupplyDateUtility.getDisplayStringArray(headerDOB.getDateOfQuotation());
        String[] effDate  = eSupplyDateUtility.getDisplayStringArray(headerDOB.getEffDate());
        */
        String[] strDate = null;
        String[] effDate = null;
        if ("View".equalsIgnoreCase(request.getParameter("Operation"))) {
            if ("PDF".equalsIgnoreCase(request.getParameter("PDF"))) {
                strDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getModifiedDate());
                effDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getEffDate());
            } else {
                strDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getModifiedDate());
                effDate = eSupplyDateUtility.getDisplayStringArray(masterDOB.getCreatedDate());
            }

        } else {
            strDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getDateOfQuotation());
            effDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getEffDate());

        }

        String[] validDate;
        String validUptoStr = "";
        if (headerDOB.getValidUpto() != null) {
            validDate = eSupplyDateUtility.getDisplayStringArray(headerDOB.getValidUpto());
            validUptoStr = validDate[0];
        }

        StringBuffer attentionTo = new StringBuffer("");
        if (masterDOB.getCustContactNames() != null) {
            for (int i = 0; i < masterDOB.getCustContactNames().length; i++) {
                //Logger.info(FILE_NAME,"masterDOB.getCustContactNames()[i]::"+masterDOB.getCustomerContacts()[i]);
                attentionTo.append(
                        masterDOB.getCustContactNames()[i] != null ? masterDOB.getCustContactNames()[i] : "");
                if (i != (masterDOB.getCustContactNames().length - 1))
                    attentionTo.append(",");
            }
        }

        String chargeRate = null;

        //System.out.println("After getting data------------------------------>"+pickUpQuoteCartageRates.size());
        Document document = new Document(PageSize.A4, 54f, 54f, 68.4f, 68.4f);//@@ 36 points represent 0.5 inch            
        document.addTitle("Approved Report");
        document.addSubject("Report PDF");
        document.addKeywords("Test, Key Words");
        document.addAuthor("DHL");
        document.addCreator("Auto Generated through 4S DHL");
        document.addCreationDate();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.open();

        int[] widths = { 10, 10, 10, 10, 10, 10, 12, 28 };

        Table mainT = new Table(8);
        mainT.setWidth(100);
        mainT.setWidths(widths);
        mainT.setBorderColor(Color.white);
        mainT.setPadding(1);
        mainT.setSpacing(0);

        Phrase headingPhrase = new Phrase("", FontFactory.getFont("ARIAL", 12, Font.BOLD, Color.BLACK));
        Cell cellHeading = new Cell(headingPhrase);
        cellHeading.setBorderColor(new Color(255, 255, 255));
        cellHeading.setHorizontalAlignment(cellHeading.ALIGN_CENTER);
        cellHeading.setColspan(7);
        mainT.addCell(cellHeading);

        Cell imageCell = new Cell();
        java.net.URL url = getServletConfig().getServletContext().getResource("/images/DHLlogo.gif");
        Image img0 = Image.getInstance(url);
        //img0.scalePercent(75);
        imageCell.add(img0);
        imageCell.setHorizontalAlignment(imageCell.ALIGN_RIGHT);
        imageCell.setBorderWidth(0);
        imageCell.setNoWrap(true);
        imageCell.setColspan(1);
        mainT.addCell(imageCell);
        mainT.setAlignment(mainT.ALIGN_CENTER);
        document.add(mainT);

        //pickBreaks = pickQuoteCartageRates.getRates().keySet();
        //System.out.println("After Heading ----------------pickBreaks----------->");            
        Table partCountry = new Table(1, 4);
        partCountry.setBorderWidth(0);
        partCountry.setWidth(100);
        partCountry.setBorderColor(Color.black);
        //partCountry.setBackgroundColor(Color.ORANGE);
        partCountry.setPadding(1);
        partCountry.setSpacing(1);
        partCountry.setAutoFillEmptyCells(true);
        //partCountry.setTableFitsPage(true);
        partCountry.setAlignment(partCountry.ALIGN_CENTER);
        // partCountry.setWidth(100.0f);
        Cell cellCountry;
        Chunk chk;

        chk = new Chunk("ANNEXURE", FontFactory.getFont("ARIAL", 12, Font.BOLD, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
        partCountry.addCell(cellCountry);

        if ("MY".equalsIgnoreCase(masterDOB.getCountryId())) {
            chk = new Chunk(
                    (headerDOB.getOriginCountry() != null ? headerDOB.getOriginCountry().toUpperCase() : "")
                            + " TO "
                            + (headerDOB.getDestinationCountry() != null
                                    ? headerDOB.getDestinationCountry().toUpperCase()
                                    : ""),
                    FontFactory.getFont("ARIAL", 16, Font.BOLD, Color.BLUE));
            cellCountry = new Cell(chk);
            cellCountry.setWidth("100");
            cellCountry.setBorderWidth(0);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(10.0f);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            partCountry.addCell(cellCountry);

            cellCountry = new Cell("");
            cellCountry.setBorderWidth(0);
            cellCountry.setLeading(5.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk(headerDOB.getCustomerName(),
                    FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.BLUE));
            cellCountry = new Cell(chk);
            cellCountry.setHeader(true);
            cellCountry.setWidth("100");
            cellCountry.setBorderWidth(0);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(10.0f);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            partCountry.addCell(cellCountry);
            //Logger.info(FILE_NAME,"attentionTo.toString():"+attentionTo.toString());

            chk = new Chunk("ATTENTION TO: " + attentionTo.toString(),
                    FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.BLUE));
            cellCountry = new Cell(chk);
            cellCountry.setWidth("100");
            cellCountry.setBorderWidth(0);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(10.0f);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            partCountry.addCell(cellCountry);

            cellCountry = new Cell("");
            cellCountry.setBorderWidth(0);
            cellCountry.setLeading(5.0f);
            partCountry.addCell(cellCountry);
        } else {
            chk = new Chunk(
                    (headerDOB.getOriginCountry() != null ? headerDOB.getOriginCountry().toUpperCase() : "")
                            + " TO "
                            + (headerDOB.getDestinationCountry() != null
                                    ? headerDOB.getDestinationCountry().toUpperCase()
                                    : ""),
                    FontFactory.getFont("ARIAL", 16, Font.BOLD, Color.RED));
            cellCountry = new Cell(chk);
            cellCountry.setWidth("100");
            cellCountry.setBorderWidth(0);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(10.0f);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            partCountry.addCell(cellCountry);

            cellCountry = new Cell("");
            cellCountry.setBorderWidth(0);
            cellCountry.setLeading(5.0f);
            partCountry.addCell(cellCountry);

            chk = new Chunk(headerDOB.getCustomerName(),
                    FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.RED));
            cellCountry = new Cell(chk);
            cellCountry.setHeader(true);
            cellCountry.setWidth("100");
            cellCountry.setBorderWidth(0);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(10.0f);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            partCountry.addCell(cellCountry);
            //Logger.info(FILE_NAME,"attentionTo.toString():"+attentionTo.toString());

            chk = new Chunk("ATTENTION TO: " + attentionTo.toString(),
                    FontFactory.getFont("ARIAL", 14, Font.BOLD, Color.RED));
            cellCountry = new Cell(chk);
            cellCountry.setWidth("100");
            cellCountry.setBorderWidth(0);
            cellCountry.setNoWrap(true);
            cellCountry.setLeading(10.0f);
            cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
            partCountry.addCell(cellCountry);

            cellCountry = new Cell("");
            cellCountry.setBorderWidth(0);
            cellCountry.setLeading(5.0f);
            partCountry.addCell(cellCountry);
        }
        chk = new Chunk("QUOTE REFERENCE: " + masterDOB.getQuoteId(),
                FontFactory.getFont("ARIAL", 12, Font.BOLD, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
        partCountry.addCell(cellCountry);
        chk = new Chunk("DATE OF QUOTATION: " + strDate[0],
                FontFactory.getFont("ARIAL", 12, Font.BOLD, Color.BLACK));
        cellCountry = new Cell(chk);
        cellCountry.setWidth("100");
        cellCountry.setBorderWidth(0);
        cellCountry.setNoWrap(true);
        cellCountry.setLeading(10.0f);
        cellCountry.setHorizontalAlignment(cellCountry.ALIGN_CENTER);
        partCountry.addCell(cellCountry);

        document.add(partCountry);

        Table partZone = null;
        Cell cellZone;
        if (pickUpQuoteCartageRates != null && pickUpQuoteCartageRates.size() > 0) {
            /*Set keys = null;            
            for(int i=0;i<pickUpQuoteCartageRates.size();i++)
            {              
              if(i==0)
              { 
                pickBreaks = new TreeSet();//@@This is needed as only a new Set Implementation obj supports addAll() 
              }
              pickQuoteCartageRates = (QuoteCartageRates) pickUpQuoteCartageRates.get(i);
              keys = pickQuoteCartageRates.getRates().keySet();
              pickBreaks.addAll(keys);
            }*/

            //if(pickBreaks!=null && pickBreaks.size()>0)
            //if(pickupWeightBreaks != null && pickupWeightBreaksSize>0)
            partZone = new Table(pickupWeightBreaksSize + 2);
            partZone.setOffset(30);
            partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
            partZone.setBorderWidth(1);
            partZone.setBorderColor(Color.black);
            partZone.setPadding(1);
            partZone.setSpacing(1);
            partZone.setAutoFillEmptyCells(true);
            partZone.setWidth(100);
            //partZone.setTableFitsPage(true);
            //@@ Added by subrahmanyam for the enhancement #147062 on 09/12/2008
            chk = new Chunk("PICKUP CARTAGE RATES AT: " + headerDOB.getOriginLocName(),
                    FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
            cellZone = new Cell(chk);
            cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
            cellZone.setLeading(10.0f);
            cellZone.setBackgroundColor(Color.WHITE);
            cellZone.setColspan(pickupWeightBreaksSize + 2);
            partZone.addCell(cellZone);
            //@@ Ended by subrahmanyam for the enhancement #147062 on 09/12/2008
            chk = new Chunk("PICKUP CARTAGE RATES", FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
            cellZone.setLeading(10.0f);
            cellZone.setBackgroundColor(Color.ORANGE);
            cellZone.setColspan(pickupWeightBreaksSize + 2);
            partZone.addCell(cellZone);

            chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            //cellZone.setNoWrap(true);
            cellZone.setLeading(8.0f);
            cellZone.setHeader(true);
            cellZone.setBackgroundColor(Color.LIGHT_GRAY);
            partZone.addCell(cellZone);

            chk = new Chunk("Currency", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            //cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            cellZone.setLeading(8.0f);
            cellZone.setBackgroundColor(Color.LIGHT_GRAY);
            partZone.addCell(cellZone);
            //breaksSet = pickBreaks.iterator();  // logger.info("breaksSetbreaksSet::"+breaksSet);
            /*while(breaksSet.hasNext())
            {              
              chk = new Chunk((String)breaksSet.next(),FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
              cellZone = new Cell(chk);              
              cellZone.setNoWrap(true);
              cellZone.setHeader(true);
              partZone.addCell(cellZone);
            }*/
            //if(pickupWeightBreaks!=null)
            //{
            //logger.info("pickupWeightBreaks"+pickupWeightBreaks);
            for (int i = 0; i < pickupWeightBreaksSize; i++) {
                chk = new Chunk((String) pickupWeightBreaks.get(i),
                        FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                cellZone = new Cell(chk);
                //cellZone.setNoWrap(true);
                cellZone.setLeading(8.0f);
                cellZone.setHeader(true);
                cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                partZone.addCell(cellZone);
            }

            //Added By Kishore For the ChargeBasis in the Annexure PDF on 06-Jun-11
            chk = new Chunk("");
            cellZone = new Cell(chk);
            cellZone.setLeading(8.0f);
            // cellZone.setHeader(true);
            // cellZone.setBackgroundColor(Color.LIGHT_GRAY);
            partZone.addCell(cellZone);

            chk = new Chunk("");
            cellZone = new Cell(chk);
            cellZone.setLeading(8.0f);
            //cellZone.setHeader(true);
            //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
            partZone.addCell(cellZone);

            for (int i = 0; i < pickupChargeBasisSize; i++)////commented by Brahmaiah.R on 31/5/2012 for WPBN issue 304241
            {
                chk = new Chunk(toTitleCase((String) pickupChargeBasisList.get(i)),
                        FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));

                cellZone = new Cell(chk);
                //cellZone.setNoWrap(true);
                cellZone.setLeading(8.0f);
                cellZone.setHeader(true);
                //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                partZone.addCell(cellZone);
            }
            ////added by Brahmaiah.R on 31/5/2012 for WPBN issue 304241
            /*    for(int J=0;J<originChargesSize;J++)
                {
                  if(originIndices[J] !=-1)
                  {
                  chargesDOB                = (QuoteCharges)originCharges.get(originIndices[J]);
                   logger.info("Origin Charges doPDFGeneration::"+J+":"+chargesDOB); // newly added                  
                  originChargeInfo        = chargesDOB.getChargeInfoList();
                  originChargesInfoSize   = originChargeInfo.size();
                  int m =0;
              String breakPoint = null;
                  for(int k=0;k<originChargesInfoSize;k++)
                  {
                    chargeInfo = (QuoteChargeInfo)originChargeInfo.get(k);
                    String chargeBasis = (String)(chargeInfo.getBasis());
                   // chargeBasis  = df.format(Double.parseDouble(chargeBasis));
                    chk = new Chunk(chargeBasis,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                    cellZone = new Cell(chk);              
                    //cellZone.setNoWrap(true);
                    cellZone.setLeading(8.0f);
                    //cellZone.setHeader(true);
                  //  cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);
                            
                  }
                  }
                }//ended by Brahmaiah .R */
            //Added By Kishore For the ChargeBasis in the Annexure PDF on 06-Jun-11 

            //}
            partZone.endHeaders();
            int pikupQuoteCartRatSize = pickUpQuoteCartageRates.size();
            for (int i = 0; i < pikupQuoteCartRatSize; i++) {
                pickQuoteCartageRates = (QuoteCartageRates) pickUpQuoteCartageRates.get(i);
                chk = new Chunk(pickQuoteCartageRates.getZone(),
                        FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                cellZone = new Cell(chk);
                cellZone.setLeading(8.0f);
                //cellZone.setNoWrap(true);            
                partZone.addCell(cellZone);

                chk = new Chunk(pickQuoteCartageRates.getCurrency(),
                        FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                cellZone = new Cell(chk);
                cellZone.setLeading(8.0f);
                //cellZone.setNoWrap(true);            
                partZone.addCell(cellZone);

                pickUpZoneCodeMap = pickQuoteCartageRates.getRates();
                /*breaksSet = pickBreaks.iterator();
                while(breaksSet.hasNext())
                 {
                   String wBreak = (String)breaksSet.next();
                   if(pickUpZoneCodeMap.containsKey(wBreak))
                   {
                    chargeRate = (String)pickUpZoneCodeMap.get(wBreak);
                    chargeRate  = df.format(Double.parseDouble(chargeRate));
                   }
                   else
                   {
                    chargeRate = "--";              
                   }
                  chk = new Chunk(chargeRate,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                  cellZone = new Cell(chk);
                  cellZone.setNoWrap(true);            
                  partZone.addCell(cellZone); 
                 }*/
                //-------------------------------------------Commented  by Brahmaiah.R on 31/5/2012 for WPBN issue 304241
                if (pickupWeightBreaks != null) {
                    String wBreak = null;
                    for (int k = 0; k < pickupWeightBreaksSize; k++) {
                        wBreak = (String) pickupWeightBreaks.get(k);

                        if (wBreak != null && pickUpZoneCodeMap.containsKey(wBreak)) {
                            chargeRate = (String) pickUpZoneCodeMap.get(wBreak);
                            chargeRate = df.format(Double.parseDouble(chargeRate));

                        } else {
                            chargeRate = "--";
                        }
                        chk = new Chunk(chargeRate, FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);            
                        partZone.addCell(cellZone);
                    }
                }
            }
            ////added by Brahmaiah.R on 31/5/2012 for WPBN issue 304241
            /* for(int J=0;J<originChargesSize;J++)
            {
             if(originIndices[J] !=-1)
             {
             chargesDOB                = (QuoteCharges)originCharges.get(originIndices[J]);
              logger.info("Origin Charges doPDFGeneration::"+J+":"+chargesDOB); // newly added                  
             originChargeInfo        = chargesDOB.getChargeInfoList();
             originChargesInfoSize   = originChargeInfo.size();
             int m =0;
            String breakPoint = null;
             for(int k=0;k<originChargesInfoSize;k++)
             {
               chargeInfo = (QuoteChargeInfo)originChargeInfo.get(k);
               chargeRate =  ((Double)chargeInfo.getSellRate()).toString();
               chargeRate  = df.format(Double.parseDouble(chargeRate));
               chk = new Chunk(chargeRate,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
               cellZone = new Cell(chk);              
               //cellZone.setNoWrap(true);
               cellZone.setLeading(8.0f);
              // cellZone.setHeader(true);
               //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
               partZone.addCell(cellZone);
             }
             }
            }
            }//ended by Brahmaiah.R */
            //System.out.println("After zone header------------------------------>");
            document.add(partZone);
        }

        if (deliveryQuoteCartageRates != null && deliveryQuoteCartageRates.size() > 0) {
            /*Set dkeys         = null;
            for(int i=0;i<deliveryQuoteCartageRates.size();i++)
            {       
             if(i==0)
             { 
               deliBreaks = new TreeSet();//@@This is needed as only a new Set Implementation obj supports addAll() 
             }
             deliQuoteCartageRates = (QuoteCartageRates) deliveryQuoteCartageRates.get(i);
             dkeys = deliQuoteCartageRates.getRates().keySet();
             deliBreaks.addAll(dkeys);
             //System.out.println("Before zone header------------------------------>"+deliBreaks);
             //System.out.println("Before zone header------------------------------>"+deliBreaks.size());              
            }*/

            partZone = new Table(delWeightBreaksSize + 2);
            partZone.setOffset(30);
            partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
            partZone.setBorderWidth(1);
            partZone.setWidth(100);
            partZone.setBorderColor(Color.black);
            partZone.setPadding(1);
            partZone.setSpacing(1);
            partZone.setAutoFillEmptyCells(true);
            //partZone.setTableFitsPage(true);
            //@@ Added by subrahmanyam for the enhancement #147062 on 08/12/2008
            chk = new Chunk("DELIVERY CARTAGE RATES AT: " + headerDOB.getDestLocName(),
                    FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
            cellZone = new Cell(chk);
            cellZone.setNoWrap(true);
            cellZone.setLeading(10.0f);
            cellZone.setHeader(true);
            cellZone.setBackgroundColor(Color.WHITE);
            cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
            cellZone.setColspan(delWeightBreaksSize + 2);
            partZone.addCell(cellZone);
            //@@ Ended by subrahmanyam for the enhancement #147062 on 08/12/2008
            chk = new Chunk("DELIVERY CARTAGE RATES", FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            cellZone.setNoWrap(true);
            cellZone.setLeading(10.0f);
            cellZone.setHeader(true);
            cellZone.setBackgroundColor(Color.ORANGE);
            cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
            cellZone.setColspan(delWeightBreaksSize + 2);
            partZone.addCell(cellZone);

            chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            cellZone.setLeading(8.0f);
            //cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            cellZone.setBackgroundColor(Color.LIGHT_GRAY);
            partZone.addCell(cellZone);

            chk = new Chunk("Currency", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            cellZone.setLeading(8.0f);
            //cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            cellZone.setBackgroundColor(Color.LIGHT_GRAY);
            partZone.addCell(cellZone);

            //breaksSet = deliBreaks.iterator();

            /*while(breaksSet.hasNext())
            {              
              String breaks = (String)breaksSet.next();
                    
              chk = new Chunk(breaks,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
              cellZone = new Cell(chk);              
              cellZone.setNoWrap(true);
              cellZone.setHeader(true);
              partZone.addCell(cellZone);
            }*/
            for (int i = 0; i < delWeightBreaksSize; i++) {
                chk = new Chunk((String) delWeightBreaks.get(i),
                        FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                cellZone = new Cell(chk);
                cellZone.setLeading(8.0f);
                //cellZone.setNoWrap(true);
                cellZone.setHeader(true);
                cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                partZone.addCell(cellZone);
            }
            partZone.endHeaders();

            //Added By Kishore For the ChargeBasis in the Annexure PDF on 06-Jun-11

            chk = new Chunk("");
            cellZone = new Cell(chk);
            cellZone.setLeading(8.0f);
            //cellZone.setHeader(true);
            //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
            partZone.addCell(cellZone);

            chk = new Chunk("");
            cellZone = new Cell(chk);
            cellZone.setLeading(8.0f);
            //cellZone.setHeader(true);
            //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
            partZone.addCell(cellZone);
            ////commented  by Brahmaiah.R on 31/5/2012 for WPBN issue 304241 
            for (int i = 0; i < delChargeBasisSize; i++) {
                chk = new Chunk(toTitleCase((String) delChargeBasisList.get(i)),
                        FontFactory.getFont("ARIAL", 7, Font.BOLD, Color.BLACK));
                cellZone = new Cell(chk);
                //cellZone.setNoWrap(true);
                cellZone.setLeading(8.0f);
                cellZone.setHeader(true);
                //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                partZone.addCell(cellZone);
            }
            //added by Brahmaiah.R on 31/5/2012 for WPBN issue 304241
            /*    for(int J=0;J<destChargesSize;J++)
                {
                  if(destIndices[J] !=-1)
                  {
                  chargesDOB                = (QuoteCharges)destCharges.get(destIndices[J]);
                   logger.info("Dest Charges doPDFGeneration::"+J+":"+chargesDOB); // newly added                  
                  ArrayList destChargeInfo = chargesDOB.getChargeInfoList();
                  int destChargesInfoSize = destChargeInfo.size();
                  int m =0;
              String breakPoint = null;
                  for(int k=0;k<destChargesInfoSize;k++)
                  {
                    chargeInfo = (QuoteChargeInfo)destChargeInfo.get(k);
                    String chargeDestBasis = (String)chargeInfo.getBasis();
                    //chargeRate  = df.format(Double.parseDouble(chargeRate));
                    chk = new Chunk(chargeDestBasis,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                    cellZone = new Cell(chk);              
                    //cellZone.setNoWrap(true);
                    cellZone.setLeading(8.0f);
                   // cellZone.setHeader(true);
                    //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                    partZone.addCell(cellZone);
                  }
                  }
                }
                }//ended by Brahmaiah.R  */
            //End of Kishore For the ChargeBasis in the Annexure PDF on 06-Jun-11

            int delQuoteCartRtSize = deliveryQuoteCartageRates.size();
            for (int i = 0; i < delQuoteCartRtSize; i++) {
                deliQuoteCartageRates = (QuoteCartageRates) deliveryQuoteCartageRates.get(i);

                chk = new Chunk(deliQuoteCartageRates.getZone(),
                        FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                cellZone = new Cell(chk);
                cellZone.setLeading(8.0f);
                //cellZone.setNoWrap(true);            
                partZone.addCell(cellZone);

                chk = new Chunk(deliQuoteCartageRates.getCurrency(),
                        FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                cellZone = new Cell(chk);
                cellZone.setLeading(8.0f);
                //cellZone.setNoWrap(true);            
                partZone.addCell(cellZone);

                deliveryZoneCodeMap = deliQuoteCartageRates.getRates();

                //breaksSet = deliBreaks.iterator();
                /*while(breaksSet.hasNext())
                 {
                   String wBreak = (String)breaksSet.next();
                   if(deliveryZoneCodeMap.containsKey(wBreak))
                   {
                    chargeRate = (String)deliveryZoneCodeMap.get(wBreak);  
                    chargeRate  = df.format(Double.parseDouble(chargeRate));
                   }
                   else
                   {
                    chargeRate = "--";              
                   }
                  chk = new Chunk(chargeRate,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                  cellZone = new Cell(chk);
                  cellZone.setNoWrap(true);            
                  partZone.addCell(cellZone); 
                 }*/
                //commented  by Brahmaiah.R on 31/5/2012 for WPBN issue 304241
                String wBreak = null;
                for (int k = 0; k < delWeightBreaksSize; k++) {
                    wBreak = (String) delWeightBreaks.get(k);
                    if (wBreak != null && deliveryZoneCodeMap.containsKey(wBreak)) {
                        chargeRate = (String) deliveryZoneCodeMap.get(wBreak);
                        chargeRate = df.format(Double.parseDouble(chargeRate));
                    } else {
                        chargeRate = "--";
                    }
                    chk = new Chunk(chargeRate, FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                    cellZone = new Cell(chk);
                    cellZone.setLeading(8.0f);
                    //cellZone.setNoWrap(true);            
                    partZone.addCell(cellZone);
                }
            }
            //added by Brahmaiah.R on 31/5/2012 for WPBN issue 304241
            /*     for(int J=0;J<destChargesSize;J++)
                 {
                   if(destIndices[J] !=-1)
                   {
                   chargesDOB                = (QuoteCharges)destCharges.get(destIndices[J]);
                    logger.info("Dest Charges doPDFGeneration::"+J+":"+chargesDOB); // newly added                  
                   ArrayList destChargeInfo = chargesDOB.getChargeInfoList();
                   int destChargesInfoSize = destChargeInfo.size();
                   int m =0;
               String breakPoint = null;
                   for(int k=0;k<destChargesInfoSize;k++)
                   {
                     chargeInfo = (QuoteChargeInfo)destChargeInfo.get(k);
                     String percent = chargeInfo.isPercentValue()?"%":"";
                     String chargeDestRate = round1(((Double)chargeInfo.getSellRate()),percent).toString();
                     chargeDestRate  = df.format(Double.parseDouble(chargeDestRate));
                     chk = new Chunk(chargeDestRate,FontFactory.getFont("ARIAL", 8, Font.BOLD,Color.BLACK));
                     cellZone = new Cell(chk);              
                     //cellZone.setNoWrap(true);
                     cellZone.setLeading(8.0f);
                    // cellZone.setHeader(true);
                     //cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                     partZone.addCell(cellZone);
                   }
                   }
                 }*/
            document.add(partZone);
        }
        //ended by Brahmaiah.R 
        //System.out.println("After zone header------------------------------>");

        pickUpZoneZipMap = finalDOB.getPickZoneZipMap();
        //@@For Sorting the Zone Codes in an Order.
        List list = new ArrayList();
        Set zoneSet;
        //@@End of Declarations - Sorting
        if (pickUpZoneZipMap != null && pickUpZoneZipMap.size() > 0) {
            //System.out.println("Before zipCode header--------Set size------->"+pickUpZoneZipMap.keySet().size());
            //@@Sorting the Zone Codes (as TreeSet implements java.util.SortedSet)
            list.addAll(pickUpZoneZipMap.keySet());
            zoneSet = new TreeSet(list);
            //@@End of Sorting- Added by Yuvraj

            zones = zoneSet.iterator();

            partZone = new Table(2);
            partZone.setOffset(30);
            partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
            partZone.setBorderWidth(1);
            partZone.setBorderColor(Color.black);
            partZone.setPadding(1);
            partZone.setSpacing(1);
            partZone.setWidth(100);
            //partZone.setAutoFillEmptyCells(true);
            //partZone.setTableFitsPage(true);
            //@@ Added by subrahmanyam for the enhancement #147062 on 08/12/2008
            chk = new Chunk("PICKUP CHARGES AT: " + headerDOB.getOriginLocName(),
                    FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
            cellZone = new Cell(chk);
            cellZone.setLeading(10.0f);
            //cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            cellZone.setBackgroundColor(Color.WHITE);
            cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
            cellZone.setColspan(2);
            partZone.addCell(cellZone);

            //@@ Ended by subrahmanyam for the enhancement #147062 on  08/12/2008
            chk = new Chunk("PICKUP ZONE ZIP MAPPING",
                    FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            cellZone.setLeading(10.0f);
            //cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            cellZone.setBackgroundColor(Color.ORANGE);
            cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
            cellZone.setColspan(2);
            partZone.addCell(cellZone);

            chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            cellZone.setLeading(8.0f);
            //cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            cellZone.setBackgroundColor(Color.LIGHT_GRAY);
            partZone.addCell(cellZone);
            chk = new Chunk("Zip Code", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            cellZone.setLeading(8.0f);
            cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            partZone.addCell(cellZone);
            partZone.endHeaders();
            // System.out.println("Before zipCode Body------------------------------>");

            while (zones.hasNext()) {
                String zone = (String) zones.next();
                // System.out.println("zone------------------------------>"+zone);
                zipList = (ArrayList) pickUpZoneZipMap.get(zone);
                //System.out.println("zipList--------------------------->"+zipList);
                int zipListSize = zipList.size();
                for (int i = 0; i < zipListSize; i++) {
                    //System.out.println("zone for ------------------------------>"+zone);
                    if (zone != null && !zone.equals("null") && zipList.get(i) != null
                            && !((String) zipList.get(i)).equals("null")) {
                        chk = new Chunk(zone, FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                        cellZone.setLeading(8.0f);
                        //cellZone.setNoWrap(true);            
                        partZone.addCell(cellZone);
                        //System.out.println("zipList.get(i)--------------------------->"+(String)zipList.get(i));
                        chk = new Chunk((String) zipList.get(i),
                                FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                        cellZone = new Cell(chk);
                        cellZone.setLeading(8.0f);
                        cellZone.setNoWrap(true);
                        partZone.addCell(cellZone);
                    }
                }
            }
            document.add(partZone);
        }

        deliveryZoneZipMap = finalDOB.getDeliveryZoneZipMap();

        list = new ArrayList();
        zoneSet = null;

        if (deliveryZoneZipMap != null && deliveryZoneZipMap.size() > 0) {
            //System.out.println("Before zipCode header--------Set size------->"+deliveryZoneZipMap.keySet().size());
            list.addAll(deliveryZoneZipMap.keySet());
            zoneSet = new TreeSet(list);
            zones = zoneSet.iterator();

            partZone = new Table(2);
            partZone.setOffset(30);
            partZone.setDefaultHorizontalAlignment(partZone.ALIGN_CENTER);
            partZone.setBorderWidth(1);
            partZone.setBorderColor(Color.black);
            partZone.setPadding(1);
            partZone.setSpacing(1);
            partZone.setWidth(100);
            //partZone.setAutoFillEmptyCells(true);
            //partZone.setTableFitsPage(true);
            //@@ Added by subrahmanyam for the enhancement #147062 on 08/12/2008
            chk = new Chunk("DELIVERY CHARGES AT: " + headerDOB.getDestLocName(),
                    FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.RED));
            cellZone = new Cell(chk);
            cellZone.setLeading(10.0f);
            //cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            cellZone.setBackgroundColor(Color.WHITE);
            cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);
            cellZone.setColspan(2);
            partZone.addCell(cellZone);
            //@@ Ended by subrahmanyam for the enhancement #147062 on 08/12/2008 
            chk = new Chunk("DELIVERY ZONE ZIP MAPPING",
                    FontFactory.getFont("ARIAL", 10, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            cellZone.setLeading(10.0f);
            //cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            cellZone.setBackgroundColor(Color.ORANGE);
            cellZone.setVerticalAlignment(cellZone.ALIGN_BOTTOM);

            cellZone.setColspan(2);
            partZone.addCell(cellZone);

            chk = new Chunk("Zone", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            cellZone.setLeading(8.0f);
            cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            cellZone.setBackgroundColor(Color.LIGHT_GRAY);
            partZone.addCell(cellZone);
            chk = new Chunk("Zip Code", FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
            cellZone = new Cell(chk);
            cellZone.setLeading(8.0f);
            cellZone.setNoWrap(true);
            cellZone.setHeader(true);
            partZone.addCell(cellZone);
            partZone.endHeaders();
            //System.out.println("Before zipCode Body------------------------------>");

            while (zones.hasNext()) {
                String zone = (String) zones.next();
                //System.out.println("zone------------------------------>"+zone);
                zipList = (ArrayList) deliveryZoneZipMap.get(zone);
                if (zipList != null) {
                    //System.out.println("zipList--------------------------->"+zipList);
                    //logger.info("zipList--------------------------->"+zipList);
                    int zipListSize = zipList.size();
                    for (int i = 0; i < zipListSize; i++) {
                        //System.out.println("zone for ------------------------------>"+zone);
                        if (zone != null && !zone.equals("null") && zipList.get(i) != null
                                && !((String) zipList.get(i)).equals("null")) {
                            chk = new Chunk(zone, FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                            cellZone = new Cell(chk);
                            cellZone.setLeading(8.0f);
                            cellZone.setBackgroundColor(Color.LIGHT_GRAY);
                            cellZone.setNoWrap(true);
                            partZone.addCell(cellZone);
                            //System.out.println("zipList.get(i)--------------------------->"+(String)zipList.get(i));
                            chk = new Chunk((String) zipList.get(i),
                                    FontFactory.getFont("ARIAL", 8, Font.BOLD, Color.BLACK));
                            cellZone = new Cell(chk);
                            cellZone.setLeading(8.0f);
                            cellZone.setNoWrap(true);
                            partZone.addCell(cellZone);
                        }
                    }
                }
            }
            document.add(partZone);
        }
        //System.out.println("After zipCode header------------------------------>");

        document.close();
        //System.out.println("After     document Close----------------------------------------->");               
        File f = new File("Cartage.pdf");
        FileOutputStream fileOutputStream = new FileOutputStream(f);
        baos.writeTo(fileOutputStream);
        fileOutputStream.close();//added by sanjay on 20/03/2006
        //@@Added by Kameswari for the WPBN issue-80440
        PdfReader reader = new PdfReader("Cartage.pdf");
        int n = reader.getNumberOfPages();
        File fs = new File(fileName);
        String space = " ";
        // we create a stamper that will copy the document to a new file
        PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(fs));

        // adding some metadata
        // adding content to each page

        int k = 0;
        PdfContentByte under;
        PdfContentByte over = null;
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
        while (k < n) {
            k++;
            over = stamp.getOverContent(k);
            over.beginText();
            over.setFontAndSize(bf, 8);
            over.setTextMatrix(15, 15);
            over.showText("page " + k + " of " + n);

            if (k > 1) {
                over.setFontAndSize(bf, 7);
                over.showText(
                        "                                                                                                       QUOTE REFERENCE:"
                                + masterDOB.getQuoteId());
                //@@Added by subrahmanyam for the WPBN:146452 on 12/12/2008
                over.endText();
                over.beginText();
                over.showText(
                        "                                                                                                                                    CUSTOMER NAME: "
                                + headerDOB.getCustomerName());//subrahmanyam 12/12/2008
                //@@ Ended by subrahmanyam for the WPBM:146452 on 12/12/2008               
            }
            over.endText();
        }
        stamp.close();
        //@@WPBN issue-80440    
        //@@ Commented by subrahmanyam for 146460         
        /* if("on".equalsIgnoreCase(request.getParameter("print")))
        {
                
           request.getSession().setAttribute("CartageOuptutStream",fs);
        }*/
        //@@ Added by subrahmanyam for  146460                

        if ("on".equalsIgnoreCase(request.getParameter("print"))
                || "PDF".equalsIgnoreCase(request.getParameter("pdf"))) {

            request.getSession().setAttribute("CartageOuptutStream", fs);
        }
        //@@ Ended by subrahmanyam for 146460
        //f.delete();
        baos.close();
        //System.out.println("End of generation header------------------------------>");

    } catch (Exception e) {
        e.printStackTrace();
        //Logger.error(FILE_NAME,"Error while generating the PDF"+e.toString());
        logger.error(FILE_NAME + "Error while generating the PDF" + e.toString());
        throw new Exception("Error while generating PDF format");
    }
    return 1;
}

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

public void createWordReport_hardware(String filename) {
    try {//from  w  ww  .  j  a v a 2  s  .  c  om
        String starttime = (String) reportHash.get("starttime");
        String totime = (String) reportHash.get("totime");
        Document document = new Document(PageSize.A4);
        RtfWriter2.getInstance(document, new FileOutputStream(filename));
        fileName = 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, 10, Font.NORMAL);
        Paragraph title = new Paragraph("");
        title.setAlignment(Element.ALIGN_CENTER);
        document.add(title);

        String contextString = ":" + impReport.getTimeStamp() + " \n"// 
                + ":" + starttime + "  " + totime;
        Paragraph context = new Paragraph(contextString);
        // 
        context.setAlignment(Element.ALIGN_LEFT);
        // context.setFont(contextFont);
        // 
        context.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);

        Table aTable = new Table(4);
        float[] widths = { 100f, 100f, 300f, 100f };
        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();
        aTable.addCell("");
        aTable.addCell("");
        aTable.addCell("");
        aTable.addCell("");
        Vector deviceV = (Vector) reportHash.get("deviceV");
        for (int m = 0; m < deviceV.size(); m++) {
            Devicecollectdata devicedata = (Devicecollectdata) deviceV.get(m);
            String name = devicedata.getName();
            String type = devicedata.getType();
            String status = devicedata.getStatus();
            aTable.addCell(m + 1 + "");
            aTable.addCell(type);
            aTable.addCell(name);
            aTable.addCell(status);
        }
        document.add(aTable);
        document.close();
        // System.out.println("abcdefg");
    } catch (Exception e) {
        SysLogger.error("", e);
    }
}

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

public void createReportusa_oraDoc(String filename) throws DocumentException, IOException {
    try {// w  w  w . java2  s .co m
        // 
        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);
        // System.out.println("newi ========================"+newip);
        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.setSpacingBefore(5);
        // 
        context.setFirstLineIndent(5);
        document.add(context);
        Table aTable = new Table(4);
        float[] widths = { 220f, 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("", 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 = new Cell(new Phrase((String) maxping.get("pingnow"), contextFont));// HONGLI
        // MODIFY
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
        // cell = new Cell(new Phrase((String)
        // maxping.get("ping"),contextFont));
        cell = new Cell(new Phrase((String) maxping.get("pingmin"), contextFont));// HONGLI
        // MODIFY
        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");
        document.add(aTable);
        document.add(img);
        document.close();
    } catch (Exception e) {
        SysLogger.error("", e);
    }
}

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

public void createReport_networkDoc(String file) throws DocumentException, IOException {
    String runmodel = PollingEngine.getCollectwebflag();
    Hashtable CPU = (Hashtable) reportHash.get("CPU");
    String Ping = (String) reportHash.get("Ping");
    String ip = (String) reportHash.get("ip");
    String newip = doip(ip);//from   www  .  ja va2 s.  c  o m
    Calendar colTime = (Calendar) reportHash.get("time");
    Date cc = colTime.getTime();
    Vector netifVector = (Vector) reportHash.get("netifVector");
    Hashtable portconfigHash = (Hashtable) reportHash.get("portconfigHash");
    List reportports = (List) reportHash.get("reportports");
    Vector iprouterVector = (Vector) reportHash.get("iprouterVector");

    Hashtable Memory = (Hashtable) reportHash.get("Memory");
    Hashtable Disk = (Hashtable) reportHash.get("Disk");
    String hostname = (String) reportHash.get("equipname");
    Hashtable memMaxHash = (Hashtable) reportHash.get("memmaxhash");
    Hashtable maxping = (Hashtable) reportHash.get("ping");

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

    String[] netIfItemch = { "", "", "", "(M)", "", "", "" };
    String[] ipRouterItemch = { "", "", "", "", "", "" };
    String[] memoryItem = { "Capability", "Utilization" };
    String[] diskItem = { "AllSize", "UsedSize", "Utilization", "INodeUsedSize", "INodeUtilization" };
    String[] diskItemch = { "", "", "", "i-node", "i-node" };
    String[] iproutertype = { "", "", "", "direct(3)", "indirect(4)" };
    String[] iprouterproto = { "", "other(1)", "local(2)", "netmgmt(3)", "icmp(4)", "egp(5)", "ggp(6)",
            "hello(7)", "rip(8)", "is-is(9)", "es-is(10)", "ciscoIgrp(11)", "bbnSpfIgp(12)", "ospf(13)",
            "bgp(14)" };
    // 
    Document document = new Document(PageSize.A4);
    // (Writer)document(Writer)
    RtfWriter2.getInstance(document, new FileOutputStream(file));
    document.open();
    // 
    BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED);
    // 
    Font titleFont = new Font(bfChinese, 12, Font.BOLD);
    // 
    Font contextFont = new Font(bfChinese, 10, Font.NORMAL);

    Paragraph title = new Paragraph(hostname + "", titleFont);
    // 
    title.setAlignment(Element.ALIGN_CENTER);
    // title.setFont(titleFont);
    document.add(title);
    String contextString = ":" + impReport.getTimeStamp() + " \n"// 
            + ":" + sdf.format(cc);

    Paragraph context = new Paragraph(contextString, titleFont);
    // 
    context.setAlignment(Element.ALIGN_LEFT);
    // context.setFont(contextFont);
    // 
    context.setSpacingBefore(5);
    // 
    context.setFirstLineIndent(5);
    document.add(context);
    //  Table 
    Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black);
    Table aTable = new Table(4);
    float[] widths = { 220f, 300f, 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 cellt0 = new Cell("");
    cellt0.setBackgroundColor(Color.LIGHT_GRAY);
    cellt0.setHorizontalAlignment(Element.ALIGN_CENTER);
    cellt0.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cellt0.setRowspan(2);
    Cell cellt1 = new Cell("");
    cellt1.setBackgroundColor(Color.LIGHT_GRAY);
    Cell cellt2 = new Cell("");
    cellt2.setBackgroundColor(Color.LIGHT_GRAY);
    Cell cellt3 = new Cell("");
    cellt3.setBackgroundColor(Color.LIGHT_GRAY);
    aTable.addCell(cellt0);
    aTable.addCell(cellt1);
    aTable.addCell(cellt2);
    aTable.addCell(cellt3);

    // aTable.addCell("3.2",Ping+"%");
    // Cell cellt4 = new Cell("");
    // cellt4.setBackgroundColor(Color.LIGHT_GRAY);
    // aTable.addCell(cellt4);
    aTable.addCell(Ping + "%");
    aTable.addCell((String) maxping.get("pingmax"));
    aTable.addCell((String) maxping.get("avgpingcon"));
    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"));
    // document.close();
    Table aTable1 = new Table(4);
    float[] width = { 220f, 300f, 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);// 
    aTable1.endHeaders();

    cellt0 = new Cell("CPU");
    cellt0.setBackgroundColor(Color.LIGHT_GRAY);
    cellt0.setHorizontalAlignment(Element.ALIGN_CENTER);
    cellt0.setVerticalAlignment(Element.ALIGN_MIDDLE);

    cellt1 = new Cell("");
    cellt1.setBackgroundColor(Color.LIGHT_GRAY);
    cellt2 = new Cell("");
    cellt2.setBackgroundColor(Color.LIGHT_GRAY);
    cellt3 = new Cell("");
    cellt3.setBackgroundColor(Color.LIGHT_GRAY);
    aTable1.addCell(cellt0);
    aTable1.addCell(cellt1);
    aTable1.addCell(cellt2);
    aTable1.addCell(cellt3);
    // aTable.addCell("3.2",Ping+"%");
    aTable1.addCell("");

    aTable1.addCell((String) CPU.get("cpu") + "%");
    aTable1.addCell((String) CPU.get("cpumax"));
    aTable1.addCell((String) CPU.get("avgcpu"));
    cellt0.setRowspan(2);
    Image img1 = Image.getInstance(
            ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "cpu" + ".png");
    img.setAbsolutePosition(0, 0);
    img.setAlignment(Image.MIDDLE);// 
    document.add(aTable1);
    document.add(img1);

    if (netifVector != null && netifVector.size() > 0) {
        Table aTable2 = new Table(8);
        float[] width2 = { 300f, 220f, 220f, 180f, 300f, 180f, 220f, 220f };
        aTable2.setWidths(width2);
        aTable2.setWidth(100); //  100%
        aTable2.setAlignment(Element.ALIGN_CENTER);// 
        aTable2.setAutoFillEmptyCells(true); // 
        aTable2.setBorderWidth(1); // 
        aTable2.setBorderColor(new Color(0, 125, 255)); // 
        aTable2.setPadding(2);// 
        aTable2.setSpacing(0);// 
        aTable2.setBorder(2);// 
        aTable2.endHeaders();
        Cell c = new Cell("");
        c.setBackgroundColor(Color.LIGHT_GRAY);
        c.setRowspan(netifVector.size() + 1);
        c.setHorizontalAlignment(Element.ALIGN_CENTER);
        c.setVerticalAlignment(Element.ALIGN_MIDDLE);
        aTable2.addCell(c);
        // 
        // allRow = allRow;
        for (int i = 0; i < netIfItemch.length; i++) {
            Cell cell = new Cell(netIfItemch[i]);
            cell.setBackgroundColor(Color.LIGHT_GRAY);
            aTable2.addCell(cell);
        }
        Color color = new Color(204, 204, 255);
        // 
        for (int i = 0; i < netifVector.size(); i++) {
            // aTable2.addCell("");
            String[] strs = (String[]) netifVector.get(i);
            String ifname = strs[1];
            String index = strs[0];
            for (int j = 0; j < strs.length; j++) {
                if (j == 1) {
                    String linkuse = "";
                    if (portconfigHash != null && portconfigHash.size() > 0) {
                        if (portconfigHash.get(ip + ":" + index) != null)
                            linkuse = (String) portconfigHash.get(ip + ":" + index);
                    }
                    Cell cell1 = new Cell(strs[j]);
                    Cell cell2 = new Cell(linkuse);
                    if (i % 2 != 0) {
                        cell1.setBackgroundColor(color);
                        cell2.setBackgroundColor(color);
                    }
                    aTable2.addCell(cell1);
                    aTable2.addCell(cell2);
                } else if (j > 1) {
                    Cell cell3 = new Cell(strs[j]);
                    if (i % 2 != 0) {
                        cell3.setBackgroundColor(color);
                    }
                    aTable2.addCell(cell3);
                } else {
                    Cell cell4 = new Cell(strs[j]);
                    if (i % 2 != 0) {
                        cell4.setBackgroundColor(color);
                    }
                    aTable2.addCell(cell4);
                }
            } // end 
        }
        document.add(aTable2);
    }
    if ("0".equals(runmodel)) {
        // 
        if (iprouterVector != null && iprouterVector.size() > 0) {
            Table aTable3 = new Table(7);
            float[] width2 = { 240f, 200f, 300f, 300f, 220f, 180f, 300f };
            aTable3.setWidths(width2);
            aTable3.setWidth(100); //  100%
            aTable3.setAlignment(Element.ALIGN_CENTER);// 
            aTable3.setAutoFillEmptyCells(true); // 
            aTable3.setBorderWidth(1); // 
            aTable3.setBorderColor(new Color(0, 125, 255)); // 
            aTable3.setPadding(2);// 
            aTable3.setSpacing(0);// 
            aTable3.setBorder(2);// 
            aTable3.endHeaders();
            aTable3.addCell("");
            // 
            // allRow = allRow+1;
            for (int i = 0; i < ipRouterItemch.length; i++) {
                Cell cell = new Cell(ipRouterItemch[i]);
                aTable3.addCell(cell);

            }

            // 

            for (int i = 0; i < iprouterVector.size(); i++) {
                aTable3.addCell("");
                /* allRow = allRow + 1; */

                IpRouter iprouter = (IpRouter) iprouterVector.get(i);
                Cell cell = new Cell(iprouter.getIfindex());
                aTable3.addCell(cell);
                Cell cell1 = new Cell(iprouter.getDest());
                aTable3.addCell(cell1);
                Cell cell2 = new Cell(iprouter.getNexthop());
                aTable3.addCell(cell2);
                Cell cell3 = new Cell(iproutertype[Integer.parseInt(iprouter.getType().longValue() + "")]);
                aTable3.addCell(cell3);
                Cell cell4 = new Cell(iprouterproto[Integer.parseInt(iprouter.getProto().longValue() + "")]);
                aTable3.addCell(cell4);
                Cell cell5 = new Cell(iprouter.getMask());
                aTable3.addCell(cell5);
            }
            document.add(aTable3);
        }
    } else {
        // 
        List routerList = (ArrayList) reportHash.get("routerList");
        Table aTable3 = new Table(7);
        float[] width2 = { 240f, 200f, 300f, 300f, 220f, 180f, 300f };
        aTable3.setWidths(width2);
        aTable3.setWidth(100); //  100%
        aTable3.setAlignment(Element.ALIGN_CENTER);// 
        aTable3.setAutoFillEmptyCells(true); // 
        aTable3.setBorderWidth(1); // 
        aTable3.setBorderColor(new Color(0, 125, 255)); // 
        aTable3.setPadding(2);// 
        aTable3.setSpacing(0);// 
        aTable3.setBorder(2);// 
        aTable3.endHeaders();
        aTable3.addCell("");
        // 
        // allRow = allRow+1;
        for (int i = 0; i < ipRouterItemch.length; i++) {
            Cell cell = new Cell(ipRouterItemch[i]);
            aTable3.addCell(cell);

        }
        if (routerList != null) {
            for (int i = 0; i < routerList.size(); i++) {
                aTable3.addCell("");
                RouterNodeTemp iprouter = (RouterNodeTemp) routerList.get(i);
                Cell cell = new Cell(iprouter.getIfindex());
                aTable3.addCell(cell);
                Cell cell1 = new Cell(iprouter.getDest());
                aTable3.addCell(cell1);
                Cell cell2 = new Cell(iprouter.getNexthop());
                aTable3.addCell(cell2);
                Cell cell3 = new Cell(iprouter.getType());
                aTable3.addCell(cell3);
                Cell cell4 = new Cell(iprouter.getProto());
                aTable3.addCell(cell4);
                Cell cell5 = new Cell(iprouter.getMask());
                aTable3.addCell(cell5);
            }
            document.add(aTable3);
        }
    }
    // doc

    if (reportports != null && reportports.size() > 0) {
        // 

        // aTable4.addCell("");
        for (int i = 0; i < reportports.size(); i++) {
            Table aTable4 = new Table(2);
            float[] width2 = { 300f, 300f };
            aTable4.setWidths(width2);
            aTable4.setWidth(100); //  100%
            aTable4.setAlignment(Element.ALIGN_CENTER);// 
            aTable4.setAutoFillEmptyCells(true); // 
            aTable4.setBorderWidth(1); // 
            aTable4.setBorderColor(new Color(0, 125, 255)); // 
            aTable4.setPadding(2);// 
            aTable4.setSpacing(0);// 
            aTable4.setBorder(2);// 
            aTable4.endHeaders();
            // SysLogger.info(reportports.get(i).getClass()+"=============================================");
            com.afunms.config.model.Portconfig portconfig = (com.afunms.config.model.Portconfig) reportports
                    .get(i);
            /*
             * tmpLabel = new Label(0, allRow, "" +
             * portconfig.getPortindex() + "(" + portconfig.getName() +
             * ")", b_labelFormat);
             * 
             * sheet.addCell(tmpLabel);
             */
            Cell cell = new Cell("" + portconfig.getPortindex() + "(" + portconfig.getName() + ")");
            aTable4.addCell(cell);
            if (portconfig.getLinkuse() == null)
                portconfig.setLinkuse("");
            Cell cell1 = new Cell(":" + portconfig.getLinkuse());
            aTable4.addCell(cell1);
            document.add(aTable4);
            // 
            Image img2 = Image.getInstance(ResourceCenter.getInstance().getSysPath()
                    + "/resource/image/jfreechart/" + newip + portconfig.getPortindex() + "ifspeed_day.png");
            img2.setAbsolutePosition(0, 0);
            img2.setAlignment(Image.LEFT);// 
            // sheet,0,0,5,1,,,
            img2.scalePercent(67);
            document.add(img2);
        }
    } // 
    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());
         */
        Image img2 = Image.getInstance(baos.toByteArray());
        img.setAbsolutePosition(0, 0);
        img.setAlignment(Image.LEFT);// 
        img.scalePercent(67);
        document.add(img2);
    }

    document.close();
}

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

public void createReport_hostNewDoc(String file) throws DocumentException, IOException {
    Hashtable Memory = (Hashtable) reportHash.get("Memory");
    // EventListDao eventListDao = new EventListDao();

    Hashtable memMaxHash = (Hashtable) reportHash.get("memmaxhash");
    Hashtable memAvgHash = (Hashtable) reportHash.get("memavghash");
    Hashtable CPU = (Hashtable) reportHash.get("CPU");
    String[] memoryItemch = { "", "", "", "" };
    String[] memoryItem = { "Capability", "Utilization" };
    if (CPU == null)
        CPU = new Hashtable();
    String cpu = "";
    if (CPU.get("cpu") != null)
        cpu = (String) CPU.get("cpu");
    String cpumax = "0.0%";
    if (CPU.get("cpumax") != null)
        cpumax = (String) CPU.get("cpumax");
    String avgcpu = "";
    if (CPU.get("avgcpu") != null)
        avgcpu = (String) CPU.get("avgcpu");
    String starttime = (String) reportHash.get("starttime");
    String totime = (String) reportHash.get("totime");
    String hostname = (String) reportHash.get("equipname");
    String hostnameDoc = (String) reportHash.get("equipnameDoc");
    String ip = (String) reportHash.get("ip");
    String typename = (String) reportHash.get("typename");
    String startdate = (String) reportHash.get("startdate");
    int cpuvalue = ((Integer) reportHash.get("cpuvalue")).intValue();

    int memvalue = ((Integer) reportHash.get("memvalue")).intValue();
    int diskvalue = ((Integer) reportHash.get("diskvalue")).intValue();
    int pingvalue = ((Integer) reportHash.get("pingvalue")).intValue();

    /* String type = (String)request.getAttribute("type"); */
    Document document = new Document(PageSize.A4);
    // (Writer)document(Writer)
    RtfWriter2.getInstance(document, new FileOutputStream(file));
    document.open();/*from   ww  w .  j a v a2s.  co m*/
    // 
    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);

    Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black);
    Table aTable = new Table(8);
    float[] widths = { 220f, 220f, 220f, 110f, 110f, 110f, 110f, 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("\n" + "" + hostname + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setColspan(8);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_CENTER);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable.addCell(cell);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    cell = new Cell(new Phrase("\n" + starttime + "  " + totime + "\n", contextFont));
    cell.setColspan(7);

    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(hostnameDoc, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("IP", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(ip, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(typename, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    String grade = (String) reportHash.get("grade");
    cell = new Cell(new Phrase("\n" + grade + "\n", contextFont));
    cell.setColspan(7);

    aTable.addCell(cell);
    cell = new Cell(new Phrase("" + "\n" + "" + "\n" + "" + "\n" + "", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setRowspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "CPU" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(avgcpu, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("CPU", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase(cpumax, contextFont));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    String avgvalue = "0.0%";
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    if (memAvgHash.get("PhysicalMemory") != null) {

        avgvalue = (String) memAvgHash.get("PhysicalMemory");
        cell = new Cell(new Phrase(avgvalue, contextFont));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
    } else {
        cell = new Cell(new Phrase(avgvalue, contextFont));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
    }
    cell = new Cell(new Phrase("", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    String value = "0.0%";
    if (memMaxHash.get("PhysicalMemory") != null) {

        value = (String) memMaxHash.get("PhysicalMemory");
        cell = new Cell(new Phrase(value, contextFont));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
    } else {
        cell = new Cell(new Phrase(value, contextFont));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
    }

    // end 

    // end  }
    cell = new Cell(new Phrase("" + "\n" + "" + "\n" + "" + "\n" + "", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setRowspan(4);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "CPU" + cpuvalue + "" + "\n", contextFont));
    cell.setColspan(7);
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "" + memvalue + "" + "\n", contextFont));
    cell.setColspan(7);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + pingvalue + "" + "\n", contextFont));
    cell.setColspan(7);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + diskvalue + "" + "\n", contextFont));
    cell.setColspan(7);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setColspan(8);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    String strcpu = "";
    String strmem = "";
    String strping = "";
    String strdisk = "";
    if (cpuvalue > 0) {
        strcpu = "    2   " + cpuvalue + "CPU" + "\n"
                + "\n";
    } else {
        strcpu = "    2   CPU" + " \n" + "\n";
    }
    if (memvalue > 0) {
        strmem = "    3   " + memvalue + "" + "\n" + "\n";
    } else {
        strmem = "    3   " + "\n" + "\n";
    }
    if (pingvalue > 0) {
        strping = "    4   " + pingvalue + "" + "\n"
                + "\n";
    } else {
        strping = "    4   " + "\n" + "\n";
    }
    if (diskvalue > 0) {

        strdisk = "    5   " + diskvalue + "";
    } else {
        strdisk = "    5   ";
    }

    cell = new Cell(new Phrase("    1   " + " \n" + "\n"
            + strcpu + strmem + strping + strdisk + "\n" + "\n" + "\n", contextFont)

    );
    cell.setColspan(8);
    aTable.addCell(cell);
    document.add(aTable);
    document.close();

}

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

public void createReport_hostNewPDF(String file) throws DocumentException, IOException {
    Hashtable Memory = (Hashtable) reportHash.get("Memory");
    // EventListDao eventListDao = new EventListDao();

    Hashtable memMaxHash = (Hashtable) reportHash.get("memmaxhash");
    Hashtable memAvgHash = (Hashtable) reportHash.get("memavghash");
    Hashtable CPU = (Hashtable) reportHash.get("CPU");
    String[] memoryItemch = { "", "", "", "" };
    String[] memoryItem = { "Capability", "Utilization" };
    if (CPU == null)
        CPU = new Hashtable();
    String cpu = "";
    if (CPU.get("cpu") != null)
        cpu = (String) CPU.get("cpu");
    String cpumax = "0.0%";
    if (CPU.get("cpumax") != null)
        cpumax = (String) CPU.get("cpumax");
    String avgcpu = "";
    if (CPU.get("avgcpu") != null)
        avgcpu = (String) CPU.get("avgcpu");
    String starttime = (String) reportHash.get("starttime");
    String totime = (String) reportHash.get("totime");
    String hostname = (String) reportHash.get("equipname");
    String hostnameDoc = (String) reportHash.get("equipnameDoc");
    String ip = (String) reportHash.get("ip");
    String typename = (String) reportHash.get("typename");
    String startdate = (String) reportHash.get("startdate");
    int cpuvalue = ((Integer) reportHash.get("cpuvalue")).intValue();
    int memvalue = ((Integer) reportHash.get("memvalue")).intValue();
    int diskvalue = ((Integer) reportHash.get("diskvalue")).intValue();
    int pingvalue = ((Integer) reportHash.get("pingvalue")).intValue();

    /* String type = (String)request.getAttribute("type"); */
    Document document = new Document(PageSize.A4);
    // (Writer)document(Writer)
    PdfWriter.getInstance(document, new FileOutputStream(file));
    document.open();/* w  w w .  ja  v  a 2  s .  c o m*/
    // 
    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, 10, Font.NORMAL);
    Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black);
    Table aTable = new Table(8);
    float[] widths = { 220f, 220f, 220f, 110f, 110f, 110f, 110f, 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("\n" + "" + hostname + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setColspan(8);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_CENTER);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable.addCell(cell);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    cell = new Cell(new Phrase("\n" + starttime + "  " + totime + "\n", contextFont1));
    cell.setColspan(7);

    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(hostnameDoc, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("IP", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(ip));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(typename, contextFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    String grade = (String) reportHash.get("grade");
    cell = new Cell(new Phrase("\n" + grade + "\n", contextFont));
    cell.setColspan(7);

    aTable.addCell(cell);
    cell = new Cell(new Phrase("" + "\n" + "" + "\n" + "" + "\n" + "", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setRowspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "CPU" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase(avgcpu));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    cell = new Cell(new Phrase("CPU", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase(cpumax));
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    String avgvalue = "0.0%";
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    if (memAvgHash.get("PhysicalMemory") != null) {

        avgvalue = (String) memAvgHash.get("PhysicalMemory");
        cell = new Cell(new Phrase(avgvalue));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
    } else {
        cell = new Cell(new Phrase(avgvalue));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
    }
    cell = new Cell(new Phrase("", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setColspan(2);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    String value = "0.0%";
    if (memMaxHash.get("PhysicalMemory") != null) {

        value = (String) memMaxHash.get("PhysicalMemory");
        cell = new Cell(new Phrase(value));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
    } else {
        cell = new Cell(new Phrase(value));
        cell.setColspan(2);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
        aTable.addCell(cell);
    }

    // end 

    // end  }
    cell = new Cell(new Phrase("" + "\n" + "" + "\n" + "" + "\n" + "", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setRowspan(4);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "CPU" + cpuvalue + "" + "\n", contextFont));
    cell.setColspan(7);
    aTable.addCell(cell);

    cell = new Cell(new Phrase("\n" + "" + memvalue + "" + "\n", contextFont));
    cell.setColspan(7);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + pingvalue + "" + "\n", contextFont));
    cell.setColspan(7);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + diskvalue + "" + "\n", contextFont));
    cell.setColspan(7);
    aTable.addCell(cell);
    cell = new Cell(new Phrase("\n" + "" + "\n", titleFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    cell.setColspan(8);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 
    aTable.addCell(cell);
    String strcpu = "";
    String strmem = "";
    String strping = "";
    String strdisk = "";
    if (cpuvalue > 0) {
        strcpu = "    2   " + cpuvalue + "CPU" + "\n"
                + "\n";
    } else {
        strcpu = "    2   CPU" + " \n" + "\n";
    }
    if (memvalue > 0) {
        strmem = "    3   " + memvalue + "" + "\n" + "\n";
    } else {
        strmem = "    3   " + "\n" + "\n";
    }
    if (pingvalue > 0) {
        strping = "    4   " + pingvalue + "" + "\n"
                + "\n";
    } else {
        strping = "    4   " + "\n" + "\n";
    }
    if (diskvalue > 0) {

        strdisk = "    5   " + diskvalue + "";
    } else {
        strdisk = "    5   ";
    }

    cell = new Cell(new Phrase("    1   " + " \n" + "\n"
            + strcpu + strmem + strping + strdisk + "\n" + "\n" + "\n", contextFont)

    );
    /*
     * cell = new Cell(new Phrase(" 1 " + " \n" +
     * "\n" + " 2 " + cpuvalue + "CPU" + "\n" +
     * "\n" + " 3 "+memvalue+"" + "\n" +
     * "\n" + " 4 "+pingvalue+"" + "\n" +
     * "\n"+" 5 "+diskvalue+"" + "\n" + "\n"+
     * "\n",contextFont) );
     */
    cell.setColspan(8);
    aTable.addCell(cell);
    document.add(aTable);
    document.close();

}

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

public void createReport_hostDoc(String file) throws DocumentException, IOException {
    String starttime = (String) reportHash.get("starttime");
    String totime = (String) reportHash.get("totime");

    String hostname = (String) reportHash.get("equipname");
    String ip = (String) reportHash.get("ip");
    String newip = doip(ip);//from  w w w  .j ava2s . c om
    // WritableSheet sheet = wb.createSheet(hostname + "", 0);
    Hashtable CPU = (Hashtable) reportHash.get("CPU");
    if (CPU == null)
        CPU = new Hashtable();
    String Ping = (String) reportHash.get("Ping");
    Calendar colTime = (Calendar) reportHash.get("time");
    Date cc = colTime.getTime();
    Hashtable Memory = (Hashtable) reportHash.get("Memory");
    Hashtable Disk = (Hashtable) reportHash.get("Disk");

    Hashtable memMaxHash = (Hashtable) reportHash.get("memmaxhash");
    Hashtable memAvgHash = (Hashtable) reportHash.get("memavghash");
    Hashtable maxping = (Hashtable) reportHash.get("ping");

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

    String[] memoryItemch = { "", "", "", "" };
    String[] memoryItem = { "Capability", "Utilization" };
    String[] diskItem = { "AllSize", "UsedSize", "Utilization" };
    String[] diskItemch = { "", "", "" };
    // 
    Document document = new Document(PageSize.A4);
    // (Writer)document(Writer)
    RtfWriter2.getInstance(document, new FileOutputStream(file));
    document.open();
    // 
    BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED);
    // 
    Font titleFont = new Font(bfChinese, 12, Font.BOLD);
    // 
    Font contextFont = new Font(bfChinese, 10, Font.NORMAL);
    Paragraph title = new Paragraph(hostname + "", titleFont);
    // 
    title.setAlignment(Element.ALIGN_CENTER);
    // title.setFont(titleFont);
    document.add(title);
    String contextString = ":" + impReport.getTimeStamp() + " \n"// 
            + ":" + starttime + "  " + totime;
    Paragraph context = new Paragraph(contextString, titleFont);
    // 
    context.setAlignment(Element.ALIGN_LEFT);
    // context.setFont(contextFont);
    // 
    context.setSpacingBefore(5);
    // 
    context.setFirstLineIndent(5);
    document.add(context);
    Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black);
    Table aTable = new Table(4);
    float[] widths = { 220f, 300f, 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 = new Cell();
    cell.addElement(new Paragraph("", contextFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable.addCell(cell);
    cell = new Cell();
    cell.addElement(new Paragraph("", contextFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable.addCell(cell);
    cell = new Cell();
    cell.addElement(new Paragraph("", contextFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable.addCell(cell);
    cell = new Cell();
    cell.addElement(new Paragraph("", contextFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable.addCell(cell);
    cell = new Cell();
    cell.addElement(new Paragraph("", contextFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable.addCell(cell);
    aTable.addCell(Ping + "%");
    aTable.addCell((String) maxping.get("pingmax"));
    aTable.addCell((String) maxping.get("avgpingcon"));
    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);

    String cpu = "";
    if (CPU.get("cpu") != null)
        cpu = (String) CPU.get("cpu");
    String cpumax = "";
    if (CPU.get("cpumax") != null)
        cpumax = (String) CPU.get("cpumax");
    String avgcpu = "";
    if (CPU.get("avgcpu") != null)
        avgcpu = (String) CPU.get("avgcpu");
    Table aTable1 = new Table(4);
    float[] width = { 220f, 300f, 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);// 
    aTable1.endHeaders();

    cell = new Cell();
    cell.addElement(new Paragraph("CPU", contextFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable1.addCell(cell);
    cell = new Cell();
    cell.addElement(new Paragraph("", contextFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable1.addCell(cell);
    cell = new Cell();
    cell.addElement(new Paragraph("", contextFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable1.addCell(cell);
    cell = new Cell();
    cell.addElement(new Paragraph("", contextFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable1.addCell(cell);
    cell = new Cell();
    cell.addElement(new Paragraph("", contextFont));
    cell.setBackgroundColor(Color.LIGHT_GRAY);
    aTable1.addCell(cell);

    aTable1.addCell(cpu + "%");
    aTable1.addCell(cpumax);
    aTable1.addCell(avgcpu);

    Image img1 = Image.getInstance(
            ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/" + newip + "cpu" + ".png");
    img.setAbsolutePosition(0, 0);
    img.setAlignment(Image.MIDDLE);// 
    document.add(aTable1);
    document.add(img1);

    if (Memory != null && Memory.size() > 0) {
        Table aTable2 = new Table(6);
        float[] widthss = { 220f, 300f, 220f, 220f, 220f, 220f };
        aTable2.setWidths(widthss);
        aTable2.setWidth(100); //  90%
        aTable2.setAlignment(Element.ALIGN_CENTER);// 
        aTable2.setAutoFillEmptyCells(true); // 
        aTable2.setBorderWidth(1); // 
        aTable2.setBorderColor(new Color(0, 125, 255)); // 
        aTable2.setPadding(2);// 
        aTable2.setSpacing(0);// 
        aTable2.setBorder(2);// 
        aTable2.endHeaders();
        cell = new Cell("");
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        aTable2.addCell(cell);
        cell = new Cell("");
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        aTable2.addCell(cell);
        // 

        for (int i = 0; i < memoryItemch.length; i++) {
            cell = new Cell(memoryItemch[i]);
            cell.setBackgroundColor(Color.LIGHT_GRAY);
            // cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            aTable2.addCell(cell);
        }
        // 
        for (int i = 0; i < Memory.size(); i++) {
            aTable2.addCell("");
            Hashtable mhash = (Hashtable) (Memory.get(new Integer(i)));
            String name = (String) mhash.get("name");
            Cell cell1 = new Cell(name);
            aTable2.addCell(cell1);
            for (int j = 0; j < memoryItem.length; j++) {
                String value = "";
                if (mhash.get(memoryItem[j]) != null) {
                    value = (String) mhash.get(memoryItem[j]);
                }
                Cell cell2 = new Cell(value);
                aTable2.addCell(cell2);
            }
            String value = "";
            if (memMaxHash.get(name) != null) {
                value = (String) memMaxHash.get(name);
                Cell cell3 = new Cell(value);
                aTable2.addCell(cell3);
            }
            String avgvalue = "";
            if (memAvgHash.get(name) != null) {
                avgvalue = (String) memAvgHash.get(name);
                aTable2.addCell(avgvalue);
            }

        } // end 
          // 
        Image img2 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "memory" + ".png");
        img.setAbsolutePosition(0, 0);
        img.setAlignment(Image.MIDDLE);// 
        document.add(aTable2);
        document.add(img2);
    } else {
        Table aTable2 = new Table(6);
        float[] widthss = { 220f, 300f, 220f, 220f, 220f, 220f };
        aTable2.setWidths(widthss);
        aTable2.setWidth(100); //  90%
        aTable2.setAlignment(Element.ALIGN_CENTER);// 
        aTable2.setAutoFillEmptyCells(true); // 
        aTable2.setBorderWidth(1); // 
        aTable2.setBorderColor(new Color(0, 125, 255)); // 
        aTable2.setPadding(2);// 
        aTable2.setSpacing(0);// 
        aTable2.setBorder(2);// 
        aTable2.endHeaders();
        cell = new Cell("");
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        aTable2.addCell(cell);
        cell = new Cell("");
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        aTable2.addCell(cell);
        // 

        for (int i = 0; i < memoryItemch.length; i++) {
            cell = new Cell(memoryItemch[i]);
            cell.setBackgroundColor(Color.LIGHT_GRAY);
            aTable2.addCell(cell);
        }
        // 
        String[] names = null;
        HostNodeDao dao = new HostNodeDao();
        HostNode node = (HostNode) dao.findByCondition("ip_address", ip).get(0);
        // Monitoriplist monitor = monitorManager.getByIpaddress(ip);
        if (node.getSysOid().startsWith("1.3.6.1.4.1.311")) {
            names = new String[] { "PhysicalMemory", "VirtualMemory" };
        } else {
            names = new String[] { "PhysicalMemory", "SwapMemory" };
        }
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            aTable2.addCell("");
            cell = new Cell(names[i]);
            aTable2.addCell(cell);

            for (int j = 0; j < memoryItem.length; j++) {
                // 
                String value = "";
                Cell cell1 = new Cell(value);
                aTable2.addCell(cell1);
            }
            String value = "";
            if (memMaxHash.get(name) != null) {
                value = (String) memMaxHash.get(name);
                Cell cell2 = new Cell(value);
                aTable2.addCell(cell2);
            } else {
                Cell cell3 = new Cell(value);
                aTable2.addCell(cell3);
            }
            String avgvalue = "";
            if (memAvgHash.get(name) != null) {
                avgvalue = (String) memAvgHash.get(name);
                Cell cell4 = new Cell(avgvalue);
                aTable2.addCell(cell4);
            } else {
                Cell cell5 = new Cell(avgvalue);
                aTable2.addCell(cell5);
            }

        } // end 
          // 
        Image img2 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "memory" + ".png");
        img.setAbsolutePosition(0, 0);
        img.setAlignment(Image.MIDDLE);// 
        document.add(aTable2);
        document.add(img2);

    }
    Table aTable3 = new Table(5);
    float[] widthss1 = { 220f, 440f, 150f, 150f, 220f };
    aTable3.setWidths(widthss1);
    aTable3.setWidth(100); //  90%
    aTable3.setAlignment(Element.ALIGN_CENTER);// 
    aTable3.setAutoFillEmptyCells(true); // 
    aTable3.setBorderWidth(1); // 
    aTable3.setBorderColor(new Color(0, 125, 255)); // 
    aTable3.setPadding(2);// 
    aTable3.setSpacing(0);// 
    aTable3.setBorder(2);// 
    aTable3.endHeaders();
    if (Disk != null && Disk.size() > 0) {
        cell = new Cell("");
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        aTable3.addCell(cell);
        cell = new Cell("");
        cell.setBackgroundColor(Color.LIGHT_GRAY);
        aTable3.addCell(cell);

        for (int i = 0; i < diskItemch.length; i++) {
            cell = new Cell(diskItemch[i]);
            cell.setBackgroundColor(Color.LIGHT_GRAY);
            aTable3.addCell(cell);
        }
        // 

        for (int i = 0; i < Disk.size(); i++) {
            aTable3.addCell("");
            Hashtable diskhash = (Hashtable) (Disk.get(new Integer(i)));
            String name = (String) diskhash.get("name");
            cell = new Cell(name);
            aTable3.addCell(cell);
            for (int j = 0; j < diskItem.length; j++) {
                String value = "";
                if (diskhash.get(diskItem[j]) != null) {
                    value = (String) diskhash.get(diskItem[j]);
                }
                Cell cell1 = new Cell(value);
                // System.out.println(value+"================value===============");
                aTable3.addCell(cell1);
            }
        } // end 
          // 
        Image img3 = Image.getInstance(ResourceCenter.getInstance().getSysPath() + "/resource/image/jfreechart/"
                + newip + "disk" + ".png");
        img.setAbsolutePosition(0, 0);
        img.setAlignment(Image.MIDDLE);// 
        document.add(aTable3);
        document.add(img3);

    }
    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 img3 = Image.getInstance(baos.toByteArray());
        img.setAbsolutePosition(0, 0);
        img.setAlignment(Image.MIDDLE);// 

        document.add(img3);
    }
    document.close();
}

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

public void createReport_pingDoc(String file) throws DocumentException, IOException {
    String starttime = (String) reportHash.get("starttime");
    String totime = (String) reportHash.get("totime");

    String hostname = (String) reportHash.get("equipname");
    String ip = (String) reportHash.get("ip");
    String newip = doip(ip);/*from   w w w .  j  a va 2  s.com*/
    // WritableSheet sheet = wb.createSheet(hostname + "", 0);
    Hashtable CPU = (Hashtable) reportHash.get("CPU");
    if (CPU == null)
        CPU = new Hashtable();
    String Ping = (String) reportHash.get("Ping");
    Calendar colTime = (Calendar) reportHash.get("time");
    Date cc = colTime.getTime();
    Hashtable Memory = (Hashtable) reportHash.get("Memory");
    Hashtable Disk = (Hashtable) reportHash.get("Disk");

    Hashtable memMaxHash = (Hashtable) reportHash.get("memmaxhash");
    Hashtable memAvgHash = (Hashtable) reportHash.get("memavghash");
    Hashtable maxping = (Hashtable) reportHash.get("ping");

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

    String[] memoryItemch = { "", "", "", "" };
    String[] memoryItem = { "Capability", "Utilization" };
    String[] diskItem = { "AllSize", "UsedSize", "Utilization" };
    String[] diskItemch = { "", "", "" };
    // 
    Document document = new Document(PageSize.A4);
    // (Writer)document(Writer)
    RtfWriter2.getInstance(document, new FileOutputStream(file));
    document.open();
    // 
    BaseFont bfChinese = BaseFont.createFont("Times-Roman", "", BaseFont.NOT_EMBEDDED);
    // 
    Font titleFont = new Font(bfChinese, 12, Font.BOLD);
    // 
    Font contextFont = new Font(bfChinese, 10, Font.NORMAL);
    Paragraph title = new Paragraph(hostname + "");
    // 
    title.setAlignment(Element.ALIGN_CENTER);
    // title.setFont(titleFont);
    document.add(title);
    String contextString = ":" + impReport.getTimeStamp() + " \n"// 
            + ":" + starttime + "  " + totime;
    Paragraph context = new Paragraph(contextString);
    // 
    context.setAlignment(Element.ALIGN_LEFT);
    // context.setFont(contextFont);
    // 
    context.setSpacingBefore(5);
    // 
    context.setFirstLineIndent(5);
    document.add(context);
    Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.black);
    Table aTable = new Table(4);
    float[] widths = { 220f, 300f, 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();

    aTable.addCell("");
    aTable.addCell("");
    aTable.addCell("");
    aTable.addCell("");
    // aTable.addCell("3.2",Ping+"%");
    aTable.addCell("");
    aTable.addCell(Ping + "%");
    aTable.addCell((String) maxping.get("pingmax"));
    aTable.addCell((String) maxping.get("avgpingcon"));
    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.close();
}