org.apache.cocoon.transformation
Class PatternTransformer

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.xml.AbstractXMLProducer
          extended by org.apache.cocoon.xml.AbstractXMLPipe
              extended by org.apache.cocoon.transformation.AbstractTransformer
                  extended by org.apache.cocoon.transformation.PatternTransformer
All Implemented Interfaces:
Poolable, Recyclable, Disposable, Component, LogEnabled, Parameterizable, Serviceable, CacheableProcessingComponent, SitemapModelComponent, Transformer, XMLPipe, XMLProducer, XMLConsumer, ContentHandler, LexicalHandler

public class PatternTransformer
extends AbstractTransformer
implements LogEnabled, Serviceable, Recyclable, Disposable, Parameterizable, CacheableProcessingComponent

This transfomer transforms text pattern of a XML file into lexemes by using a lexicon file.

Input:

 <section>
  Text 123 bla
 </section>
 

can be transformed into the following output:

 <section>
  Text
  <lexeme symbol="number" text="123"/>
  bla
 </section>
 

Version:
$Id: PatternTransformer.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Stephan Michels

Nested Class Summary
static class PatternTransformer.LexicalAutomatonEntry
          This class represent a entry in a store to cache the lexical automaton.
 
Field Summary
static String NS
          Namespace for the SAX events.
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.transformation.Transformer
ROLE
 
Constructor Summary
PatternTransformer()
           
 
Method Summary
 void characters(char[] c, int start, int len)
          Receive notification of character data.
 void comment(char[] ch, int start, int len)
          Report an XML comment anywhere in the document.
 void dispose()
          The dispose operation is called at the end of a components lifecycle.
 void enableLogging(Logger logger)
          Provide component with a logger.
 void endElement(String uri, String loc, String raw)
          Receive notification of the end of an element.
 Serializable getKey()
          Generate the unique key.
 SourceValidity getValidity()
          Generate the validity object.
 void ignorableWhitespace(char[] c, int start, int len)
          Receive notification of ignorable whitespace in element content.
 void parameterize(Parameters parameters)
          Provide component with parameters.
 void processingInstruction(String target, String data)
          Receive notification of a processing instruction.
 void recycle()
          Recycle this component.
 void service(ServiceManager manager)
          Pass the ServiceManager to the Serviceable.
 void setup(SourceResolver resolver, Map objectmodel, String src, Parameters parameters)
          Set the SourceResolver, objectModel Map, the source and sitemap Parameters used to process the request.
 void startElement(String uri, String loc, String raw, Attributes a)
          Receive notification of the beginning of an element.
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLPipe
endCDATA, endDocument, endDTD, endEntity, endPrefixMapping, setDocumentLocator, skippedEntity, startCDATA, startDocument, startDTD, startEntity, startPrefixMapping
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
getLogger, setupLogger, setupLogger, setupLogger
 
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
endDocument, endPrefixMapping, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping
 
Methods inherited from interface org.xml.sax.ext.LexicalHandler
endCDATA, endDTD, endEntity, startCDATA, startDTD, startEntity
 
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
 

Field Detail

NS

public static final String NS
Namespace for the SAX events.

See Also:
Constant Field Values
Constructor Detail

PatternTransformer

public PatternTransformer()
Method Detail

enableLogging

public void enableLogging(Logger logger)
Provide component with a logger.

Specified by:
enableLogging in interface LogEnabled
Overrides:
enableLogging in class AbstractLogEnabled
Parameters:
logger - the logger

service

public void service(ServiceManager manager)
Pass the ServiceManager to the Serviceable. The Serviceable implementation should use the specified ServiceManager to acquire the services it needs for execution.

Specified by:
service in interface Serviceable
Parameters:
manager - The ServiceManager which this Serviceable uses.

parameterize

public void parameterize(Parameters parameters)
                  throws ParameterException
Provide component with parameters.

Specified by:
parameterize in interface Parameterizable
Parameters:
parameters - the parameters
Throws:
ParameterException - if parameters are invalid

setup

public void setup(SourceResolver resolver,
                  Map objectmodel,
                  String src,
                  Parameters parameters)
           throws ProcessingException,
                  SAXException,
                  IOException
Set the SourceResolver, objectModel Map, the source and sitemap Parameters used to process the request.

Specified by:
setup in interface SitemapModelComponent
Parameters:
resolver - Source resolver
objectmodel - Object model
src - Source
parameters - Parameters
Throws:
IOException
ProcessingException
SAXException

getKey

public Serializable getKey()
Generate the unique key. This key must be unique inside the space of this component.

Specified by:
getKey in interface CacheableProcessingComponent
Returns:
The generated key hashes the src

getValidity

public SourceValidity getValidity()
Generate the validity object.

Specified by:
getValidity in interface CacheableProcessingComponent
Returns:
The generated validity object or null if the component is currently not cacheable.

recycle

public void recycle()
Recycle this component. All instance variables are set to null.

Specified by:
recycle in interface Recyclable
Overrides:
recycle in class AbstractXMLProducer

dispose

public void dispose()
The dispose operation is called at the end of a components lifecycle.

Specified by:
dispose in interface Disposable

startElement

public void startElement(String uri,
                         String loc,
                         String raw,
                         Attributes a)
                  throws SAXException
Receive notification of the beginning of an element.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class AbstractXMLPipe
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
loc - The local name (without prefix), or the empty string if Namespace processing is not being performed.
raw - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
a - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException

endElement

public void endElement(String uri,
                       String loc,
                       String raw)
                throws SAXException
Receive notification of the end of an element.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class AbstractXMLPipe
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
loc - The local name (without prefix), or the empty string if Namespace processing is not being performed.
raw - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
Throws:
SAXException

characters

public void characters(char[] c,
                       int start,
                       int len)
                throws SAXException
Receive notification of character data.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class AbstractXMLPipe
Parameters:
c - The characters from the XML document.
start - The start position in the array.
len - The number of characters to read from the array.
Throws:
SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] c,
                                int start,
                                int len)
                         throws SAXException
Receive notification of ignorable whitespace in element content.

Specified by:
ignorableWhitespace in interface ContentHandler
Overrides:
ignorableWhitespace in class AbstractXMLPipe
Parameters:
c - The characters from the XML document.
start - The start position in the array.
len - The number of characters to read from the array.
Throws:
SAXException

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Receive notification of a processing instruction.

Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in class AbstractXMLPipe
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none was supplied.
Throws:
SAXException

comment

public void comment(char[] ch,
                    int start,
                    int len)
             throws SAXException
Report an XML comment anywhere in the document.

Specified by:
comment in interface LexicalHandler
Overrides:
comment in class AbstractXMLPipe
Parameters:
ch - An array holding the characters in the comment.
start - The starting position in the array.
len - The number of characters to use from the array.
Throws:
SAXException


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.