|
|
发表于 2011/7/22 10:34:23
|
显示全部楼层
RTF模板,提供了数据的显示格式,而OAF程序提供数据源。
两项工作是分开来的,所以说,OAF程序又提供数据源又提供显示格式的设计本身就是不合理的。
以下是OAF提供数据源,根据RTF模板显示PDF的代码,提供参考。
1、在点击生成PDF按钮的CO中的代码
import Oracle.cabo.ui.data.DataObject;
import Oracle.jbo.domain.BlobDomain;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletOutputStream;
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
try
{
if("print".equals(pageContext.getParameter(EVENT_PARAM)))
{
OAApplicationModule am = pageContext.getApplicationModule(webBean);
Serializable[] serial = new Serializable[]{new Number(pageContext.getParameter("deptno"))};
BlobDomain blobDomain = (BlobDomain)am.invokeMethod("generatePdfDoc", serial, new Class[]{Number.class});
DataObject dataobject = pageContext.getNamedDataObject("_SessionParameters");
HttpServletResponse httpservletresponse = (HttpServletResponse)dataobject.selectValue(null, "HttpServletResponse");
int i = (int)blobDomain.getLength();
ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
if (i > 0)
{
byte abyte0[] = blobDomain.toByteArray();
httpservletresponse.setContentType("application/pdf");
httpservletresponse.setContentLength(i);
httpservletresponse.setHeader("Content-Disposition", "Attachment;Filename=BillDocument.pdf");
servletoutputstream.write(abyte0, 0, abyte0.length);
servletoutputstream.flush();
servletoutputstream.close();
}
}
}
catch (Exception e)
{
e.printStackTrace();
throw OAException.wrapperException(e);
}
}
2、相应AM中的代码
import Oracle.apps.xdo.XDOException;
import Oracle.apps.xdo.template.FOProcessor;
import Oracle.apps.xdo.template.RTFProcessor;
import Oracle.jbo.domain.BlobDomain;
import Oracle.jbo.XMLInterface;
import Oracle.xml.parser.v2.XMLNode;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
private static final String RTF_FILE = "d:\\BI_file\\15.rtf";
public BlobDomain generatePdfDoc(Number deptNum)
{
BlobDomain blobDomain = new BlobDomain();
try
{
DeptVOImpl vo = getDeptVO2();
vo.setWhereClause(null);
vo.setWhereClauseParams(null);
vo.setWhereClause(" dept_no = :1 ");
vo.setWhereClauseParam(0, deptNum);
vo.executeQuery();
//created the XSL template by RTF file.
RTFProcessor rtfP = new RTFProcessor(RTF_FILE);
ByteArrayOutputStream baosXSL = new ByteArrayOutputStream();
rtfP.setOutput(baosXSL);
rtfP.setExtractAttributeSet(RTFProcessor.EXTRACT_DISABLE);
rtfP.process();
//created the XML data by VO
ByteArrayOutputStream baosXML = new ByteArrayOutputStream();
((XMLNode)vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS)).print(baosXML);
System.out.println(baosXML.toString());
//created the PDF file by XSL and XML
FOProcessor fop = new FOProcessor();
fop.setData(new ByteArrayInputStream(baosXML.toByteArray()));
fop.setTemplate(new ByteArrayInputStream(baosXSL.toByteArray()));
fop.setOutput(blobDomain.getOutputStream());
fop.setOutputFormat(FOProcessor.FORMAT_PDF);
fop.generate();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
catch (XDOException e)
{
e.printStackTrace();
}
return blobDomain;
}
|
|