jefft 2003/05/17 01:11:27
Modified: src/webapp/WEB-INF cocoon.xconf
src/webapp/samples/modules index.xhtml menu.xml sitemap.xmap
Added: src/java/org/apache/cocoon/components/modules/input
BaseLinkModule.java
Log:
Add a module that returns a string of ../'s, one for each directory in the
current request URI.
Submitted by: Torsten Knodt
Revision Changes Path
1.1
cocoon-2.1/src/java/org/apache/cocoon/components/modules/input/BaseLinkModule.java
Index: BaseLinkModule.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.components.modules.input;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.environment.ObjectModelHelper;
/**
* BaseLinkModule returns a relative link (<code>../</code>,
* <code>../../</code> etc) to the base of the current request URI. For
* instance, if called within a <map:match pattern="a/b/c.xsp"> pipeline,
* <code>{baselink:}</code> would evaluate to <code>../../</code>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Torsten Knodt</a>
* based on RequestURIModule
*
*/
public class BaseLinkModule extends AbstractInputModule implements ThreadSafe
{
final static Vector returnNames;
static {
Vector tmp = new Vector();
tmp.add("baseLink");
returnNames = tmp;
}
public Object getAttribute( String name, Configuration modeConf, Map
objectModel ) throws ConfigurationException {
String uri =
ObjectModelHelper.getRequest(objectModel).getSitemapURI();
if (uri.startsWith("/")) {
uri = uri.substring(1);
}
StringBuffer result = new StringBuffer(uri.length());
int nextIndex = 0;
while ((nextIndex = uri.indexOf ('/', nextIndex) + 1) > 0) {
result.append("../");
}
if (getLogger().isDebugEnabled())
getLogger().debug ("Returns " + result + " for uri " + uri);
return result.toString();
}
public Iterator getAttributeNames( Configuration modeConf, Map
objectModel ) throws ConfigurationException {
return RequestURIModule.returnNames.iterator();
}
public Object[] getAttributeValues( String name, Configuration modeConf,
Map objectModel )
throws ConfigurationException {
List values = new LinkedList();
values.add( this.getAttribute(name, modeConf, objectModel) );
return values.toArray();
}
}
1.20 +1 -0 cocoon-2.1/src/webapp/WEB-INF/cocoon.xconf
Index: cocoon.xconf
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/webapp/WEB-INF/cocoon.xconf,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- cocoon.xconf 4 May 2003 06:03:12 -0000 1.19
+++ cocoon.xconf 17 May 2003 08:11:27 -0000 1.20
@@ -136,6 +136,7 @@
<input-modules>
<component-instance logger="core.modules.input" name="global"
class="org.apache.cocoon.components.modules.input.GlobalInputModule"/>
<component-instance logger="core.modules.input" name="request"
class="org.apache.cocoon.components.modules.input.RequestModule"/>
+ <component-instance logger="core.modules.input" name="baselink"
class="org.apache.cocoon.components.modules.input.BaseLinkModule" />
<component-instance logger="core.modules.input" name="session"
class="org.apache.cocoon.components.modules.input.SessionModule"/>
<component-instance logger="core.modules.input" name="request-param"
class="org.apache.cocoon.components.modules.input.RequestParameterModule"/>
<component-instance logger="core.modules.input" name="raw-request-param"
class="org.apache.cocoon.components.modules.input.RawRequestParameterModule"/>
1.4 +4 -0 cocoon-2.1/src/webapp/samples/modules/index.xhtml
Index: index.xhtml
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/modules/index.xhtml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- index.xhtml 8 May 2003 04:40:05 -0000 1.3
+++ index.xhtml 17 May 2003 08:11:27 -0000 1.4
@@ -17,6 +17,10 @@
<td>Request object properties</td>
</tr>
<tr>
+ <td><a href="baselink.xsp">baselink</a></td>
+ <td>BaseLink properties</td>
+ </tr>
+ <tr>
<td><a href="requestparam">request-param</a></td>
<td>Request parameters</td>
</tr>
1.7 +1 -0 cocoon-2.1/src/webapp/samples/modules/menu.xml
Index: menu.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/modules/menu.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- menu.xml 17 May 2003 06:48:16 -0000 1.6
+++ menu.xml 17 May 2003 08:11:27 -0000 1.7
@@ -13,6 +13,7 @@
<menu label="Modules">
<menu-item label="RequestModule" href="request.xsp"/>
+ <menu-item label="BaseLinkModule" href="baselink.xsp"/>
<menu-item label="RequestParameterModule" href="requestparam"/>
<menu-item label="DateInputModule" href="date.xsp"/>
<menu-item label="DefaultsModule" href="defaults.xsp"/>
1.6 +16 -1 cocoon-2.1/src/webapp/samples/modules/sitemap.xmap
Index: sitemap.xmap
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/modules/sitemap.xmap,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- sitemap.xmap 4 May 2003 02:07:31 -0000 1.5
+++ sitemap.xmap 17 May 2003 08:11:27 -0000 1.6
@@ -83,6 +83,21 @@
<map:parameter name="title" value="Request Input Module
(RequestModule)"/>
</map:transform>
<map:serialize />
+ </map:match>
+
+ <map:match pattern="content/baselink.xsp">
+ <map:generate type="serverpages" src="properties.xsp">
+ <map:parameter name="(anything)" value="{baselink:}"/>
+ </map:generate>
+
+ <map:transform src="properties2html.xsl">
+ <map:parameter name="title" value="BaseLink Input Module
(BaseLinkModule)"/>
+ <map:parameter name="description" value="Returns a relative path
(../,
+ ../../, etc) linking to the base of the current request URI. In
+ this demonstration, the request URI is {0} (an internal request
not
+ equivalent to what the user sees)"/>
+ </map:transform>
+ <map:serialize />
</map:match>
<map:match pattern="requestparam">