zoukankan      html  css  js  c++  java
  • XMLItergration.java

    /*===========================================================================+
     |   Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA    |
     |                         All rights reserved.                              |
     +===========================================================================+
     |  HISTORY                                                                  |
     +===========================================================================*/
    package oareport.oracle.apps.ak.webui;
    
    import oracle.apps.fnd.common.VersionInfo;
    import oracle.apps.fnd.framework.OAApplicationModule;
    import oracle.apps.fnd.framework.OAException;
    import oracle.apps.fnd.framework.server.OADBTransactionImpl;
    import oracle.apps.fnd.framework.webui.OAControllerImpl;
    import oracle.apps.fnd.framework.webui.OAPageContext;
    import oracle.apps.fnd.framework.webui.beans.OAWebBean;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServletResponse;
    import oracle.apps.fnd.framework.webui.beans.table.OAAdvancedTableBean;
    import oracle.apps.xdo.oa.schema.server.TemplateHelper;
    import oracle.apps.fnd.framework.OAException;
     import oracle.cabo.ui.data.DataObject;
     import oracle.apps.xdo.XDOException;
    
    import oracle.jbo.XMLInterface;
    
    import oracle.xml.parser.v2.XMLNode;
    import java.lang.System;
    import oracle.apps.xdo.oa.schema.server.TemplateInputStream;
    import oracle.apps.xdo.common.log.Logger;
    
    /**
     * Controller for ...
     */
    public class XMLIntegrationCO extends OAControllerImpl
    {
      public static final String RCS_ID="$Header$";
      public static final boolean RCS_ID_RECORDED =
            VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
    
      /**
       * Layout and page setup logic for a region.
       * @param pageContext the current OA page context
       * @param webBean the web bean corresponding to the region
       */
      public void processRequest(OAPageContext pageContext, OAWebBean webBean)
      {
        super.processRequest(pageContext, webBean);
        OAApplicationModule am= pageContext.getApplicationModule(webBean);
       // am.invokeMethod("initEmpVO");
       // am.invokeMethod("getEmpDataXML");
    
      }
    
      /**
       * Procedure to handle form submissions for form elements in
       * a region.
       * @param pageContext the current OA page context
       * @param webBean the web bean corresponding to the region
       */
      public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
      {     
           super.processFormRequest(pageContext, webBean);
        OAApplicationModule am= (OAApplicationModule)pageContext.getApplicationModule(webBean);
        //String event = pageContext.getParameter("event");
                      DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
    
                       HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
        
        
        if(pageContext.getParameter("PrintPdf") != null)
          {
    
                      try {
    
                                               ServletOutputStream os = response.getOutputStream();
    
                                                // Set the Output Report File Name and Content Type
    
                                                String contentDisposition = "attachment;filename=PrintPage.pdf";
    
                                                response.setHeader("Content-Disposition",contentDisposition);
    
                                                response.setContentType("application/pdf");
    
                                                // Get the Data XML File as the XMLNode
    
                                                XMLNode xmlNode = (XMLNode) am.invokeMethod("getEmpDataXML");
                           
     ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                                   xmlNode.print(outputStream);
                               //    System.out.println(outputStream.toString());  
                                 ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    
                                 ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();
    
                                 //Generate the PDF Report.
    
                                 //Process Template
    
                                 TemplateHelper.processTemplate(
    
                                 ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),
    
                                 "PER",//APPLICATION SHORT NAME
    
                                 "EmpDataDT", //TEMPLATE_SHORT_CODE
    
                                 ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(),
    
                                 ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),
    
                                 inputStream,
    
                                 TemplateHelper.OUTPUT_TYPE_PDF,
    
                                 null,
    
                                 pdfFile);
    
                                   //TemplateHelper.
    
                                 // Write the PDF Report to the HttpServletResponse object and flush.
    
                                 byte[] b = pdfFile.toByteArray();
    
                                 response.setContentLength(b.length);
    
                                 os.write(b, 0, b.length);
    
                                 os.flush();
    
                                 os.close();
    
                         pdfFile.flush();
    
                         pdfFile.close();
    
                                 }
    
                                 catch(Exception e)
    
                                 {
    
                                 response.setContentType("text/html");
                                //System.out.println(e.getMessage());
                                 throw new OAException(e.getMessage(), OAException.ERROR);
    
                                 }
    
                                 pageContext.setDocumentRendered(true);
    
                                 } 
    
         
         
                      
                      if(pageContext.getParameter("PrintExcel") != null)
                        {
    
                                    try {
    
                                                             ServletOutputStream os = response.getOutputStream();
    
                                                              // Set the Output Report File Name and Content Type
    
                                                              String contentDisposition = "attachment;filename=ExcelReport.xls";
    
                                                              response.setHeader("Content-Disposition",contentDisposition);
    
                                                              response.setContentType("application/MSEXCEL");
    
                                                              // Get the Data XML File as the XMLNode
    
                                                              XMLNode xmlNode = (XMLNode) am.invokeMethod("getEmpDataXML");
                                         
                      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                                                 xmlNode.print(outputStream);
                                             //    System.out.println(outputStream.toString());  
                                               ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    
                                               ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();
    
                                               //Generate the PDF Report.
    
                                               //Process Template
    
                                               TemplateHelper.processTemplate(
    
                                               ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),
    
                                               "PER",//APPLICATION SHORT NAME
    
                                               "EmpDataDT", //TEMPLATE_SHORT_CODE
    
                                               ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(),
    
                                               ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),
    
                                               inputStream,
    
                                               TemplateHelper.OUTPUT_TYPE_EXCEL,
    
                                               null,
    
                                               pdfFile);
    
                                                 //TemplateHelper.
    
                                               // Write the PDF Report to the HttpServletResponse object and flush.
    
                                               byte[] b = pdfFile.toByteArray();
    
                                               response.setContentLength(b.length);
    
                                               os.write(b, 0, b.length);
    
                                               os.flush();
    
                                               os.close();
    
                                       pdfFile.flush();
    
                                       pdfFile.close();
    
                                               }
    
                                               catch(Exception e)
    
                                               {
    
                                               response.setContentType("text/html");
                                              //System.out.println(e.getMessage());
                                               throw new OAException(e.getMessage(), OAException.ERROR);
    
                                               }
    
                                               pageContext.setDocumentRendered(true);
    
                                               }
         
                      if(pageContext.getParameter("PrintWord") != null)
                        {
    
                                    try {
    
                                                             ServletOutputStream os = response.getOutputStream();
    
                                                              // Set the Output Report File Name and Content Type
    
                                                              String contentDisposition = "attachment;filename=PrintPage.doc";
    
                                                              response.setHeader("Content-Disposition",contentDisposition);
    
                                                              response.setContentType("application/MSWORD");
    
                                                              // Get the Data XML File as the XMLNode
    
                                                              XMLNode xmlNode = (XMLNode) am.invokeMethod("getEmpDataXML");
                                         
                      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                                                 xmlNode.print(outputStream);
                                             //    System.out.println(outputStream.toString());  
                                               ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    
                                               ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();
    
                                               //Generate the PDF Report.
    
                                               //Process Template
    
                                               TemplateHelper.processTemplate(
    
                                               ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),
    
                                               "PER",//APPLICATION SHORT NAME
    
                                               "EmpDataDT", //TEMPLATE_SHORT_CODE
    
                                               ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(),
    
                                               ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),
    
                                               inputStream,
    
                                               TemplateHelper.OUTPUT_TYPE_RTF,
    
                                               null,
    
                                               pdfFile);
    
                                                 //TemplateHelper.
    
                                               // Write the PDF Report to the HttpServletResponse object and flush.
    
                                               byte[] b = pdfFile.toByteArray();
    
                                               response.setContentLength(b.length);
    
                                               os.write(b, 0, b.length);
    
                                               os.flush();
    
                                               os.close();
    
                                       pdfFile.flush();
    
                                       pdfFile.close();
    
                                               }
    
                                               catch(Exception e)
    
                                               {
    
                                               response.setContentType("text/html");
                                              //System.out.println(e.getMessage());
                                               throw new OAException(e.getMessage(), OAException.ERROR);
    
                                               }
    
                                               pageContext.setDocumentRendered(true);
    
                                               }
         
         
         
         
         
         
         
         
         
                    }
    
                   
                    
    
            
        
        
        
            
          
          
    }


    public XMLNode getEmpDataXML()
    {
      OAViewObject vo = (OAViewObject)findViewObject("AbcVO"); 
      XMLNode xmlNode = (XMLNode) vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS);
      return xmlNode;
    }
  • 相关阅读:
    mysql优化---订单查询优化(1):视图优化+索引创建
    docker系列(一):docker基础与安装笔记
    Linux进程管理
    scrapy-redis源码解读之发送POST请求
    anaconda虚拟环境管理,从此Python版本不用愁
    Ubuntu18.04安装mongodb
    Python开发之日志记录模块:logging
    Git学习笔记:基础篇
    python开发之虚拟环境管理:virtualenv、virtualenvwrapper、pycharm
    Python开发之序列化与反序列化:pickle、json模块使用详解
  • 原文地址:https://www.cnblogs.com/huanghongbo/p/4828372.html
Copyright © 2011-2022 走看看