| org.apache.cocoon.transformation.AbstractTransformer org.apache.cocoon.transformation.AbstractSAXTransformer org.apache.cocoon.transformation.VariableRewriterTransformer
VariableRewriterTransformer | public class VariableRewriterTransformer extends AbstractSAXTransformer implements Initializable,Disposable(Code) | | Rewrites URIs in links to a value determined by an InputModule.
The URI scheme identifies the InputModule to use, and the rest of the URI is
used as the attribute name.
Example
For instance, if we had an
org.apache.cocoon.components.modules.input.XMLFileModule , configured to
read values from an XML file:
<site>
<faq>
<how_to_boil_eggs href="faq/eggs.html"/>
</faq>
</site>
mapped to the prefix 'site:', then <link
href="site:/site/faq/how_to_boil_eggs/@href"> would be replaced with
<link href="faq/eggs.html">
InputModules are configured twice; first statically in
cocoon.xconf , and then dynamically at runtime, with dynamic
configuration (if any) taking precedence. VariableRewriterTransformer allows
you to pass a dynamic configuration to used InputModules as follows.
First, a template Configuration is specified in the static
<map:components> block of the sitemap:
<map:transformer name="linkrewriter"
src="org.apache.cocoon.transformation.VariableRewriterTransformer">
<input-module name="site" src="cocoon://samples/link/linkmap" reloadable="true"/>
<input-module name="mapper">
<input-module name="site" src="{src}" reloadable="true"/>
<prefix>/site/</prefix>
<suffix>/@href</suffix>
</input-module>
</map:transformer>
Here, we have established dynamic configuration templates for two modules,
'site' (an
org.apache.cocoon.components.modules.input.XMLFileModule and 'mapper' (A
org.apache.cocoon.components.modules.input.SimpleMappingMetaModule . All
other InputModules will use their static configs. Note that the dynamic
config syntax different to the static config syntax (attributes instead of
elements). Note also that, when configuring a Meta InputModule like
'mapper', we need to also configure the 'inner' module (here, 'site') with a
nested <input-module>.
There is one further twist; to have really dynamic configuration,
we need information available only when the transformer actually runs. This
is why the above config was called a "template" Configuration; it needs to
be 'instantiated' and provided extra info, namely:
- The {src} string will be replaced with the map:transform @src attribute value.
- Any other {variables} will be replaced with map:parameter values
With the above config template, we can have a matcher like:
<map:match pattern="**welcome">
<map:generate src="index.xml"/>
<map:transform type="linkrewriter" src="cocoon:/{1}linkmap"/>
<map:serialize type="xml"/>
</map:match>
Which would cause the 'mapper' XMLFileModule to be configured with a
different XML file, depending on the request.
Similarly, we could use a dynamic prefix:
<prefix>{prefix}</prefix>
in the template config, and:
<map:parameter name="prefix" value="/site/"/>
in the map:transform
Configuration
The following map:parameter's are recognised:
- link-attrs
- Space-separated list of attributes to consider links (to be
transformed). Defaults to 'href'.
- schemes
- Space-separated list of URI schemes to explicitly include. If specified, all URIs with unlisted schemes will not be converted.
- exclude-schemes
- Space-separated list of URI schemes to explicitly exclude.
- bad-link-str
- String to use for links with a correct InputModule prefix, but no value
therein. Defaults to the original URI.
Note that currently, only links in the default ("") namespace are converted.
author: Jeff Turner version: $Id: VariableRewriterTransformer.java 433543 2006-08-22 06:22:54Z crossley $ |
Method Summary | |
public void | characters(char[] p0, int p1, int p2) Process the SAX event. | public void | configure(Configuration conf) Configure this component from the map:transformer block. | public void | dispose() | public void | initialize() Initiate resources prior to this component becoming active. | public void | recycle() Recycle this component for use in another map:transform. | public void | setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) Setup this component to handle a map:transform instance. | public void | startTransformingElement(String uri, String name, String raw, Attributes attr) Start processing elements of our namespace. |
characters | public void characters(char[] p0, int p1, int p2) throws SAXException(Code) | | Process the SAX event.
|
configure | public void configure(Configuration conf) throws ConfigurationException(Code) | | Configure this component from the map:transformer block. Called before
initialization and setup.
|
dispose | public void dispose()(Code) | | |
initialize | public void initialize() throws Exception(Code) | | Initiate resources prior to this component becoming active.
|
recycle | public void recycle()(Code) | | Recycle this component for use in another map:transform.
|
startTransformingElement | public void startTransformingElement(String uri, String name, String raw, Attributes attr) throws ProcessingException, IOException, SAXException(Code) | | Start processing elements of our namespace.
This hook is invoked for each sax event with our namespace.
Parameters: uri - The namespace of the element. Parameters: name - The local name of the element. Parameters: raw - The qualified name of the element. Parameters: attr - The attributes of the element. |
Methods inherited from org.apache.cocoon.transformation.AbstractSAXTransformer | protected void addRecorder(XMLConsumer recorder)(Code)(Java Doc) public void characters(char[] p0, int p1, int p2) throws SAXException(Code)(Java Doc) public void comment(char ary, int start, int length) throws SAXException(Code)(Java Doc) public void configure(Configuration configuration) throws ConfigurationException(Code)(Java Doc) public void dispose()(Code)(Java Doc) public void endCDATA() throws SAXException(Code)(Java Doc) public void endDTD() throws SAXException(Code)(Java Doc) public void endDocument() throws SAXException(Code)(Java Doc) public void endElement(String uri, String name, String raw) throws SAXException(Code)(Java Doc) public void endEntity(String name) throws SAXException(Code)(Java Doc) public SourceParameters endParametersRecording(Parameters source) throws SAXException(Code)(Java Doc) public SourceParameters endParametersRecording(SourceParameters source) throws SAXException(Code)(Java Doc) public void endPrefixMapping(String prefix) throws SAXException(Code)(Java Doc) public DocumentFragment endRecording() throws SAXException(Code)(Java Doc) public XMLizable endSAXRecording() throws SAXException(Code)(Java Doc) public String endSerializedXMLRecording() throws SAXException, ProcessingException(Code)(Java Doc) public String endTextRecording() throws SAXException(Code)(Java Doc) public void endTransformingElement(String uri, String name, String raw) throws ProcessingException, IOException, SAXException(Code)(Java Doc) protected String findPrefixMapping(String uri)(Code)(Java Doc) protected AttributesImpl getMutableAttributes(Attributes a)(Code)(Java Doc) public void ignorableWhitespace(char[] p0, int p1, int p2) throws SAXException(Code)(Java Doc) public void processingInstruction(String target, String data) throws SAXException(Code)(Java Doc) public void recycle()(Code)(Java Doc) protected Object removeRecorder()(Code)(Java Doc) public void sendEndElementEvent(String localname) throws SAXException(Code)(Java Doc) public void sendEndElementEventNS(String localname) throws SAXException(Code)(Java Doc) protected void sendEndPrefixMapping() throws SAXException(Code)(Java Doc) public void sendEvents(Node node) throws SAXException(Code)(Java Doc) public void sendParametersEvents(SourceParameters pars) throws SAXException(Code)(Java Doc) public void sendStartElementEvent(String localname) throws SAXException(Code)(Java Doc) public void sendStartElementEvent(String localname, Attributes attr) throws SAXException(Code)(Java Doc) public void sendStartElementEventNS(String localname) throws SAXException(Code)(Java Doc) public void sendStartElementEventNS(String localname, Attributes attr) throws SAXException(Code)(Java Doc) protected void sendStartPrefixMapping() throws SAXException(Code)(Java Doc) public void sendTextEvent(String text) throws SAXException(Code)(Java Doc) public void service(ServiceManager manager) throws ServiceException(Code)(Java Doc) public void setDocumentLocator(Locator locator)(Code)(Java Doc) public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params) throws ProcessingException, SAXException, IOException(Code)(Java Doc) public void setupTransforming() throws IOException, ProcessingException, SAXException(Code)(Java Doc) public void skippedEntity(String name) throws SAXException(Code)(Java Doc) public void startCDATA() throws SAXException(Code)(Java Doc) public void startDTD(String name, String public_id, String system_id) throws SAXException(Code)(Java Doc) public void startDocument() throws SAXException(Code)(Java Doc) public void startElement(String uri, String name, String raw, Attributes attr) throws SAXException(Code)(Java Doc) public void startEntity(String name) throws SAXException(Code)(Java Doc) public void startParametersRecording() throws SAXException(Code)(Java Doc) public void startPrefixMapping(String prefix, String uri) throws SAXException(Code)(Java Doc) public void startRecording() throws SAXException(Code)(Java Doc) public void startSAXRecording() throws SAXException(Code)(Java Doc) public void startSerializedXMLRecording(Properties format) throws SAXException(Code)(Java Doc) public void startTextRecording() throws SAXException(Code)(Java Doc) public void startTransformingElement(String uri, String name, String raw, Attributes attr) throws ProcessingException, IOException, SAXException(Code)(Java Doc)
|
|
|