jefft 2003/06/19 04:31:06
Modified: src/blocks/linkrewriter/java/org/apache/cocoon/transformation
LinkRewriterTransformer.java
Log:
Allow the various options (attributes to intercept, schemes to process, etc) to
be configured once in the setup() method, instead of once per transformer
invocation.
Revision Changes Path
1.7 +34 -8
cocoon-2.1/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/LinkRewriterTransformer.java
Index: LinkRewriterTransformer.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/LinkRewriterTransformer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- LinkRewriterTransformer.java 13 May 2003 11:13:00 -0000 1.6
+++ LinkRewriterTransformer.java 19 Jun 2003 11:31:05 -0000 1.7
@@ -99,6 +99,8 @@
* <pre>
* <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>
@@ -111,7 +113,10 @@
* </input-module>
* </map:transformer>
* </pre>
- * Here, we have established dynamic configuration templates for two modules,
+ * 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 [EMAIL PROTECTED]
org.apache.cocoon.components.modules.input.XMLFileModule}
* and 'mapper' (A [EMAIL PROTECTED]
* org.apache.cocoon.components.modules.input.SimpleMappingMetaModule}. All
@@ -156,7 +161,7 @@
*
* <h3>Configuration</h3>
* <p>
- * The following map:parameter's are recognised:
+ * The following map:parameter's and map:transformer parameters are recognised:
* <dl>
* <dt>link-attrs</dt>
* <dd>Space-separated list of attributes to consider links (to be
@@ -209,6 +214,7 @@
*/
public void configure(Configuration conf)
throws ConfigurationException {
+ if (conf == null) throw new NullPointerException("No static configuration
passed to LinkRewriter");
this.origConf = conf;
}
@@ -230,10 +236,29 @@
{
super.setup(resolver, objectModel, src, parameters);
this.links = new HashSet();
- this.badLinkStr = parameters.getParameter("bad-link-str", null);
- this.linkAttrs = split(parameters.getParameter("link-attrs", "href"), " ");
- this.inSchemes = split(parameters.getParameter("schemes", ""), " ");
- this.outSchemes = split(parameters.getParameter("exclude-schemes", "http
https ftp news mailto"), " ");
+ this.badLinkStr = parameters.getParameter("bad-link-str", // per-request
config
+ origConf.getChild("bad-link-str"). // else fall back to
per-instance config
+ getValue(null) // else use hardcoded default
+ );
+ this.linkAttrs = split(parameters.getParameter("link-attrs",
+ origConf.getChild("link-attrs").
+ getValue("href")
+ ), " ");
+ this.inSchemes = split(parameters.getParameter("schemes",
+ origConf.getChild("schemes").
+ getValue("")
+ ), " ");
+ this.outSchemes = split(parameters.getParameter("exclude-schemes",
+ origConf.getChild("exclude-schemes").
+ getValue("http https ftp news mailto")
+ ), " ");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("bad-link-str = "+badLinkStr);
+ getLogger().debug("link-attrs = "+linkAttrs);
+ getLogger().debug("schemes = "+inSchemes);
+ getLogger().debug("exclude-schemes = "+outSchemes);
+ }
+
if (getLogger().isDebugEnabled()) {
getLogger().debug("Will ignore the following schemes: " + outSchemes);
}
@@ -267,6 +292,7 @@
* @return A Set of strings in 'str'
*/
private Set split(String str, String delim) {
+ if (str == null) return null;
Set schemes = new HashSet();
StringTokenizer st = new StringTokenizer(str, delim);
while (st.hasMoreTokens()) {
@@ -364,7 +390,7 @@
* @return Configuration for specified scheme, from the map:transformer block.
*/
private Configuration getConf(String scheme) {
- Configuration[] schemeConfs = this.conf.getChildren();
+ Configuration[] schemeConfs = this.conf.getChildren("input-module");
for (int i=0; i<schemeConfs.length; i++) {
if (scheme.equals(schemeConfs[i].getAttribute("name", null))) {
return schemeConfs[i];