XML Publisher Using API’s(转)

本文深入探讨了XMLPublisher中应用程序层API的功能,包括如何通过API存储和管理数据源、模板,以及如何操作数据源API和模板API。详细介绍了创建、更新、删除数据源定义文件和样本文件的方法,以及下载、上传模板文件的过程,并阐述了如何应用模板到数据源生成输出文档。

原文地址:XML Publisher Using API’s

Applications Layer APIs
The applications layer of XML Publisher allows you to store and manager data sources
and templates through the Template Manager user interface via the XML Publisher
Administrator responsibility. You can also access and manipulate these objects via an
application program interfaces.


Data sources and templates are stored in the database. This includes the metadata
describing the object and the physical object itself (for example, an RTF file). Use these
APIs to register, update, and retrieve information about datasources and templates. You
can also call use the APIs to call XML Publisher to apply a template to a data source to
generate output documents directly (without going through the concurrent manager).


Datasource APIs
The following APIs are provided to access and manipulate the data definitions
programmatically:
• DataSource Class
The data source acts as a placeholder object against which you register templates. The
DataSource class represents a single data source definition entry.
• DataSourceHelper Class
This is a utility class that can be used to manage data source definition entries in the
Template Manager repository.


Getting AppsContext
All methods require the AppsContext instance to communicate with the Applications
database like If you are using this class in a Java concurrent program, pass CpContext as an
AppsContext.


Creating Data Source Definition Entries
Add a new data source definition entry to the Template Manager repository as follows:
1. Create an instance of the DataSource class by calling the
DataSource.createInstance() method.
2. Set the attributes of the instance.
3. Pass it to the DataSourceHelper.createDataSource()method.


Adding, Updating, and Deleting Schema Files and Sample Files
You can add, update and delete the data source schema definition file and the sample
XML file by calling methods defined in the DataSourceHelper class. Please note that
unlike the deleteDataSource() method described above, these methods actually
delete the schema file and sample records from the repository.
Example
// Add a schema definition file
DataSourceHelper.addSchemaFile(ctx, “XDO”, “TestDataSource”,
“schema.xsd”, new FileInputStream(“/path/to/schema.xsd”));
// Add a sample xml data file
DataSourceHelper.addSampleFile(ctx, “XDO”, “TestDataSource”,
“sample.xml”, new FileInputStream(“/path/to/sample.xml”));
// Update a schema definition file
DataSourceHelper.addSchemaFile(ctx, “XDO”, “TestDataSource”,
new FileInputStream(“/path/to/new_schema.xsd”));
// Update a sample xml data file
DataSourceHelper.addSampleFile(ctx, “XDO”, “TestDataSource”,
new FileInputStream(“/path/to/new_sample.xml”));
// Delete a schema definition file
DataSourceHelper.deleteSchemaFile(ctx, “XDO”, “TestDataSource”);
// Delete a sample xml data file
DataSourceHelper.deleteSampleFile(ctx, “XDO”, “TestDataSource”);


Getting Schema Files and Sample Files from the Repository
You can download schema files or sample files from the repository by calling the
getSchemaFile() or the getSampleFile() method. These methods return an
InputStream connected to the file contents as a return value.
The sample code is as follows:
Example
// Download the schema definition file from the repository
InputStream schemaFile = DataSourceHelper.getSchemaFile(ctx, “XDO”, “TestDataSource”, );
// Download the XML sample data file from the repository
InputStream sampleFile = DataSourceHelper.getSampleFile(ctx, “XDO”, “TestDataSource”, );


Template APIs
Multiple template objects can be associated with a single data source. The Template
class represents a single template instance. The TemplateHelper class is a utility class
used to create and update template objects in the Template Manager.


The Template Class
The Template class represents a single template object in the template manager. It is
associated with a data source object. The class has several get and set methods to
manipulate the template object.
TemplateHelper Class
The TemplateHelper class is a utility class to manage the template entries in the
Template Manager repository. It consists of a set of static utility methods.


Creating Template EntriesTo add a new template entry to the Template Manager repository:
1. Create an instance of the Template class by calling the
Template.createInstance() method
2. Set the attributes of the instance.
3. Pass it to the TemplateHelper.createTemplate() method
Example
// Create an instance
Template t = Template.createInstance(appsContext, “XDO”,”TestTemplate”,
TypeDefinitions.TEMPLATE_TYPE_PDF, “XDO”, “TestTemplate”);
// Set properties
t.setDescription(“This is the test template entry.”);
t.setStartDate(new java.sql.Date(System.currentTimeMillis()));
t.setName(“Test template !”);
t.setStatus(TypeDefinitions.TEMPLATE_STATUS_ENABLED);
// Call createTemplate() to create an entry into the repository
TemplateHelper.createTemplate(am, t);


Where am = oracle apps module.


Adding, Updating, and Deleting Template Files
You can add, update and delete template files by calling methods defined in the
TemplateHelper class.


Example
// Add English template file to the template entry
TemplateHelper.addTemplateFile(
appsContext, // AppsContext
“XDO”, // Application short name of the template
“TestTemplate”, // Template code of the template
“en”, // ISO language code of the template
“US”, // ISO territory code of the template
Template.TEMPLATE_TYPE_PDF, // Type of the template file
“us.pdf”, // Filename of the template file
new FileInputStream(“/path/to/us.pdf”)); // Template file


// Add Japanese template file to the template entry
TemplateHelper.addTemplateFile(
appsContext, // AppsContext
“XDO”, // Application short name of the template
“TestTemplate”, // Template code of the template
“ja”, // ISO language code of the template
“JP”, // ISO territory code of the template
Template.TEMPLATE_TYPE_PDF, // Type of the template file
“ja.pdf”, // Filename of the template file
new FileInputStream(“/path/to/ja.pdf”)); // Template file


// Update English template file to the template entry
TemplateHelper.updateTemplateFile(
appsContext, // AppsContext
“XDO”, // Application short name of the template
“TestTemplate”, // Template code of the template
“en”, // ISO language code of the template
“US”, // ISO territory code of the template
Template.TEMPLATE_TYPE_PDF, // Type of the template file
“us.pdf”, // Filename of the template file
new FileInputStream(“/path/to/new/us.pdf”)); // Template file


// Delete Japanese template file to the template entry
TemplateHelper.deleteTemplateFile(
appsContext, // AppsContext
“XDO”, // Application short name of the template
“TestTemplate”, // Template code of the template
“ja”, // ISO language code of the template
“JP”); // ISO territory code of the template


Getting Template FilesDownload template file contents from the repository by calling the getTemplateFile() methods. These methods return an InputStream connected to
the template file as a return value.
Example
// Download the English template file from the repository
InputStream in = TemplateHelper.getTemplateFile(
appsContext, // AppsContext
“XDO”, // Application short name of the template
“TestTemplate”, // Template code of the template
“en”, // ISO language code of the template
“US”); // ISO territory code of the template


Processing TemplatesYou can apply a template, stored in the Template Manager, to an XML data source by
calling one of the processTemplate() methods. You need to pass the OutputStream
object for the destination of the processed document.
Example
// Process template
TemplateHelper.processTemplateFile(
appsContext, // AppsContext
“XDO”, // Application short name of the template
“TestTemplate”, // Template code of the template
“en”, // ISO language code of the template
“US”, // ISO territory code of the template
dataInputStream, // XML data for the template
TemplateHelper.OUTPUT_TYPE_PDF, // Output type of the procesed
document
properties, // Properties for the template processing
docOutputStream) // OutputStream where the processed document goes.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值