org.apache.cocoon.components.treeprocessor.sitemap
Class SitemapLanguage

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.components.treeprocessor.sitemap.SitemapLanguage
All Implemented Interfaces:
Contextualizable, Poolable, Recyclable, Serviceable, TreeBuilder

public class SitemapLanguage
extends org.apache.cocoon.util.AbstractLogEnabled
implements TreeBuilder, Contextualizable, Serviceable, Recyclable

The tree builder for the sitemap language.

Version:
$Id: SitemapLanguage.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
protected  Map attributes
           
protected  List enterSitemapEventListeners
          Optional event listeners for the enter sitemap event
static String FIRST_POS_LABEL
          Pseudo-label for views from-position="first" (i.e.
protected  org.apache.cocoon.components.pipeline.impl.PipelineComponentInfo itsComponentInfo
          The sitemap component information grabbed while building itsMaanger
protected  String itsNamespace
          The namespace of configuration for the processor that we are building.
static String LAST_POS_LABEL
          Pseudo-label for views from-position="last" (i.e.
protected  List leaveSitemapEventListeners
          Optional event listeners for the leave sitemap event
protected  ConcreteTreeProcessor processor
          The tree processor that we are building.
 
Fields inherited from interface org.apache.cocoon.components.treeprocessor.TreeBuilder
ROLE
 
Constructor Summary
SitemapLanguage()
           
 
Method Summary
 void addViewForLabel(String label, String view)
          Add a view for a label.
 ProcessingNode build(Configuration tree, String location)
          Build a processing tree from a Configuration.
 void contextualize(Context avalonContext)
           
 ProcessingNodeBuilder createNodeBuilder(Configuration config)
           
protected  ProcessingNode createTree(Configuration tree)
          Create the tree once component manager and node builders have been set up.
 Object getAttribute(String name)
          Get the value of an attribute.
protected  String getBuilderConfigURL()
          Get the location of the treebuilder config file.
 List getDisposableNodes()
          Return the list of ProcessingNodes part of this tree that are Disposable.
 List getEnterSitemapEventListeners()
          Return all event listers that are registered for the EnterSitemapEvent.
 Map getHintsForStatement(String role, String hint, Configuration statement)
          Extract pipeline-hints from the given statement (if any exist)
 List getLeaveSitemapEventListeners()
          Return all event listers that are registered for the LeaveSitemapEvent.
protected  org.apache.cocoon.util.location.LocationImpl getLocation(Configuration config)
           
 String getMimeType(String role, String hint)
          Get the mime-type for a component (either a serializer or a reader)
 String getNamespace()
          Get the namespace URI that builders should use to find their nodes.
protected  Map getParameters(Configuration config, org.apache.cocoon.util.location.Location location)
          Get <xxx:parameter> elements as a Map of ListOfMapResolvers, that can be turned into parameters using ListOfMapResolver.buildParameters().
 ConcreteTreeProcessor getProcessor()
           
 ProcessingNode getRegisteredNode(String name)
           
 String getTypeForStatement(Configuration statement, String role)
          Get the type for a statement : it returns the 'type' attribute if present, and otherwhise the default type defined for this role in the components declarations.
 Map getViewNodes(Collection viewNames)
          Get the {view name, view node} map for a collection of view names.
 Collection getViewsForStatement(String role, String hint, Configuration statement)
          Get the names of views for a given statement.
 WebApplicationContext getWebApplicationContext()
           
 boolean isBuildingErrorHandler()
          Are we currently building an error handler ?
 boolean isBuildingView()
          Are we currently building a view ?
protected  void linkNodes()
          Resolve links : call linkNode() on all LinkedProcessingNodeBuilders.
 void recycle()
           
protected  void registerListeners()
          Register all registered sitemap listeners
 boolean registerNode(String name, ProcessingNode node)
          Register a ProcessingNode under a given name.
protected  VariableResolver resolve(String expression)
          Resolve expression using its manager
 void service(ServiceManager serviceManager)
           
 void setAttribute(String name, Object value)
          Add an attribute.
 void setBuildingErrorHandler(boolean building)
          Set to true while building the internals of a <map:handle-errors>
 void setBuildingView(boolean building)
          Set to true while building the internals of a <map:view>
 void setProcessor(ConcreteTreeProcessor processor)
           
 ProcessingNode setupNode(ProcessingNode node, Configuration config)
          Setup a ProcessingNode by setting its location, calling all the lifecycle interfaces it implements and giving it the parameter map if it's a ParameterizableNode.
 
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

attributes

protected Map attributes

processor

protected ConcreteTreeProcessor processor
The tree processor that we are building.


itsNamespace

protected String itsNamespace
The namespace of configuration for the processor that we are building.


itsComponentInfo

protected org.apache.cocoon.components.pipeline.impl.PipelineComponentInfo itsComponentInfo
The sitemap component information grabbed while building itsMaanger


enterSitemapEventListeners

protected List enterSitemapEventListeners
Optional event listeners for the enter sitemap event


leaveSitemapEventListeners

protected List leaveSitemapEventListeners
Optional event listeners for the leave sitemap event


FIRST_POS_LABEL

public static final String FIRST_POS_LABEL
Pseudo-label for views from-position="first" (i.e. generator).

See Also:
Constant Field Values

LAST_POS_LABEL

public static final String LAST_POS_LABEL
Pseudo-label for views from-position="last" (i.e. serializer).

See Also:
Constant Field Values
Constructor Detail

SitemapLanguage

public SitemapLanguage()
Method Detail

contextualize

public void contextualize(Context avalonContext)
                   throws ContextException
Specified by:
contextualize in interface Contextualizable
Throws:
ContextException
See Also:
Contextualizable.contextualize(org.apache.avalon.framework.context.Context)

service

public void service(ServiceManager serviceManager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException
See Also:
Serviceable.service(org.apache.avalon.framework.service.ServiceManager)

getBuilderConfigURL

protected String getBuilderConfigURL()
Get the location of the treebuilder config file. Can be overridden for other versions.

Returns:
The location of the treebuilder config file

setAttribute

public void setAttribute(String name,
                         Object value)
Description copied from interface: TreeBuilder
Add an attribute. Useful to transmit information between distant (in the tree) node builders

Specified by:
setAttribute in interface TreeBuilder
See Also:
TreeBuilder.setAttribute(java.lang.String, java.lang.Object)

getAttribute

public Object getAttribute(String name)
Description copied from interface: TreeBuilder
Get the value of an attribute.

Specified by:
getAttribute in interface TreeBuilder
See Also:
TreeBuilder.getAttribute(java.lang.String)

setProcessor

public void setProcessor(ConcreteTreeProcessor processor)
Specified by:
setProcessor in interface TreeBuilder
See Also:
TreeBuilder.setProcessor(ConcreteTreeProcessor)

getProcessor

public ConcreteTreeProcessor getProcessor()
Specified by:
getProcessor in interface TreeBuilder
See Also:
TreeBuilder.getProcessor()

getWebApplicationContext

public WebApplicationContext getWebApplicationContext()
Specified by:
getWebApplicationContext in interface TreeBuilder
See Also:
TreeBuilder.getWebApplicationContext()

getEnterSitemapEventListeners

public List getEnterSitemapEventListeners()
Description copied from interface: TreeBuilder
Return all event listers that are registered for the EnterSitemapEvent.

Specified by:
getEnterSitemapEventListeners in interface TreeBuilder
Returns:
A list of components.
See Also:
TreeBuilder.getEnterSitemapEventListeners()

getLeaveSitemapEventListeners

public List getLeaveSitemapEventListeners()
Description copied from interface: TreeBuilder
Return all event listers that are registered for the LeaveSitemapEvent.

Specified by:
getLeaveSitemapEventListeners in interface TreeBuilder
Returns:
A list of components.
See Also:
TreeBuilder.getLeaveSitemapEventListeners()

registerNode

public boolean registerNode(String name,
                            ProcessingNode node)
Description copied from interface: TreeBuilder
Register a ProcessingNode under a given name. For example, ResourceNodeBuilder stores here the ProcessingNodes it produces for use by sitemap pipelines. This allows to turn the tree into a graph. If a node with the name is already registed, the process fails!

Specified by:
registerNode in interface TreeBuilder
Returns:
If the node could be registered, true is returned; otherwise false.
See Also:
TreeBuilder.registerNode(java.lang.String, org.apache.cocoon.components.treeprocessor.ProcessingNode)

getRegisteredNode

public ProcessingNode getRegisteredNode(String name)
Specified by:
getRegisteredNode in interface TreeBuilder
See Also:
TreeBuilder.getRegisteredNode(java.lang.String)

createNodeBuilder

public ProcessingNodeBuilder createNodeBuilder(Configuration config)
                                        throws Exception
Specified by:
createNodeBuilder in interface TreeBuilder
Throws:
Exception
See Also:
TreeBuilder.createNodeBuilder(org.apache.avalon.framework.configuration.Configuration)

createTree

protected ProcessingNode createTree(Configuration tree)
                             throws Exception
Create the tree once component manager and node builders have been set up. Can be overriden by subclasses to perform pre/post tree creation operations.

Throws:
Exception

linkNodes

protected void linkNodes()
                  throws Exception
Resolve links : call linkNode() on all LinkedProcessingNodeBuilders. Can be overriden by subclasses to perform pre/post resolution operations. Before linking nodes, lookup the view category node used in getViewNodes(Collection).

Throws:
Exception

getNamespace

public String getNamespace()
Get the namespace URI that builders should use to find their nodes.

Specified by:
getNamespace in interface TreeBuilder

build

public ProcessingNode build(Configuration tree,
                            String location)
                     throws Exception
Build a processing tree from a Configuration.

Specified by:
build in interface TreeBuilder
Throws:
Exception

getDisposableNodes

public List getDisposableNodes()
Return the list of ProcessingNodes part of this tree that are Disposable. Care should be taken to properly dispose them before trashing the processing tree.

Specified by:
getDisposableNodes in interface TreeBuilder

setupNode

public ProcessingNode setupNode(ProcessingNode node,
                                Configuration config)
                         throws Exception
Setup a ProcessingNode by setting its location, calling all the lifecycle interfaces it implements and giving it the parameter map if it's a ParameterizableNode.

As a convenience, the node is returned by this method to allow constructs like return treeBuilder.setupNode(new MyNode(), config).

Specified by:
setupNode in interface TreeBuilder
Throws:
Exception

getLocation

protected org.apache.cocoon.util.location.LocationImpl getLocation(Configuration config)

getParameters

protected Map getParameters(Configuration config,
                            org.apache.cocoon.util.location.Location location)
                     throws ConfigurationException
Get <xxx:parameter> elements as a Map of ListOfMapResolvers, that can be turned into parameters using ListOfMapResolver.buildParameters().

Returns:
the Map of ListOfMapResolver, or null if there are no parameters.
Throws:
ConfigurationException

getTypeForStatement

public String getTypeForStatement(Configuration statement,
                                  String role)
                           throws ConfigurationException
Get the type for a statement : it returns the 'type' attribute if present, and otherwhise the default type defined for this role in the components declarations.

Specified by:
getTypeForStatement in interface TreeBuilder
Parameters:
statement - the statement
role - the component's role (warn: not the selector's role)
Throws:
ConfigurationException - if the type could not be found.

resolve

protected VariableResolver resolve(String expression)
                            throws org.apache.cocoon.sitemap.PatternException
Resolve expression using its manager

Throws:
org.apache.cocoon.sitemap.PatternException

recycle

public void recycle()
Specified by:
recycle in interface Recyclable

registerListeners

protected void registerListeners()
Register all registered sitemap listeners


setBuildingView

public void setBuildingView(boolean building)
Set to true while building the internals of a <map:view>


isBuildingView

public boolean isBuildingView()
Are we currently building a view ?


setBuildingErrorHandler

public void setBuildingErrorHandler(boolean building)
Set to true while building the internals of a <map:handle-errors>


isBuildingErrorHandler

public boolean isBuildingErrorHandler()
Are we currently building an error handler ?


addViewForLabel

public void addViewForLabel(String label,
                            String view)
Add a view for a label. This is used to register all views that start from a given label.

Parameters:
label - the label (or pseudo-label) for the view
view - the view name

getViewsForStatement

public Collection getViewsForStatement(String role,
                                       String hint,
                                       Configuration statement)
                                throws Exception
Get the names of views for a given statement. If the cocoon view exists in the returned collection, the statement can directly branch to the view-handling node.

Parameters:
role - the component role (e.g. Generator.ROLE)
hint - the component hint, i.e. the 'type' attribute
statement - the sitemap statement
Returns:
the view names for this statement
Throws:
Exception

getViewNodes

public Map getViewNodes(Collection viewNames)
                 throws Exception
Get the {view name, view node} map for a collection of view names. This allows to resolve view nodes at build time, thus avoiding runtime lookup.

Parameters:
viewNames - the view names
Returns:
association of names to views
Throws:
Exception

getHintsForStatement

public Map getHintsForStatement(String role,
                                String hint,
                                Configuration statement)
                         throws Exception
Extract pipeline-hints from the given statement (if any exist)

Parameters:
role - the component role (e.g. Generator.ROLE)
hint - the component hint, i.e. the 'type' attribute
statement - the sitemap statement
Returns:
the hint params Map for this statement, or null if none exist
Throws:
Exception

getMimeType

public String getMimeType(String role,
                          String hint)
Get the mime-type for a component (either a serializer or a reader)

Parameters:
role - the component role (e.g. Serializer.ROLE)
hint - the component hint, i.e. the 'type' attribute
Returns:
the mime-type, or null if none was set


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.