Docmosis API 4.5.0

com.docmosis.template.analysis.structure
Class SimpleJSONTemplateStructureProcessor

java.lang.Object
  extended bycom.docmosis.template.analysis.structure.SimpleJSONTemplateStructureProcessor
All Implemented Interfaces:
TemplateStructureProcessor
Direct Known Subclasses:
SimpleXMLTemplateStructureProcessor

public class SimpleJSONTemplateStructureProcessor
extends Object
implements TemplateStructureProcessor

This class can process a template structure and then output the template information in an JSON format. This allows automated processes to use the Docmosis template to drive various things including building input web-forms or sample/data processes. After the processor has been used by the TemplateStructureExtractor, call the toString() function to get the JSON structure. For example:

  TemplateIdentifier templateId = new TemplateIdentifier("myTemplate1.doc");
  SimpleJSONTemplateStructureProcessor jsonProcessor = new SimpleJSONTemplateStructureProcessor();
  TemplateStructureExtractor.process(jsonProcessor, templateId);
  System.out.println(jsonProcessor.toString());
 
This class is not aware of some of the more complex elements available in templates:
   variables (eg $top)
 


Constructor Summary
SimpleJSONTemplateStructureProcessor()
           
SimpleJSONTemplateStructureProcessor(String mainKeyName)
          Create a new processor which creates a JSON object with one element using the mainKeyName name.
 
Method Summary
 void conditionalBegin(TemplateStructureElement e)
          Process the start of a conditional section
 void conditionalEnd(TemplateStructureElement e)
          Process the end of a conditional section
 void field(TemplateStructureElement e)
          Process a template field.
 void finish()
          Perform processing for the end of the template structure.
 void image(TemplateStructureElement e)
          Process a template image
 boolean repeatBegin(TemplateStructureElement e, int iterationIdx)
          Process the start of a repeating section.
 boolean repeatEnd(TemplateStructureElement e, int iterationIdx)
          Process the end of a repeating section
 void setDataReferenceCollector(DataReferenceCollector dataReferenceCollector)
           
 void start()
          Perform processing for the beginning of the template structure.
 void templateReference(TemplateStructureElement e)
          Process a reference to another template
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleJSONTemplateStructureProcessor

public SimpleJSONTemplateStructureProcessor()

SimpleJSONTemplateStructureProcessor

public SimpleJSONTemplateStructureProcessor(String mainKeyName)
Create a new processor which creates a JSON object with one element using the mainKeyName name. The value associated is the array of elements from the template.

Parameters:
mainKeyName - if null, the structure returned (by toString()) will be a JSON array instead of a JSON Object containing the array.
Method Detail

start

public void start()
Description copied from interface: TemplateStructureProcessor
Perform processing for the beginning of the template structure.

Specified by:
start in interface TemplateStructureProcessor

finish

public void finish()
Description copied from interface: TemplateStructureProcessor
Perform processing for the end of the template structure.

Specified by:
finish in interface TemplateStructureProcessor

field

public void field(TemplateStructureElement e)
Description copied from interface: TemplateStructureProcessor
Process a template field.

Specified by:
field in interface TemplateStructureProcessor
Parameters:
e - the field details

image

public void image(TemplateStructureElement e)
Description copied from interface: TemplateStructureProcessor
Process a template image

Specified by:
image in interface TemplateStructureProcessor
Parameters:
e - the image details

templateReference

public void templateReference(TemplateStructureElement e)
Description copied from interface: TemplateStructureProcessor
Process a reference to another template

Specified by:
templateReference in interface TemplateStructureProcessor
Parameters:
e - the template reference details

repeatBegin

public boolean repeatBegin(TemplateStructureElement e,
                           int iterationIdx)
Description copied from interface: TemplateStructureProcessor
Process the start of a repeating section. This method will be called again if the call to repeatEnd for this section returns true (and the iterationIdx will be incremented). This allows the content of the repeating section to be repeated if the TemplateStructureProcessor wishes to repeatedly process this section. This is useful when building data for a template.

Specified by:
repeatBegin in interface TemplateStructureProcessor
Parameters:
e - the section details
iterationIdx - the index of the iteration of this repeating section starting at zero
Returns:
true if this repeat is to be processed. Return false to ignore this section (which stops calls for all content and the call to repeatEnd()).

repeatEnd

public boolean repeatEnd(TemplateStructureElement e,
                         int iterationIdx)
Description copied from interface: TemplateStructureProcessor
Process the end of a repeating section

Specified by:
repeatEnd in interface TemplateStructureProcessor
Parameters:
e - the section details
iterationIdx - the index of the iteration of this repeating section starting at zero
Returns:
true to iterate this repeating section again

conditionalBegin

public void conditionalBegin(TemplateStructureElement e)
Description copied from interface: TemplateStructureProcessor
Process the start of a conditional section

Specified by:
conditionalBegin in interface TemplateStructureProcessor
Parameters:
e - the section details

conditionalEnd

public void conditionalEnd(TemplateStructureElement e)
Description copied from interface: TemplateStructureProcessor
Process the end of a conditional section

Specified by:
conditionalEnd in interface TemplateStructureProcessor
Parameters:
e - the section details

toString

public String toString()

setDataReferenceCollector

public void setDataReferenceCollector(DataReferenceCollector dataReferenceCollector)

Docmosis API 4.5.0

Copyright © 2014 Docmosis Pty Ltd. All Rights Reserved.