Andreas Delmelle-2 wrote:
> 
> The actual FO result, or at least, the inclusion of the base XML that  
> is transformed by the stylesheet, would probably make it more useful  
> to us. The stylesheet alone is, at best, interesting to look at, but  
> of little value without the actual input.
> 

Here is the XML that we feed to the Transformer:

<?xml version="1.0" encoding="UTF-8"?>
   <Statement>
      <AccountName>[redacted]</AccountName>
      <AccountNumber>[redacted]</AccountNumber>
      <MailingAddress1>[redacted]</MailingAddress1>
      <MailingAddress2/><MailingAddress3>[redacted]</MailingAddress3>
      <StatementDate>11/01/08</StatementDate>
      <OpeningDate>10/01/08</OpeningDate>
      <ClosingDate>10/31/08</ClosingDate>
      <DaysInPeriod>31</DaysInPeriod>
      <PastDue>$45.00</PastDue>
      <Limit>$0.00</Limit>
      <Available>$0.00</Available>
      <Transaction>
         <Date/>
         <Number/>
         <Description/>
         <Amount>$0.00</Amount>
      </Transaction>
      <PreviousBalance>$247.50</PreviousBalance>
      <Advances>$0</Advances>
      <FinanceCharges>$0</FinanceCharges>
      <Credits>$0.00</Credits>
      <OtherCharges>$0.00</OtherCharges>
      <OutstandingBalance>$247.50</OutstandingBalance>
      <DailyPeriodicRate>0.4110%</DailyPeriodicRate>
      <APR>150.00%</APR>
   </Statement>

Now, here is the Struts Action execute() implementation that creates the
Transformer and does all the work:

   public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException
   {
      String forward = "error";
      StatementService serv = new StatementService();

      FsvCard card = (FsvCard)
request.getSession().getAttribute("statement_fsvCard");
      CardHolder ch = (CardHolder)
request.getSession().getAttribute("statement_cardholder");

      String cid = "";
      int year = 2007;
      int month = 6;

      int index = -1;
      try
      {
         String s = request.getParameter("i");
         index = Integer.parseInt(s);
      } catch (Exception e)
      {
         /*
          * 
          */
      }

      if (card != null)
      {
         cid = card.getFsvCustomerId();
      }

      ArrayList<String[]> statementInfoArray = null;
      Object o = request.getSession().getAttribute("statementInfoArray");
      if (o != null)
         statementInfoArray = (ArrayList<String[]>) o;
      String[] info = null;

      if (statementInfoArray != null && index != -1)
      {
         info = statementInfoArray.get(index);
      }

      if (info != null && cid != null && ch != null)
      {
         month = Integer.parseInt(info[1]);
         year = Integer.parseInt(info[2]);

         StatementBean statement = serv.getStatement(card, ch, year, month);
         Document doc = serv.statement2XML(statement);

         // Dump the XML to a file for debugging purposes only
         XMLUtil.writeToFile( doc, "statement.xml" );

         // Setup a buffer to obtain the content length
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         try
         {
            if (tFactory == null)
            {
               tFactory = TransformerFactory.newInstance();
            }

            // Setup FOP
            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
            fopFactory.setStrictValidation(true);

            // Setup Transformer
            String path = getServlet().getServletContext().getRealPath("/");
            Source xsltSrc = new StreamSource(new File(path +
"/docs/en/statement2fo.xsl"));
            Transformer transformer = tFactory.newTransformer(xsltSrc);

            // Make sure the XSL transformation's result is piped through to
FOP
            Result res = new SAXResult(fop.getDefaultHandler());

            // Setup input
            Source src = new DOMSource(doc);

            // Set an error handler to log exceptions
            transformer.setErrorListener(new ErrorListener()
            {
               public void warning(TransformerException exc) throws
TransformerException
               {
                  System.out.println("FOP WARNING: " + exc.getMessage());
                  exc.printStackTrace();
               }

               public void error(TransformerException exc) throws
TransformerException
               {
                  System.out.println("FOP ERROR: " + exc.getMessage());
                  exc.printStackTrace();
               }

               public void fatalError(TransformerException exc) throws
TransformerException
               {
                  System.out.println("FOP FATAL: " + exc.getMessage());
                  exc.printStackTrace();
               }
            });

            // Start the transformation and rendering process
            transformer.transform(src, res);

            // Prepare response
            response.setContentType("application/pdf");
            response.setContentLength(out.size());

            // Send content to Browser
            response.getOutputStream().write(out.toByteArray());
            response.getOutputStream().flush();
         } catch (Exception ex)
         {
            throw new ServletException(ex);
         } finally
         {
            // Clean-up
            out.close();
         }

         forward = "success";
      }

      return mapping.findForward(forward);
   }


-- 
View this message in context: 
http://www.nabble.com/FOP-works-until-web-app-is-re-deployed-to-Tomcat-tp20271546p20307709.html
Sent from the FOP - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to