PatternParser (Apache FOP Core 2.11 API)
Date: 2025-04-24

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

      public class PatternParser
      extends DefaultHandler
      implements PatternConsumer

  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).

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PatternParser()` Construct a pattern parser.
    `PatternParser(PatternConsumer consumer)` Construct a pattern parser.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addClass(String c)` 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` | `closeTestOut()` Close test out file.
    `void` | `endElement(String uri, String local, String raw)`
    `void` | `error(SAXParseException ex)`
    `void` | `fatalError(SAXParseException ex)`
    `protected void` | `getExternalClasses()`
    `static void` | `main(String[] args)` Main entry point when used as an application.
    `void` | `parse(File file)` Parses a hyphenation pattern file.
    `void` | `parse(InputSource source)` Parses a hyphenation pattern file.
    `void` | `parse(String filename)` Parses a hyphenation pattern file.
    `void` | `setTestOut(PrintStream testOut)` Set test out stream.
    `void` | `startElement(String uri, String local, String raw, Attributes attrs)`
    `void` | `warning(SAXParseException ex)`

    - ### 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`

- - ### Constructor Detail

    - #### PatternParser

          public PatternParser()
                        throws HyphenationException

      Construct a pattern parser.
      Throws:
        `HyphenationException` - if a hyphenation exception is raised

    - #### PatternParser

          public PatternParser(PatternConsumer consumer)
                        throws HyphenationException

      Construct a pattern parser.
      Parameters:
        `consumer` - a pattern consumer
      Throws:
        `HyphenationException` - if a hyphenation exception is raised

  - ### Method Detail

    - #### parse

          public void parse(String filename)
                     throws HyphenationException

      Parses a hyphenation pattern file.
      Parameters:
        `filename` - the filename
      Throws:
        `HyphenationException` - In case of an exception while parsing

    - #### parse

          public void parse(File file)
                     throws HyphenationException

      Parses a hyphenation pattern file.
      Parameters:
        `file` - the pattern file
      Throws:
        `HyphenationException` - In case of an exception while parsing

    - #### parse

          public void parse(InputSource source)
                     throws HyphenationException

      Parses a hyphenation pattern file.
      Parameters:
        `source` - the InputSource for the file
      Throws:
        `HyphenationException` - In case of an exception while parsing

    - #### getExternalClasses

          protected void getExternalClasses()
                                     throws SAXException

      Throws:
        `SAXException` - if not caught

    - #### startElement

          public void startElement(String uri,
                                   String local,
                                   String raw,
                                   Attributes attrs)
                            throws SAXException

      Specified by:
        `startElement` in interface `ContentHandler`
      Overrides:
        `startElement` in class `DefaultHandler`
      Throws:
        `SAXException`

    - #### endElement

          public void endElement(String uri,
                                 String local,
                                 String raw)

      Specified by:
        `endElement` in interface `ContentHandler`
      Overrides:
        `endElement` in class `DefaultHandler`

    - #### characters

          public void characters(char[] ch,
                                 int start,
                                 int length)

      Specified by:
        `characters` in interface `ContentHandler`
      Overrides:
        `characters` in class `DefaultHandler`

    - #### warning

          public void warning(SAXParseException ex)

      Specified by:
        `warning` in interface `ErrorHandler`
      Overrides:
        `warning` in class `DefaultHandler`

    - #### error

          public void error(SAXParseException ex)

      Specified by:
        `error` in interface `ErrorHandler`
      Overrides:
        `error` in class `DefaultHandler`

    - #### fatalError

          public void fatalError(SAXParseException ex)
                          throws SAXException

      Specified by:
        `fatalError` in interface `ErrorHandler`
      Overrides:
        `fatalError` in class `DefaultHandler`
      Throws:
        `SAXException`

    - #### addClass

          public void addClass(String c)

      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 interface `PatternConsumer`
      Parameters:
        `c` - character group

    - #### addException

          public void addException(String w,
                                   ArrayList e)

      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 and `Hyphen` instances
      Specified by:
        `addException` in interface `PatternConsumer`
      Parameters:
        `w` - word to add as an exception
        `e` - pre-hyphenated word

    - #### addPattern

          public void addPattern(String p,
                                 String v)

      For testing purposes only. Add hyphenation patterns.
      Specified by:
        `addPattern` in interface `PatternConsumer`
      Parameters:
        `p` - the pattern
        `v` - interletter values expressed as a string of digit characters.

    - #### setTestOut

          public void setTestOut(PrintStream testOut)

      Set test out stream.
      Parameters:
        `testOut` - the testOut to set

    - #### closeTestOut

          public void closeTestOut()

      Close test out file.

    - #### main

          public static void main(String[] args)
                           throws Exception

      Main entry point when used as an application.
      Parameters:
        `args` - array of command line arguments
      Throws:
        `Exception` - in case of uncaught exception

Copyright © 2025 Apache Software Foundation. All rights reserved.