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

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.components.language.markup.AbstractMarkupLanguage
All Implemented Interfaces:
Poolable, Recyclable, Disposable, Component, Configurable, LogEnabled, Serviceable, MarkupLanguage
Direct Known Subclasses:
CocoonMarkupLanguage

public abstract class AbstractMarkupLanguage
extends AbstractLogEnabled
implements MarkupLanguage, Serviceable, Configurable, Recyclable, 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.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Ricardo Rocha, Davanum Srinivas, Ovidiu Predescu

Nested Class Summary
protected static 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
static String ATTR_INTERPOLATION
          Name "attr-interpolation" of boolean attribute to enable expression interpolation in attribute values.
protected  Map languages
          The supported language table
protected  Store logicsheetCache
          The code-generation logicsheet cache
protected  ServiceManager manager
          The service manager
protected  String name
          This language name
static String TEXT_INTERPOLATION
          Name "text-interpolation" of boolean attribute to enable expression interpolation inside text nodes.
 
Fields inherited from interface org.apache.cocoon.components.language.markup.MarkupLanguage
ROLE
 
Constructor Summary
AbstractMarkupLanguage()
          The default constructor.
 
Method Summary
protected abstract  void addDependency(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, String logicsheetLocation)
          Add a logicsheet to the code generator.
 void configure(Configuration conf)
          Process additional configuration.
 void dispose()
          Release all resources.
 String generateCode(Source source, String filename, ProgrammingLanguage programmingLanguage)
          Generate source code from the input document for the target ProgrammingLanguage.
 String getEncoding()
          Return the source document's encoding.
protected  LogicsheetFilter getLogicsheetFilter()
          Return the optional filter to prepocess logicsheets.
 String getName()
          Return the markup language name.
 String getPrefix()
          Returns the namespace prefix for this language.
protected  AbstractXMLPipe getPreprocessFilter(String filename, AbstractXMLPipe filter, ProgrammingLanguage language)
          Prepare the input source for logicsheet processing and code generation with a preprocess filter.
protected  AbstractMarkupLanguage.TransformerChainBuilderFilter getTransformerChainBuilder(LogicsheetCodeGenerator logicsheetMarkupGenerator)
          Returns a filter that chains on the fly the requested transformers for source code generation.
 String getURI()
          Returns the namespace URI for this language.
 boolean hasAttrInterpolation()
          Returns true if expansion of attribute expressions is enabled for this language.
 boolean hasTextInterpolation()
          Returns true if expansion of expressions inside text nodes is enabled for this language.
 void recycle()
          Recycle this component: clear logic sheet list and dependencies.
 void service(ServiceManager manager)
          Set the global service manager.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTR_INTERPOLATION

public static final String ATTR_INTERPOLATION
Name "attr-interpolation" of boolean attribute to enable expression interpolation in attribute values.

See Also:
Constant Field Values

TEXT_INTERPOLATION

public static final String TEXT_INTERPOLATION
Name "text-interpolation" of boolean attribute to enable expression interpolation inside text nodes.

See Also:
Constant Field Values

name

protected String name
This language name


languages

protected Map languages
The supported language table


logicsheetCache

protected Store logicsheetCache
The code-generation logicsheet cache


manager

protected ServiceManager manager
The service manager

Constructor Detail

AbstractMarkupLanguage

public AbstractMarkupLanguage()
The default constructor.

Method Detail

configure

public void configure(Configuration conf)
               throws ConfigurationException
Process additional configuration. Load supported programming language definitions

Specified by:
configure in interface Configurable
Parameters:
conf - The language configuration
Throws:
ConfigurationException - If an error occurs loading logichseets

service

public void service(ServiceManager manager)
             throws ServiceException
Set the global service manager.

Specified by:
service in interface Serviceable
Parameters:
manager - The sitemap-specified service manager
Throws:
ServiceException

recycle

public void recycle()
Recycle this component: clear logic sheet list and dependencies.

Specified by:
recycle in interface Recyclable

dispose

public void dispose()
Release all resources.

Specified by:
dispose in interface Disposable

getName

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

Returns:
The language name.

getURI

public String getURI()
Returns the namespace URI for this language.


getPrefix

public String getPrefix()
Returns the namespace prefix for this language.


hasAttrInterpolation

public boolean hasAttrInterpolation()
Returns true if expansion of attribute expressions is enabled for this language.


hasTextInterpolation

public boolean hasTextInterpolation()
Returns true if expansion of expressions inside text nodes is enabled for this language.


getEncoding

public 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)
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
Returns:
XMLFilter the filter that build on the fly the transformer chain

getPreprocessFilter

protected AbstractXMLPipe getPreprocessFilter(String filename,
                                              AbstractXMLPipe filter,
                                              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(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, AbstractServerPage

generateCode

public String generateCode(Source source,
                           String filename,
                           ProgrammingLanguage programmingLanguage)
                    throws 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:
source - The input source
filename - The input document's original filename
programmingLanguage - The target programming language
Returns:
The generated source code
Throws:
Exception - If an error occurs during code generation

addLogicsheetsToGenerator

protected void addLogicsheetsToGenerator(LogicsheetCodeGenerator codeGenerator)
                                  throws MalformedURLException,
                                         IOException,
                                         SAXException,
                                         ProcessingException
Add logicsheet list to the code generator.

Parameters:
codeGenerator - The code generator
Throws:
MalformedURLException
IOException
SAXException
ProcessingException

addLogicsheetToList

protected void addLogicsheetToList(AbstractMarkupLanguage.LanguageDescriptor language,
                                   String logicsheetLocation)
                            throws IOException,
                                   SAXException,
                                   ProcessingException
Add a logicsheet to the code generator.

Parameters:
language - Target programming language of the logicsheet
logicsheetLocation - Location of the logicsheet to be added
Throws:
MalformedURLException - If location is invalid
IOException - IO Error
SAXException - Logicsheet parse error
ProcessingException

getLogicsheetFilter

protected LogicsheetFilter getLogicsheetFilter()
Return the optional filter to prepocess logicsheets.



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