de.infinityloop.upcast.treeprocess
Class SectionProcessorBase

java.lang.Object
  extended by de.infinityloop.upcast.treeprocess.SectionProcessorBase
All Implemented Interfaces:
de.infinityloop.upcast.treeprocess.SectionProcessor

public class SectionProcessorBase
extends java.lang.Object
implements de.infinityloop.upcast.treeprocess.SectionProcessor

Base class for a custom section processor.

Subclass and implement checkParagraph(org.w3c.dom.Element, de.infinityloop.upcast.UpcastStyle, de.infinityloop.upcast.UpcastStyle) as required.


Field Summary
protected static int HEADING_PAR
           
 LoggerProxy logger
           
protected static int NO_SECTION_BREAK
           
protected static int SECTION_1_START
           
protected static int SECTION_2_START
           
protected static int SECTION_3_START
           
protected static int SECTION_4_START
           
protected static int SECTION_5_START
           
protected static int SECTION_6_START
           
protected static int SECTION_7_START
           
protected static int SECTION_8_START
           
protected static int SECTION_9_START
           
 
Fields inherited from interface de.infinityloop.upcast.treeprocess.SectionProcessor
kSectionLevelAttrName
 
Constructor Summary
SectionProcessorBase()
           
 
Method Summary
protected  int checkParagraph(org.w3c.dom.Element par, UpcastStyle baseStyle, UpcastStyle overrideStyle)
          This is the only method you need to implement.
protected  UpcastStyle getBaseStyle(org.w3c.dom.Element elem)
          retrieves the base style of an element of the internal document tree.
protected  UpcastStyle getOverrideStyle(org.w3c.dom.Element elem)
          retrieves the override style of an element of the internal document tree.
 void initialize(de.infinityloop.upcast.Converter conv, de.infinityloop.upcast.importfilters.ImportFilter filter)
          Called at initialization time.
protected  UpcastStyle mergeStyles(UpcastStyle baseStyle, UpcastStyle overrideStyle)
          Merges the base style and the override style into one representing the actual valid combination of properties.
 void processDocument(org.w3c.dom.Document doc)
          Entry point for processing the document.
protected  void setParagraphStyleName(org.w3c.dom.Element par, java.lang.String name)
          sets the name of the element's base style to the one specified.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_SECTION_BREAK

protected static final int NO_SECTION_BREAK
See Also:
Constant Field Values

SECTION_1_START

protected static final int SECTION_1_START
See Also:
Constant Field Values

SECTION_2_START

protected static final int SECTION_2_START
See Also:
Constant Field Values

SECTION_3_START

protected static final int SECTION_3_START
See Also:
Constant Field Values

SECTION_4_START

protected static final int SECTION_4_START
See Also:
Constant Field Values

SECTION_5_START

protected static final int SECTION_5_START
See Also:
Constant Field Values

SECTION_6_START

protected static final int SECTION_6_START
See Also:
Constant Field Values

SECTION_7_START

protected static final int SECTION_7_START
See Also:
Constant Field Values

SECTION_8_START

protected static final int SECTION_8_START
See Also:
Constant Field Values

SECTION_9_START

protected static final int SECTION_9_START
See Also:
Constant Field Values

HEADING_PAR

protected static final int HEADING_PAR
See Also:
Constant Field Values

logger

public LoggerProxy logger
Constructor Detail

SectionProcessorBase

public SectionProcessorBase()
Method Detail

initialize

public final void initialize(de.infinityloop.upcast.Converter conv,
                             de.infinityloop.upcast.importfilters.ImportFilter filter)
Called at initialization time.

When you override this, make sure to call the implementation of the super class.

Specified by:
initialize in interface de.infinityloop.upcast.treeprocess.SectionProcessor

processDocument

public final void processDocument(org.w3c.dom.Document doc)
Entry point for processing the document.

When you override this, make sure to call the implementation of the super class as last action to start processing.

Specified by:
processDocument in interface de.infinityloop.upcast.treeprocess.SectionProcessor

getBaseStyle

protected UpcastStyle getBaseStyle(org.w3c.dom.Element elem)
retrieves the base style of an element of the internal document tree.

This will be needed in checkParagraph() if you need to look 'down' the tree into the paragraph's children to determine wether it is a section heading or not.

Parameters:
elem - the element from which to retrieve the valid base style
Returns:
the style object, or null if it could not be retrieved

getOverrideStyle

protected UpcastStyle getOverrideStyle(org.w3c.dom.Element elem)
retrieves the override style of an element of the internal document tree.

This will be needed in checkParagraph() if you need to look 'down' the tree into the paragraph's children to determine wether it is a section heading or not.

Parameters:
elem - the element from which to retrieve the valid override style
Returns:
the style object, or null if it could not be retrieved

setParagraphStyleName

protected void setParagraphStyleName(org.w3c.dom.Element par,
                                     java.lang.String name)
sets the name of the element's base style to the one specified.

Internally, this makes a copy of the current style of the element and adds a new style to the styletable with the new name.

If a style by that name already exists in the style table, the element is linked to the existing style without changing it. This may alter the par's visual appearance if the existing style has different properties.

Parameters:
par - the element to set the new named style on. This must be a par element.
name - the new style name

mergeStyles

protected UpcastStyle mergeStyles(UpcastStyle baseStyle,
                                  UpcastStyle overrideStyle)
Merges the base style and the override style into one representing the actual valid combination of properties.

Parameters:
baseStyle - the base style
overrideStyle - the override style which is merged onto base style, replacing any existing properties that might already exist there with the same name
Returns:
the merged style

checkParagraph

protected int checkParagraph(org.w3c.dom.Element par,
                             UpcastStyle baseStyle,
                             UpcastStyle overrideStyle)
This is the only method you need to implement. It gets called for each par element in the document, along with the local base style (taken from the stylesheet) and any locally overridden (= added) properties for this paragraph.

If you want this paragraph to be placed into a new section of level X, return one of the constants SECTION_X_START, with X being the nesting level of the sections where you want this paragraph to be the first one in.

If you also want to make this paragraph a heading element in the output, add the constant HEADING_PAR to the result.

The paragraph is in the internal DOM tree, so if you need to check for properties on its children, you may traverse them using standard DOM level 1 methods and retrieve the children's style info using the getBaseStyle() and getOverrideStyle() methods.

Parameters:
par - A DOM element for the paragraph to process
baseStyle - the base style as originally assigned via the named stylesheet style
overrideStyle - all properties that have been manually and locally applied on top of the base style
Returns:
return constants as described above or NO_SECTION_BREAK (the default), if this paragraph does not indicate a change in section nesting.

By default, this implementation returns NO_SECTION_BREAK.