Docmosis API 4.5.0

com.docmosis.template.analysis.structure
Class TemplateStructureExtractor

java.lang.Object
  extended bycom.docmosis.template.analysis.structure.TemplateStructureExtractor

public class TemplateStructureExtractor
extends Object

This class provides a simple interpretation of the structure of a template from the given analysis. This structure can then be used with a TemplateStructureProcessor to perform different analyses or renderings of the structure. For example, a basic XML structure can be obtained with the following code which uses SimpleXMLTemplateStructureProcessor:

		final String context = "TemplateStructure";
		final String template = "basicTests.doc";
		// this code assumes you have a template in the local directory TemplateStructure called basicTests.doc
		final String templatePath = context + "/" + template;
		
		TemplateIdentifier tid = new TemplateIdentifier(template, context);
		
		TemplateStore store = TemplateStoreFactory.getStore();
		StoreHelper.storeTemplate(tid, new File(templatePath), store);
		SimpleXMLTemplateStructureProcessor collector = new SimpleXMLTemplateStructureProcessor();
		TemplateStructureExtractor.process(collector, tid);
		System.out.println(collector.toString();

 
You can implement your own version of SimpleXMLTemplateStructureProcessor by implementing the TemplateStructureProcessor interface and using it in the example code above.

See Also:
SimpleXMLTemplateStructureProcessor, TemplateStructureProcessor

Constructor Summary
TemplateStructureExtractor(TemplateAnalysis analysis)
           
 
Method Summary
 List getStructure()
          Get the recursive structure which is a List of TemplateStructureElements.
static List getStructureFromDefaultStore(TemplateIdentifier templateId)
          This is a convenience method to extract the TemplateStructure for the given template from the default template store.
 void process(TemplateStructureProcessor processor)
          Process the structure using the given processor.
static void process(TemplateStructureProcessor processor, TemplateIdentifier templateId)
          This convenience method will get the template from the default TemplateStore and extract the structure before passing it to the given processor to process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemplateStructureExtractor

public TemplateStructureExtractor(TemplateAnalysis analysis)
Method Detail

getStructureFromDefaultStore

public static List getStructureFromDefaultStore(TemplateIdentifier templateId)
                                         throws TemplateNotFoundException,
                                                TemplateStoreException
This is a convenience method to extract the TemplateStructure for the given template from the default template store.

Parameters:
templateId - the identifier for the template
Returns:
a List of #TemplateStructureElement items.
Throws:
TemplateNotFoundException - if the template could not be found
TemplateStoreException - if there an error from the template store
See Also:
TemplateStructureElement

getStructure

public List getStructure()
Get the recursive structure which is a List of TemplateStructureElements. Note that the Header and Footer elements are returned first, then the elements from the body of the template. The elements indicate whether they are in the header or footer to allow processing to determine how to represent them.

Returns:
the List.

process

public void process(TemplateStructureProcessor processor)
Process the structure using the given processor. This can be used to produce XML, JSON or any other interpretation of the template structure by providing different processor implementations.

Parameters:
processor - the processor that will be used to process the structure.

process

public static void process(TemplateStructureProcessor processor,
                           TemplateIdentifier templateId)
                    throws TemplateNotFoundException,
                           TemplateStoreException
This convenience method will get the template from the default TemplateStore and extract the structure before passing it to the given processor to process.

Parameters:
processor - the processor to use
templateId - the template to get
Throws:
TemplateStoreException - if a problem occurs getting the template from the store
TemplateNotFoundException - if the template does not exist

Docmosis API 4.5.0

Copyright © 2014 Docmosis Pty Ltd. All Rights Reserved.