Package org.apache.fop.hyphenation
Class PatternParser
java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.apache.fop.hyphenation.PatternParser
- All Implemented Interfaces:
PatternConsumer
,ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
A SAX document handler to read and parse hyphenation patterns from a XML file.
This work was authored by Carlos Villegas (cav@uniscope.co.jp).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PatternConsumer
private int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
private String
private ArrayList
private boolean
private char
private XMLReader
private PrintStream
private StringBuffer
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a pattern parser.PatternParser
(PatternConsumer consumer) Construct a pattern parser. -
Method Summary
Modifier and TypeMethodDescriptionvoid
For testing purposes only.void
addException
(String w, ArrayList e) For testing purposes only.void
addPattern
(String p, String v) For testing purposes only.void
characters
(char[] ch, int start, int length) void
Close test out file.(package private) static XMLReader
Creates a SAX parser using JAXPvoid
endElement
(String uri, String local, String raw) void
void
private String
protected void
private static String
private String
Returns a string of the location.private static String
getPattern
(String word) static void
Main entry point when used as an application.private ArrayList
void
Parses a hyphenation pattern file.void
Parses a hyphenation pattern file.void
parse
(InputSource source) Parses a hyphenation pattern file.private String
readToken
(StringBuffer chars) void
setTestOut
(PrintStream testOut) Set test out stream.void
startElement
(String uri, String local, String raw, Attributes attrs) void
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
parser
-
currElement
private int currElement -
consumer
-
token
-
exception
-
hyphenChar
private char hyphenChar -
errMsg
-
hasClasses
private boolean hasClasses -
ELEM_CLASSES
static final int ELEM_CLASSES- See Also:
-
ELEM_EXCEPTIONS
static final int ELEM_EXCEPTIONS- See Also:
-
ELEM_PATTERNS
static final int ELEM_PATTERNS- See Also:
-
ELEM_HYPHEN
static final int ELEM_HYPHEN- See Also:
-
testOut
-
-
Constructor Details
-
PatternParser
Construct a pattern parser.- Throws:
HyphenationException
- if a hyphenation exception is raised
-
PatternParser
Construct a pattern parser.- Parameters:
consumer
- a pattern consumer- Throws:
HyphenationException
- if a hyphenation exception is raised
-
-
Method Details
-
parse
Parses a hyphenation pattern file.- Parameters:
filename
- the filename- Throws:
HyphenationException
- In case of an exception while parsing
-
parse
Parses a hyphenation pattern file.- Parameters:
file
- the pattern file- Throws:
HyphenationException
- In case of an exception while parsing
-
parse
Parses a hyphenation pattern file.- Parameters:
source
- the InputSource for the file- Throws:
HyphenationException
- In case of an exception while parsing
-
createParser
Creates a SAX parser using JAXP- Returns:
- the created SAX parser
-
readToken
-
getPattern
-
normalizeException
-
getExceptionWord
-
getInterletterValues
-
getExternalClasses
- Throws:
SAXException
- if not caught
-
startElement
public void startElement(String uri, String local, String raw, Attributes attrs) throws SAXException - Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
-
endElement
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
-
characters
public void characters(char[] ch, int start, int length) - Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
-
warning
- Specified by:
warning
in interfaceErrorHandler
- Overrides:
warning
in classDefaultHandler
-
error
- Specified by:
error
in interfaceErrorHandler
- Overrides:
error
in classDefaultHandler
-
fatalError
- Specified by:
fatalError
in interfaceErrorHandler
- Overrides:
fatalError
in classDefaultHandler
- Throws:
SAXException
-
getLocationString
Returns a string of the location. -
addClass
For testing purposes only. Add a character class. A character class defines characters that are considered equivalent for the purpose of hyphenation (e.g. "aA"). It usually means to ignore case.- Specified by:
addClass
in interfacePatternConsumer
- Parameters:
c
- character group
-
addException
For testing purposes only. Add a hyphenation exception. An exception replaces the result obtained by the algorithm for cases for which this fails or the user wants to provide his own hyphenation. A hyphenatedword is a vector of alternating String's andHyphen
instances- Specified by:
addException
in interfacePatternConsumer
- Parameters:
w
- word to add as an exceptione
- pre-hyphenated word
-
addPattern
For testing purposes only. Add hyphenation patterns.- Specified by:
addPattern
in interfacePatternConsumer
- Parameters:
p
- the patternv
- interletter values expressed as a string of digit characters.
-
setTestOut
Set test out stream.- Parameters:
testOut
- the testOut to set
-
closeTestOut
public void closeTestOut()Close test out file. -
main
Main entry point when used as an application.- Parameters:
args
- array of command line arguments- Throws:
Exception
- in case of uncaught exception
-