org.apache.cocoon.components.language.markup
Class AbstractMarkupLanguage

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLoggable
        |
        +--org.apache.cocoon.components.language.markup.AbstractMarkupLanguage
All Implemented Interfaces:
org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.logger.Loggable, MarkupLanguage, org.apache.avalon.framework.parameters.Parameterizable, org.apache.avalon.excalibur.pool.Poolable, org.apache.avalon.excalibur.pool.Recyclable
Direct Known Subclasses:
CocoonMarkupLanguage

public abstract class AbstractMarkupLanguage
extends org.apache.avalon.framework.logger.AbstractLoggable
implements MarkupLanguage, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.parameters.Parameterizable, org.apache.avalon.excalibur.pool.Recyclable, org.apache.avalon.framework.activity.Disposable

Base implementation of MarkupLanguage. This class uses logicsheets as the only means of code generation. Code generation should be decoupled from this context!!!

Version:
CVS $Id: AbstractMarkupLanguage.java,v 1.15.2.1 2002/07/15 14:42:48 cziegeler Exp $
Author:
Ricardo Rocha, Davanum Srinivas, Ovidiu Predescu

Inner Class Summary
protected  class AbstractMarkupLanguage.LanguageDescriptor
          This class holds transient information about a target programming language.
 class AbstractMarkupLanguage.TransformerChainBuilderFilter
          An XMLFilter that build the chain of transformers on the fly.
 
Field Summary
protected  HashMap languages
          The supported language table
protected  Store logicsheetCache
          The code-generation logicsheet cache
protected  org.apache.avalon.framework.component.ComponentManager manager
          The component manager
protected  java.lang.String name
          This language name
protected  java.lang.String prefix
          The markup language's namespace prefix
protected  java.lang.String uri
          The markup language's namespace uri
 
Fields inherited from interface org.apache.cocoon.components.language.markup.MarkupLanguage
ROLE
 
Constructor Summary
AbstractMarkupLanguage()
          The default constructor.
 
Method Summary
protected abstract  void addDependency(java.lang.String location)
          Add a dependency on an external file to the document for inclusion in generated code.
protected  void addLogicsheetsToGenerator(LogicsheetCodeGenerator codeGenerator)
          Add logicsheet list to the code generator.
protected  void addLogicsheetToList(AbstractMarkupLanguage.LanguageDescriptor language, java.lang.String logicsheetLocation, SourceResolver resolver)
          Add a logicsheet to the code generator.
 void compose(org.apache.avalon.framework.component.ComponentManager manager)
          Set the global component manager.
 void configure(org.apache.avalon.framework.configuration.Configuration conf)
          Process additional configuration.
 void dispose()
          Release all resources.
 java.lang.String generateCode(org.xml.sax.InputSource input, java.lang.String filename, ProgrammingLanguage programmingLanguage, SourceResolver resolver)
          Generate source code from the input document for the target ProgrammingLanguage.
 java.lang.String getEncoding()
          Return the source document's encoding.
 java.lang.String getName()
          Return the markup language name.
protected  org.xml.sax.XMLFilter getPreprocessFilter(java.lang.String filename, ProgrammingLanguage language)
          Prepare the input source for logicsheet processing and code generation with a preprocess filter.
protected  AbstractMarkupLanguage.TransformerChainBuilderFilter getTransformerChainBuilder(LogicsheetCodeGenerator logicsheetMarkupGenerator, SourceResolver resolver)
          Returns a filter that chains on the fly the requested transformers for source code generation.
 void parameterize(org.apache.avalon.framework.parameters.Parameters params)
          Initialize the (required) markup language namespace definition.
 void recycle()
          Recycle this component: clear logic sheet list and dependencies.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable
getLogger, setLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
This language name

languages

protected HashMap languages
The supported language table

logicsheetCache

protected Store logicsheetCache
The code-generation logicsheet cache

uri

protected java.lang.String uri
The markup language's namespace uri

prefix

protected java.lang.String prefix
The markup language's namespace prefix

manager

protected org.apache.avalon.framework.component.ComponentManager manager
The component manager
Constructor Detail

AbstractMarkupLanguage

public AbstractMarkupLanguage()
The default constructor.
Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration conf)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Process additional configuration. Load supported programming language definitions
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Parameters:
conf - The language configuration
Throws:
org.apache.avalon.framework.configuration.ConfigurationException - If an error occurs loading logichseets

compose

public void compose(org.apache.avalon.framework.component.ComponentManager manager)
             throws org.apache.avalon.framework.component.ComponentException
Set the global component manager.
Specified by:
compose in interface org.apache.avalon.framework.component.Composable
Parameters:
manager - The sitemap-specified component manager

recycle

public void recycle()
Recycle this component: clear logic sheet list and dependencies.
Specified by:
recycle in interface org.apache.avalon.excalibur.pool.Recyclable

dispose

public void dispose()
Release all resources.
Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable

parameterize

public void parameterize(org.apache.avalon.framework.parameters.Parameters params)
                  throws org.apache.avalon.framework.parameters.ParameterException
Initialize the (required) markup language namespace definition.
Specified by:
parameterize in interface org.apache.avalon.framework.parameters.Parameterizable
Parameters:
params - The supplied parameters

getName

public java.lang.String getName()
Return the markup language name. Two markup languages are well-know at the moment: sitemap and xsp.
Returns:
The language name.

getEncoding

public java.lang.String getEncoding()
Return the source document's encoding. This can be null for the platform's default encoding. The default implementation returns null, but derived classes may override it if encoding applies to their concrete languages. FIXME: There should be a way to get the XML document's encoding as seen by the parser; unfortunately, this information is not returned by current DOM or SAX parsers...
Specified by:
getEncoding in interface MarkupLanguage
Returns:
The document-specified encoding

getTransformerChainBuilder

protected AbstractMarkupLanguage.TransformerChainBuilderFilter getTransformerChainBuilder(LogicsheetCodeGenerator logicsheetMarkupGenerator,
                                                                                          SourceResolver resolver)
Returns a filter that chains on the fly the requested transformers for source code generation. This method scans the input SAX events for built-in logicsheet declared as namespace attribute on the root element. Derived class should overide this method and the public inner class in order to add more specif action and to build a more specific transformer chain.
Parameters:
logicsheetMarkupGenerator - the logicsheet markup generator
resolver - the entity resolver
Returns:
XMLFilter the filter that build on the fly the transformer chain

getPreprocessFilter

protected org.xml.sax.XMLFilter getPreprocessFilter(java.lang.String filename,
                                                    ProgrammingLanguage language)
Prepare the input source for logicsheet processing and code generation with a preprocess filter. The return XMLFilter object is the first filter on the transformer chain. The default implementation does nothing by returning a identity filter, but derived classes should (at least) use the passed programming language to quote Strings
Parameters:
filename - The source filename
language - The target programming language
Returns:
The preprocess filter

addDependency

protected abstract void addDependency(java.lang.String location)
Add a dependency on an external file to the document for inclusion in generated code. This is used to populate a list of File's tested for change on each invocation; this information is used to assert whether regeneration is necessary.
Parameters:
location - The file path of the dependent file
See Also:
AbstractMarkupLanguage, ServerPagesGenerator and AbstractServerPage

generateCode

public java.lang.String generateCode(org.xml.sax.InputSource input,
                                     java.lang.String filename,
                                     ProgrammingLanguage programmingLanguage,
                                     SourceResolver resolver)
                              throws java.lang.Exception
Generate source code from the input document for the target ProgrammingLanguage. After preprocessing the input document, this method applies logicsheets in the following order:
Specified by:
generateCode in interface MarkupLanguage
Parameters:
input - The input source
filename - The input document's original filename
programmingLanguage - The target programming language
Returns:
The generated source code
Throws:
java.lang.Exception - If an error occurs during code generation

addLogicsheetsToGenerator

protected void addLogicsheetsToGenerator(LogicsheetCodeGenerator codeGenerator)
                                  throws java.net.MalformedURLException,
                                         java.io.IOException,
                                         org.xml.sax.SAXException,
                                         ProcessingException
Add logicsheet list to the code generator.
Parameters:
codeGenerator - The code generator

addLogicsheetToList

protected void addLogicsheetToList(AbstractMarkupLanguage.LanguageDescriptor language,
                                   java.lang.String logicsheetLocation,
                                   SourceResolver resolver)
                            throws java.io.IOException,
                                   org.xml.sax.SAXException,
                                   ProcessingException
Add a logicsheet to the code generator.
Parameters:
logicsheetLocation - Location of the logicsheet to be added
document - The input document
Throws:
java.net.MalformedURLException - If location is invalid
java.io.IOException - IO Error
org.xml.sax.SAXException - Logicsheet parse error


Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.