|
Docmosis API 3.0.1 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.docmosis.document.DocumentProcessor
This class is the entry point for controlling the production of documents. Templates that have been previously registered with the configured TemplateStore can be merged with data to provide the resulting document(s). The process is fairly simple:
1. register templates (only needs to be done once and whenever templates change) 2. identify the template and the data source 3. identify the output formats and destination 4. call the renderDoc() methodHere is a simple example of use:
// one off initialise - just done at application launch (or first // render) SystemManager.initialise(); try { DataProviderBuilder dpb = new DataProviderBuilder(); dpb.add("name", "James"); dpb.add("state", "CA"); DocumentProcessor.renderDoc(new File("myTemplate.doc"), new File( "myResult.pdf"), dpb.getDataProvider()); } finally { // shutdown (would not do this for each document render, just at // system shutdown) SystemManager.release(); }Here is a longer example:
// initialise from configuration specified by classpath SystemManager.initialise(); try { TemplateStore store = TemplateStoreFactory.getStore(); // Store a new template into the Template Store under the // name FirstTest. TemplateIdentifier templateId = StoreHelper.storeTemplate( "FirstTest", new File( "c:/docs/testDoc.doc"), store); // the templateId can also be manually created (if you know // the template is already registered) like this: // TemplateIdentifier templateId = new TemplateIdentifier("FirstTest"); // create some data to push into the template DataProviderBuilder dpb = new DataProviderBuilder(); dpb.add("Name", "Person Alpha"); dpb.add("Addr", "10 The Pond, Froggsville"); dpb.add("DOB", "16 Mar 2002"); dpb.add("dateReported", "10/3/07"); dpb.add("recordNumber", "1638.4"); // create the instruction for processing. PDF and WORD format implies a zip archive ConversionInstruction conversionInstruction = new ConversionInstruction(); conversionInstruction.setConversionFormats(new ConversionFormat[] { ConversionFormat.FORMAT_PDF, ConversionFormat.FORMAT_WORD }); // files inside the zip will use this as the basis for their name conversionInstruction.setOutputFileName("testResult"); OutputStream out = null; try { // Store output in this file (named zip because multiple formats will produce a zip file) final String outName = "c:/docs/firstTest.zip"; try { out = new FileOutputStream(outName); // Render the document DocumentProcessor. renderDoc(templateId, dpb.getDataProvider(), conversionInstruction, out); } finally { FileUtilities.close(out); } } finally { FileUtilities.close(out); } } finally { // shutdown (would not do this for each document render, just at system shutdown) SystemManager.release(); }
Constructor Summary | |
DocumentProcessor()
|
Method Summary | |
static int |
getOnlineConverterCount()
Get the number of converters online for the default converter pool group. |
static int |
getOnlineConverterCount(String groupName)
Get the number of converters online for the named converter pool group. |
static boolean |
hasOnlineConverters()
Determine if there are any online converters in the default Converter Pool Group. |
static boolean |
hasOnlineConverters(String groupName)
Determine if there are any online converters in the given Converter Pool Group. |
static DocumentRenderResult |
renderDoc(File template,
File outputFile,
DataProvider dp)
Render the given template to the given output file with the given data. |
static DocumentRenderResult |
renderDoc(File template,
File outputFile,
DataProvider dp,
boolean cleanupDataProvider)
Render the given template to the given output file with the given data. |
static DocumentRenderResult |
renderDoc(File template,
OutputStream outputStream,
ConversionFormat format,
DataProvider dp)
Render the given template to the given output stream with the given data. |
static DocumentRenderResult |
renderDoc(File template,
OutputStream outputStream,
ConversionFormat format,
DataProvider dp,
boolean cleanupDataProvider)
Render the given template to the given output stream with the given data. |
static DocumentRenderResult |
renderDoc(RenderRequest request)
Execute a render using the given render request. |
static DocumentRenderResult |
renderDoc(TemplateIdentifier templateId,
DataProvider dp,
ConversionInstruction instruction,
OutputStream streamTo)
Render the template specified by the given templateId with the given data according to the given instruction. |
static void |
setDefaultRenderer(Class forClass,
FieldRenderer renderer)
Set a "default" renderer against the given Class for system wide use. |
static void |
setDefaultRenderer(String name,
FieldRenderer renderer)
Set a "default" renderer against the given name for system wide use. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DocumentProcessor()
Method Detail |
public static DocumentRenderResult renderDoc(TemplateIdentifier templateId, DataProvider dp, ConversionInstruction instruction, OutputStream streamTo) throws IOException, ProcessingException, TemplateStoreException
templateId
- the identifier of the template to renderdp
- the DataProvider containing the datainstruction
- the ConversionInstruction controlling aspects of the renderstreamTo
- the destination stream for the resulting document(s)
IOException
- if an IO problem occurs
ProcessingException
- if a problem occurs processing the template
TemplateStoreException
- if the template cannot be found or the template
store has a problem.ConversionInstruction
,
TemplateIdentifier
,
DataProvider
,
Cleanable
,
ImageScalingDefault
public static DocumentRenderResult renderDoc(RenderRequest request) throws IOException, ProcessingException, TemplateStoreException, ConversionException, NoConvertersRunningException
IOException
- if an IO problem occurs
ProcessingException
- if a problem occurs processing the template
TemplateStoreException
- if the template cannot be found or the template
store has a problem.
ConversionException
- if there is a problem with converting the document
NoConvertersRunningException
- if there are no operational convertersRenderRequest
public static DocumentRenderResult renderDoc(File template, File outputFile, DataProvider dp) throws IOException, ProcessingException, TemplateStoreException, ConversionException, NoConvertersRunningException
template
- the template file to useoutputFile
- the location to place the outputdp
- the data to populate with
IOException
- if an IO problem occurs
ProcessingException
- if a general processing problem occurs.
TemplateStoreException
- if there is a problem with the store configuration
ConversionException
- if the template or document cannot be processed
NoConvertersRunningException
- if the system has not initialised correctly.public static DocumentRenderResult renderDoc(File template, File outputFile, DataProvider dp, boolean cleanupDataProvider) throws IOException, ProcessingException, TemplateStoreException, ConversionException, NoConvertersRunningException
if (dp instanceof Cleanable) {
((Cleanable)dp).cleanup();
}
The default configured template store will be used to retrieve templates.
template
- the template file to useoutputFile
- the location to place the outputdp
- the data to populate withcleanupDataProvider
- if false, the DataProvider will not be cleaned up
allowing the same data to be used to make multiple calls.
IOException
- if an IO problem occurs
ProcessingException
- if a general processing problem occurs.
TemplateStoreException
- if there is a problem with the store configuration
ConversionException
- if the template or document cannot be processed
NoConvertersRunningException
- if the system has not initialised correctly.public static DocumentRenderResult renderDoc(File template, OutputStream outputStream, ConversionFormat format, DataProvider dp) throws IOException, ProcessingException, TemplateStoreException, ConversionException, NoConvertersRunningException
template
- the template file to useoutputStream
- the stream to which the resulting document will be sentformat
- the format in which to render the resulting documentdp
- the data to populate with
IOException
- if an IO problem occurs
ProcessingException
- if a general processing problem occurs.
TemplateStoreException
- if there is a problem with the store configuration
ConversionException
- if the template or document cannot be processed
NoConvertersRunningException
- if the system has not initialised correctly.public static DocumentRenderResult renderDoc(File template, OutputStream outputStream, ConversionFormat format, DataProvider dp, boolean cleanupDataProvider) throws IOException, ProcessingException, TemplateStoreException, ConversionException, NoConvertersRunningException
if (dp instanceof Cleanable) {
((Cleanable)dp).cleanup();
}
The default configured template store will be used to retrieve templates.
template
- the template file to useoutputStream
- the stream to which the resulting document will be sentformat
- the format in which to render the resulting documentdp
- the data to populate withcleanupDataProvider
- if false, the DataProvider will not be cleaned up
allowing the same data to be used to make multiple calls.
IOException
- if an IO problem occurs
ProcessingException
- if a general processing problem occurs.
TemplateStoreException
- if there is a problem with the store configuration
ConversionException
- if the template or document cannot be processed
NoConvertersRunningException
- if the system has not initialised correctly.public static boolean hasOnlineConverters() throws ConverterPoolException
ConverterPoolException
- if the ConverterPool isn't initialized or
the group cannot be found.public static boolean hasOnlineConverters(String groupName) throws ConverterPoolException
groupName
- the name of the group to query or null for the default group
ConverterPoolException
- if the ConverterPool isn't initialized or
the group cannot be found.public static int getOnlineConverterCount() throws ConverterPoolException
ConverterPoolException
- if the ConverterPool isn't initialized or
the group cannot be found.public static int getOnlineConverterCount(String groupName) throws ConverterPoolException
ConverterPoolException
- if the ConverterPool isn't initialized or
the group cannot be found.public static void setDefaultRenderer(String name, FieldRenderer renderer)
ConversionInstruction
.
name
- the name against which the renderer is associatedrenderer
- the rendererpublic static void setDefaultRenderer(Class forClass, FieldRenderer renderer)
ConversionInstruction
.
forClass
- the Class against which the renderer is associatedrenderer
- the renderer
|
Docmosis API 3.0.1 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |