org.activemath.presentation.preproc
Class PreProcessor

java.lang.Object
  extended by org.activemath.presentation.preproc.PreProcessor

public class PreProcessor
extends Object

This class is responsible to pre-process an OMDoc by walking through all elements and performing Tasks on each of them.

An instance of a PreProcessor is a multi-threaded and re-usable object which runs through its run(org.jdom.Element, java.util.Map) method. At this point, the TaskFactory(ies) that are registred to this pre-processr are invoked to provide Task objects that can perform the given task for one tree-traversal.

TaskFactory(ies) provided there should keep as low as possible the number of new instances and possibly use a pool of tasks if these are expensive to build. In general, there should be two kind of tasks: the stateless, i.e.. pure functional tasks: there should be only one instance of these for everyone (a static member) and the task-factory should provide always the same. The second category are stateful tasks that need to keep data during their processing; for these tasks, the factory should either create a new one eveyr time of, ideally, use a pool.

The tree-traversal is performed using simple JDOM calls unless OJElement are around in which case, the method OJElement.getRealContent() exists. In this case only (currently), the modifications of the tasks to replace an item by another will remain.

Version:

Field Summary
static String CVS_ID
           
static boolean DEBUG
           
 List taskList
          The taskList that will be enumerated when running.
protected static Logger thisLogCat
           
 
Constructor Summary
PreProcessor()
          builds a blank pre-processor.
PreProcessor(List taskList)
          builds a pre-processor with the given task list, which is a list of TaskFactory.
 
Method Summary
 void addTask(TaskFactory taskFactory)
          Adds the given task to the list.
static void main(String[] args)
          Simple test: processes the file given as arguments using makePagePreProc() the and prints it to screen
static PreProcessor makeLatexPreProc()
           
static PreProcessor makeNewPagePreProc(MBaseRef mbaseRef)
          Makes a new page pre-processor every time.
static PreProcessor makePagePreProc()
          Returns a possibly cached pre-processor
 void run(org.jdom.Element elt, Map properties)
          Walks this element and all the kids for each task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVS_ID

public static final String CVS_ID
See Also:
Constant Field Values

thisLogCat

protected static Logger thisLogCat

DEBUG

public static final boolean DEBUG

taskList

public final List taskList
The taskList that will be enumerated when running. Modifying this list while a preprocessor is running can raise concurrency problems.

Constructor Detail

PreProcessor

public PreProcessor()
builds a blank pre-processor.


PreProcessor

public PreProcessor(List taskList)
builds a pre-processor with the given task list, which is a list of TaskFactory.

Method Detail

makePagePreProc

public static PreProcessor makePagePreProc()
Returns a possibly cached pre-processor


makeNewPagePreProc

public static PreProcessor makeNewPagePreProc(MBaseRef mbaseRef)
Makes a new page pre-processor every time.


makeLatexPreProc

public static PreProcessor makeLatexPreProc()

addTask

public void addTask(TaskFactory taskFactory)
Adds the given task to the list. Note that the order in which the task is performed will be given by the list.


run

public void run(org.jdom.Element elt,
                Map properties)
Walks this element and all the kids for each task.

TODO: find an optimization to make only one walk.


main

public static void main(String[] args)
                 throws Exception
Simple test: processes the file given as arguments using makePagePreProc() the and prints it to screen

Throws:
Exception