org.foray.fotree
Class Namespace

java.lang.Object
  extended by org.foray.fotree.Namespace
Direct Known Subclasses:
MathNamespace, NamespaceAxsl, NamespaceFO, NamespaceForay, NamespaceSVG, NamespaceXML

public abstract class Namespace
extends Object

Abstract class for handling namespaces. Subclasses should know how to convert SAX element and attribute input into Objects and Properties for their namespace.


Constructor Summary
Namespace()
          Constructor.
 
Method Summary
protected abstract  PropertyList createNewPropertyList(Attributes attlist)
          Return a newly-created appropriate PropertyList for this namespace.
 String formatLocator(Locator locator)
          Turns a current SAX locator into a usable user message.
abstract  String getNamespaceURI()
          Returns the URI for this namespace.
abstract  String getTypicalPrefix()
          Returns the typical prefix for this namespace, minus the ":".
protected  void makeList(PropertyList propertyList, Attributes attributes, FObj parentFO, int[] attributeSort, Locator locator, FOTreeBuilder builder)
          Parses the attributes for an object in a pre-specified order, building the PropertyList from them.
 Property parseAttribute(Attributes attributes, String attributeName, String attributeValue, FObj fobj, Locator locator, FOTreeBuilder builder)
          Parses one attribute.
abstract  Property parseAttributeForNS(Attributes attributes, String attributeName, String attributeValue, FObj fobj, Locator locator)
          Parses one attribute in this namespace.
abstract  void parseAttributes(PropertyList list, Attributes attlist, FObj currentFObj, Locator locator, FOTreeBuilder builder)
          Parse the attributes for an element in this namespace.
 FObj parseElement(String localName, FObj currentFObj, PropertyList list, Locator locator, FOTreeBuilder builder)
          Parse an element in this namespace.
protected abstract  FObj parseElementForNS(String localName, FObj currentFObj, PropertyList list, Locator locator)
          The namespace-specific logic for paring an element.
 void reset()
          Resets the error count for this namespace.
protected  int[] sortAttributes(Attributes attlist)
          Reads through the list of attributes and returns an array that contains the order in which they should be processed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Namespace

public Namespace()
Constructor.

Method Detail

getNamespaceURI

public abstract String getNamespaceURI()
Returns the URI for this namespace.

Returns:
URI for this namespace.

getTypicalPrefix

public abstract String getTypicalPrefix()
Returns the typical prefix for this namespace, minus the ":". For example, the SVG namespace should return "svg".

Returns:
The typical prefix for this namespace.

parseElement

public FObj parseElement(String localName,
                         FObj currentFObj,
                         PropertyList list,
                         Locator locator,
                         FOTreeBuilder builder)
                  throws org.axsl.fo.FoTreeException
Parse an element in this namespace.

Parameters:
localName - The local name of the element.
currentFObj - The current FObj, that is, the parent of the one being parsed.
list - The property list into which properties for the new FObj should be placed.
locator - The SAX locator.
builder - The FO Tree builder.
Returns:
The newly-created FObj instance.
Throws:
org.axsl.fo.FoTreeException - For parsing errors.

parseElementForNS

protected abstract FObj parseElementForNS(String localName,
                                          FObj currentFObj,
                                          PropertyList list,
                                          Locator locator)
                                   throws org.axsl.fo.FoTreeException
The namespace-specific logic for paring an element.

Parameters:
localName - The local name of the element.
currentFObj - The current FObj, that is, the parent of the one being parsed.
list - The property list into which properties for the new FObj should be placed.
locator - The SAX locator.
Returns:
The newly-created FObj instance.
Throws:
org.axsl.fo.FoTreeException - For parsing errors.

formatLocator

public String formatLocator(Locator locator)
Turns a current SAX locator into a usable user message.

Parameters:
locator - The SAX locator containing the location information.
Returns:
A formatted user message.

parseAttributes

public abstract void parseAttributes(PropertyList list,
                                     Attributes attlist,
                                     FObj currentFObj,
                                     Locator locator,
                                     FOTreeBuilder builder)
                              throws org.axsl.fo.FoTreeException
Parse the attributes for an element in this namespace.

Parameters:
list - The property list into which the parsed values should be placed.
attlist - The unparsed SAX attributes.
currentFObj - The FObj instance to whom the attributes belong.
locator - The SAX locator.
builder - The FOTree builder.
Throws:
org.axsl.fo.FoTreeException - For errors during attribute/property parsing.

sortAttributes

protected int[] sortAttributes(Attributes attlist)
Reads through the list of attributes and returns an array that contains the order in which they should be processed. The routine currently sorts the attributes alphabetically. The purpose of this is to ensure that any short forms of compound properties are processed before their completer forms are processed. For example, downstream processing is simplified if we know that property "leader-length" was processed before property "leader-length.minimum".

Parameters:
attlist - The Attributes instance that contains the attributes to be sorted
Returns:
An int array containing the order in which the attributes should be processed. If element 0 contains an 8 and element 1 contains a 3, then element 8 of Attributes should be processed first, and element 3 should be processed second.

parseAttribute

public Property parseAttribute(Attributes attributes,
                               String attributeName,
                               String attributeValue,
                               FObj fobj,
                               Locator locator,
                               FOTreeBuilder builder)
                        throws PropertyException
Parses one attribute.

Parameters:
attributes - The unparsed SAX attributes.
attributeName - The name of the attribute to be parsed.
attributeValue - The value of the attribute to be parsed.
fobj - The FObj to which the properties belong.
locator - The SAX locator.
builder - The FOTree builder.
Returns:
The parsed property.
Throws:
PropertyException - For errors during parsing.

parseAttributeForNS

public abstract Property parseAttributeForNS(Attributes attributes,
                                             String attributeName,
                                             String attributeValue,
                                             FObj fobj,
                                             Locator locator)
                                      throws PropertyException
Parses one attribute in this namespace.

Parameters:
attributes - The unparsed SAX attributes.
attributeName - The name of the attribute to be parsed.
attributeValue - The value of the attribute to be parsed.
fobj - The FObj to which the properties belongs.
locator - The SAX locator.
Returns:
The parsed property.
Throws:
PropertyException - For errors during parsing.

makeList

protected void makeList(PropertyList propertyList,
                        Attributes attributes,
                        FObj parentFO,
                        int[] attributeSort,
                        Locator locator,
                        FOTreeBuilder builder)
                 throws PropertyException
Parses the attributes for an object in a pre-specified order, building the PropertyList from them.

Parameters:
propertyList - The property list into which the parsed values should be placed.
attributes - The unparsed SAX attributes.
parentFO - The parent FO.
attributeSort - The order in which the various attributes should be parsed, so that compound values are handled properly.
locator - The SAX locator.
builder - The FO Tree builder.
Throws:
PropertyException - For errors during parsing.

reset

public void reset()
Resets the error count for this namespace.


createNewPropertyList

protected abstract PropertyList createNewPropertyList(Attributes attlist)
Return a newly-created appropriate PropertyList for this namespace.

Parameters:
attlist - The attributes that will become the properties in the list.
Returns:
The newly-created property list.


Copyright © 2017. All rights reserved.