tags:

views:

24

answers:

1

Here is My Code.

private void getActionItems(Document document, Chapter chapter, 
                                     Section section, Paragraph pas) {
      List drbRefList = null;
      try {
          _actionService = new ActionItemImpl();
          _aiBean = new ActionItemData();
          if (_aiBean != null) {
          _actionList = new ArrayList();
          LOG.info("business passed here is" + _business);
         _actionList = _actionService.getActionItemsForPDF(_userSSOID, 
                 _business, _reviewID, _connection); 
          }
         LOG.info(" after calling getActionItemsForPDF");
         LOG.info("_actionList" +  _actionList);

        Table tablesh1 = new Table(1, 1);
        float[] widthsh1 = new float[1];
        widthsh1[0] = ReviewConstants.MAGIC_DOTTWELVE;
        tablesh1.setTableFitsPage(true);
        tablesh1.setPadding(2);
        tablesh1.setSpacing(0);
        tablesh1.setWidth(ReviewConstants.MAGIC_ONEZEROZERO);
        tablesh1.setWidths(widthsh1);
        tablesh1.setBorderColor(Color.WHITE);
        Cell hcell = new Cell(new Paragraph(ReviewConstants.S_ACTIONHEADING, 
                   new Font(Font.HELVETICA, fontSize, Font.BOLD, Color.BLUE)));
        hcell.setHeader(true);
        tablesh1.addCell(hcell);
        section.add(tablesh1);
        Table actionTable = null;
        String businessUnit = reviewData.getBusinessUnit();
        float[] widthac = null;
        //Updated for Nuclear Energy Engineering Business Unit Requirement by Naveen
        if(!"Nuclear Energy Engineering".equalsIgnoreCase(businessUnit)){
            actionTable = new Table(ReviewConstants.NINE,ReviewConstants.THREE);
            widthac = new float[ReviewConstants.NINE];
            widthac[0] = ReviewConstants.MAGIC_DOTONE;
            widthac[1] = ReviewConstants.MAGIC_DOTONEZERO;
            widthac[2] = ReviewConstants.MAGIC_DOTTWOZERO;      
            widthac[ReviewConstants.THREE] = ReviewConstants.MAGIC_DOTTWOZERO;  
            widthac[ReviewConstants.FOUR] = ReviewConstants.MAGIC_DOTONEZERO;
            widthac[ReviewConstants.FIVE] = ReviewConstants.MAGIC_DOTONEZERO;
            widthac[ReviewConstants.SIX] = ReviewConstants.MAGIC_DOTONEZERO;
            widthac[ReviewConstants.SEVEN] = ReviewConstants.MAGIC_DOTONEZERO;
            widthac[ReviewConstants.EIGHT] = ReviewConstants.MAGIC_DOTONEZERO;
        }else{
            actionTable = new Table(ReviewConstants.SIX,ReviewConstants.THREE);
            widthac = new float[ReviewConstants.SIX];
            widthac[0] = ReviewConstants.MAGIC_DOTONE;
            widthac[1] = ReviewConstants.MAGIC_THREEZERO;
            widthac[2] = ReviewConstants.MAGIC_THREEZERO;
            widthac[ReviewConstants.THREE] = ReviewConstants.MAGIC_THREEZERO;
            widthac[ReviewConstants.FOUR] = ReviewConstants.MAGIC_DOTONEZERO;
            widthac[ReviewConstants.FIVE] = ReviewConstants.MAGIC_DOTONEZERO;
        }
        actionTable.setTableFitsPage(true);
        actionTable.setPadding(2);
        actionTable.setSpacing(0);
        actionTable.setWidth(ReviewConstants.MAGIC_ONEZEROZERO);
        actionTable.setWidths(widthac);
        actionTable.setBorderWidth(1);
        Cell accell = new Cell(new Paragraph(ReviewConstants.S_ACTIONID,
                 new Font(Font.HELVETICA, fontSize, Font.BOLD)));
        accell.setHeader(true);
        actionTable.addCell(accell);

        if(!"Nuclear Energy Engineering".equalsIgnoreCase(businessUnit)){
            accell = new Cell(new Paragraph(ReviewConstants.PDF_RT,
                     new Font(Font.HELVETICA, fontSize, Font.BOLD)));
            accell.setHeader(true);
            actionTable.addCell(accell);
        }
        accell = new Cell(new Paragraph(ReviewConstants.S_REQA,
                 new Font(Font.HELVETICA, fontSize, Font.BOLD)));
        accell.setHeader(true);
        actionTable.addCell(accell);        
        accell = new Cell(new Paragraph(ReviewConstants.S_CLOSURE, 
                 new Font(Font.HELVETICA, fontSize, Font.BOLD)));
        accell.setHeader(true);
        actionTable.addCell(accell);

        accell = new Cell(new Paragraph(ReviewConstants.S_DISPOSITION, 
                 new Font(Font.HELVETICA, fontSize, Font.BOLD)));
        accell.setHeader(true);
        actionTable.addCell(accell);
        //added by santosh on 18 june 
        actionTable.endHeaders();
        document.add(actionTable);

        if(!"Nuclear Energy Engineering".equalsIgnoreCase(businessUnit)){
            accell = new Cell(new Paragraph(ReviewConstants.S_DRB_REFERENCE, new Font(
                        Font.HELVETICA, fontSize, Font.BOLD))); 
            accell.setHeader(true);
            actionTable.addCell(accell);
            accell = new Cell(new Paragraph(ReviewConstants.S_DEADLINE, new Font(
                        Font.HELVETICA, fontSize, Font.BOLD))); 
            accell.setHeader(true);
            actionTable.addCell(accell);
        }
        accell = new Cell(new Paragraph(ReviewConstants.S_OWNER, new Font(
                    Font.HELVETICA, fontSize, Font.BOLD))); 
        accell.setHeader(true);
        actionTable.addCell(accell);
        accell = new Cell(new Paragraph(ReviewConstants.S_STATE, new Font(
                Font.HELVETICA, fontSize, Font.BOLD))); 
        accell.setHeader(true);
        actionTable.addCell(accell);
        int acSize = 0;
        if (_actionList != null) {
            acSize = _actionList.size();
        }
        for (int i = 0; i < acSize; i++) { 
        _aiBean = (ActionItemData) _actionList.get(i);      
        Cell adCell = new Cell(new Paragraph(_aiBean.getActionID(), new Font(
                    Font.HELVETICA, ReviewConstants.MAGIC_EIGHT))); 
        adCell.setHeader(false);
        actionTable.addCell(adCell);

        if(!"Nuclear Energy Engineering".equalsIgnoreCase(businessUnit)){
            if (_aiBean.getActionItemType().equals("0")) {
            adCell = new Cell(new Paragraph("Normal", 
                    new Font(Font.HELVETICA, fontSize))); 
            } else {
                adCell = new Cell(new Paragraph("Critical", 
                        new Font(Font.HELVETICA, fontSize))); 
            }       
            adCell.setHeader(false);
            actionTable.addCell(adCell);
        }
        adCell = new Cell(new Paragraph(_aiBean.getRequiredAction(), 
                        new Font(Font.HELVETICA, fontSize))); 
        adCell.setHeader(false);
        actionTable.addCell(adCell);
        adCell = new Cell(new Paragraph(_aiBean.getClosureCriteria(), 
                        new Font(Font.HELVETICA, fontSize))); 
        adCell.setHeader(false);
        actionTable.addCell(adCell);
        String drbLink = ReviewConstants.EMPTY;
        drbRefList = new ArrayList();
        if (!DRUtils.isEmpty(_aiBean.getState())
                        && ((_aiBean.getState()
                                .equalsIgnoreCase(ReviewConstants.DRAFT_BEGUN_STATE))
                                || (_aiBean.getState()
                                        .equalsIgnoreCase(ReviewConstants.SCOPE_PROPOSED)) || (_aiBean
                                .getState()
                                .equalsIgnoreCase(ReviewConstants.RES_PROPOSED)))) {
                     drbLink = ReviewConstants.EMPTY;
                    _aiBean.setDisposition(ReviewConstants.EMPTY);

                } else {                    
                    drbRefList = _actionService.getDrbRefForPDF(_aiBean.getActionSeqID(), _connection);
                    int drbRefCnt = 0;
                    if (drbRefList != null) {
                        drbRefCnt = drbRefList.size();
                        int j = 0;
                        for (j = 0; j < drbRefCnt; j++) {
                            LOG.info("drbRefList.get(j)"
                                    + drbRefList.get(j).toString());
                            if (j < (drbRefCnt - 1)) {
                                drbLink += drbRefList.get(j).toString()
                                        + ReviewConstants.COMMA_SPACE;
                            } else {
                                drbLink += drbRefList.get(j).toString();
                            }
                        }
                    }
                }
        LOG.info("drbLink" + drbLink);  
        adCell = new Cell(new Paragraph(_aiBean.getDisposition(), 
                new Font(Font.HELVETICA, fontSize))); 
        adCell.setHeader(false);
        actionTable.addCell(adCell);
        //Updated for Nuclear Energy Engineering Business Unit Requirement by Naveen
        if(!"Nuclear Energy Engineering".equalsIgnoreCase(businessUnit)){
            adCell = new Cell(new Paragraph(drbLink, new Font(
                    Font.HELVETICA, fontSize)));
            adCell.setHeader(false);
            actionTable.addCell(adCell);        
            adCell = new Cell(new Paragraph(_aiBean.getDeadline(), 
                            new Font(Font.HELVETICA, fontSize))); 
            adCell.setHeader(false);
            actionTable.addCell(adCell);
        }
        adCell = new Cell(new Paragraph(_aiBean.getActionItemOwnerName(), 
                        new Font(Font.HELVETICA, fontSize)));
        adCell.setHeader(false);
        actionTable.addCell(adCell);
        adCell = new Cell(new Paragraph(_aiBean.getState(), 
                new Font(Font.HELVETICA, fontSize)));
        adCell.setHeader(false);
        actionTable.addCell(adCell);
        //added by santosh
        actionTable.endHeaders();
        document.add(actionTable);
        // added by santosh end
        }

        /*Phrase headerPhrase = new Phrase();
        Table headTab = (Table)actionTable.getElement(0, 5);
        headerPhrase.add(headTab);
        HeaderFooter printHeader = new HeaderFooter(headerPhrase,false);
        System.out.println("addHeader");
        document.setHeader(printHeader);
        actionTable.setLastHeaderRow(1);

        actionTable.endHeaders();
        document.add(actionTable);*/
        // added by santosh
        actionTable.endHeaders();
        document.add(actionTable);
        // added by santosh end
         section.add(actionTable);

     }  catch (Exception e) {
        LOG.error("General Exception occured", e);
      }
  }
A: 

I suggest you to use JasperReports as a template design & execution framework. It does use iText under the hood. This and many other similar tasks can be done declaratively using iReports design tool.

Boris Pavlović