Java Doc for LinkRewriterTransformer.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » transformation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » apache lenya 2.0 » org.apache.cocoon.transformation 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.apache.cocoon.transformation.AbstractTransformer
   org.apache.cocoon.transformation.AbstractSAXTransformer
      org.apache.cocoon.transformation.LinkRewriterTransformer

LinkRewriterTransformer
public class LinkRewriterTransformer 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">

InputModule Configuration

InputModules are configured twice; first statically in cocoon.xconf, and then dynamically at runtime, with dynamic configuration (if any) taking precedence. Transformer 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 within <input-module> tags:

 <map:transformer name="linkrewriter"
 src="org.apache.cocoon.transformation.LinkRewriterTransformer">
 <link-attrs>href src</link-attrs>
 <schemes>site ext</schemes>
 <input-module name="site">
 <file src="cocoon://samples/link/linkmap" reloadable="true"/>
 </input-module>
 <input-module name="mapper">
 <input-module name="site">
 <file src="{src}" reloadable="true"/>
 </input-module>
 <prefix>/site/</prefix>
 <suffix>/@href</suffix>
 </input-module>
 </map:transformer>
 
Here, we have first configured which attributes to examine, and which URL schemes to consider rewriting. In this example, <a href="site:index"> would be processed. See below for more configuration options.

Then, 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, 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

A live example of LinkRewriterTransformer can be found in the Apache Forrest sitemap.

Transformer Configuration

The following configuration entries in map:transformer block are recognised:

link-attrs
Space-separated list of attributes to consider links (to be transformed). The whole value of the attribute is considered link and transformed.
link-attr
0..n of these elements each specify an attribute containing link(s) (to be transformed) and optionally a regular expression to locate substring(s) of the attribute value considered link(s). Has two attributes:
name
(required) name of the attribute whose value contains link(s).
pattern
(optional) regular expression such that when matched against the attribute value, all parenthesized expressions (except number 0) will be considered links that should be transformed. If absent, the whole value of the attribute is considered to be a link, as if the attribute was included in 'link-attrs'.
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. Defaults to 'http https ftp news mailto'.
bad-link-str
String to use for links with a correct InputModule prefix, but no value therein. Defaults to the original URI.
namespace-uri
The namespace uri of elements whose attributes are considered for transformation. Defaults to the empty namespace ("").

The attributes considered to contain links are a set of the attributes specified in 'link-attrs' element and all 'link-attr' elements. Each attribute should be specified only once either in 'link-attrs' or 'link-attr'; i.e. an attribute can have at most 1 regular expression associated with it. If neither 'link-attrs' nor 'link-attr' configuration is present, defaults to 'href'.

Below is an example of regular expression usage that will transform links x1 and x2 in <action target="foo url(x1) bar url(x2)"/>:

 <map:transformer name="linkrewriter"
 src="org.apache.cocoon.transformation.LinkRewriterTransformer">
 <link-attr name="target" pattern="(?:url\((.*?)\).*?){1,2}$"/>
 <!-- additional configuration ... -->
 </map:transformer>
 

When matched against the value of target attribute above, the parenthesized expressions are:
$0 = url(x1) bar url(x2)
$1 = x1
$2 = x2

Expression number 0 is always discarded by the transformer and the rest are considered links and re-written.

If present, map:parameter's from the map:transform block override the corresponding configuration entries from map:transformer. As an exception, 'link-attr' parameters are not recognised; 'link-attrs' parameter overrides both 'link-attrs' and 'link-attr' configuration.


version:
   $Id: LinkRewriterTransformer.java 433543 2006-08-22 06:22:54Z crossley $





Method Summary
public  voidconfigure(Configuration conf)
     Configure this component from the map:transformer block.
public  voiddispose()
    
public  voidinitialize()
     Initiate resources prior to this component becoming active.
public  voidrecycle()
     Recycle this component for use in another map:transform.
public  voidsetup(SourceResolver resolver, Map objectModel, String src, Parameters parameters)
     Setup this component to handle a map:transform instance.
public  voidstartTransformingElement(String uri, String name, String raw, Attributes attr)
     Start processing elements of our namespace.



Method Detail
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.



setup
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException, SAXException, IOException(Code)
Setup this component to handle a map:transform instance.



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.



Fields inherited from org.apache.cocoon.transformation.AbstractSAXTransformer
final protected static Attributes EMPTY_ATTRIBUTES(Code)(Java Doc)
protected Context context(Code)(Java Doc)
protected String defaultNamespaceURI(Code)(Java Doc)
protected Attributes emptyAttributes(Code)(Java Doc)
protected boolean ignoreEmptyCharacters(Code)(Java Doc)
protected int ignoreEventsCount(Code)(Java Doc)
protected int ignoreHooksCount(Code)(Java Doc)
protected boolean ignoreWhitespaces(Code)(Java Doc)
protected ServiceManager manager(Code)(Java Doc)
protected String namespaceURI(Code)(Java Doc)
protected Map objectModel(Code)(Java Doc)
protected Parameters parameters(Code)(Java Doc)
final protected Stack recorderStack(Code)(Java Doc)
protected Request request(Code)(Java Doc)
protected SourceResolver resolver(Code)(Java Doc)
protected Response response(Code)(Java Doc)
protected String source(Code)(Java Doc)
final protected Stack stack(Code)(Java Doc)

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)


www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.