cziegeler 02/03/13 23:09:50 Modified: . changes.xml src/scratchpad/src/org/apache/cocoon/sunshine SunShine.java src/webapp sitemap.xmap Added: src/java/org/apache/cocoon/transformation EncodeURLTransformer.java Removed: src/scratchpad/src/org/apache/cocoon/transformation EncodeURLTransformer.java encodeurl.xmap Log: Moved encodeURL transformer to main trunk Revision Changes Path 1.118 +5 -1 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.117 retrieving revision 1.118 diff -u -r1.117 -r1.118 --- changes.xml 13 Mar 2002 16:28:02 -0000 1.117 +++ changes.xml 14 Mar 2002 07:09:50 -0000 1.118 @@ -4,7 +4,7 @@ <!-- History of Cocoon changes - $Id: changes.xml,v 1.117 2002/03/13 16:28:02 cziegeler Exp $ + $Id: changes.xml,v 1.118 2002/03/14 07:09:50 cziegeler Exp $ --> <changes title="History of Changes"> @@ -18,6 +18,7 @@ <person name="Pierpaolo Fumagalli" email="[EMAIL PROTECTED]" id="PF"/> <person name="Vadim Gritsenko" email="[EMAIL PROTECTED]" id="VG"/> <person name="Christian Haul" email="[EMAIL PROTECTED]" id="CH"/> + <person name="Bernhard Huber" email="[EMAIL PROTECTED]" id="BH"/> <person name="Berin Loritsch" email="[EMAIL PROTECTED]" id="BL"/> <person name="Stefano Mazzocchi" email="[EMAIL PROTECTED]" id="SM"/> <person name="Giacomo Pati" email="[EMAIL PROTECTED]" id="GP"/> @@ -32,6 +33,9 @@ </devs> <release version="@version@" date="@date@"> + <action dev="BH" type="add"> + Added encodeURL transformer for encoding URIs. + </action> <action dev="CZ" type="update"> Using migrated XPath Processor from Avalon Excalibur instead of own component. </action> 1.1 xml-cocoon2/src/java/org/apache/cocoon/transformation/EncodeURLTransformer.java Index: EncodeURLTransformer.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.transformation; import java.io.IOException; import java.util.Map; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.caching.Cacheable; import org.apache.cocoon.caching.CacheValidity; import org.apache.cocoon.caching.NOPCacheValidity; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Response; import org.apache.cocoon.environment.Session; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.transformation.AbstractTransformer; import org.apache.regexp.RE; import org.apache.regexp.RESyntaxException; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; /** * The encodeURL transformer emits encoded URLs. * <p> * This transformer applies encodeURL method to URLs. * You may want to use this transform to avoid doing the manually * encodeURL() call. * </p> * <p> * Usually this transformer is appended as last transformer before * the serialization process. In this case it is possible to encode * URLs introduced in the generator, and xslt transformer phase. * </p> * <p> * You can specify which attributes hold URL values in order to restrict * URL rewriting to specific attributes only. * </p> * <p> * Usage in a sitemap: * </p> * <pre><tt> * <map:composition> * ... * <map:transformers> * ... * <map:transformer type="encodeURL" * src="org.apache.cocoon.optional.transformation.EncodeURLTransformer"> * <exclude-name>img/@src</exclude-name> * <include-name>.&asterik;/@href|.&asterik;/@src|.&asterik;/@action</include-name> * </map:transformer> * ... * <map:pipelines> * <map:pipeline> * ... * <map:transform type="encodeURL"/> * ... * </pre></tt> * * @author <a href="mailto:[EMAIL PROTECTED]">Bernhard Huber</a> * @version CVS $Id: EncodeURLTransformer.java,v 1.1 2002/03/14 07:09:50 cziegeler Exp $ * * @cocoon:name encodeURL * @cocoon:status scratchpad * @cocoon:parameter name="exclude-name" * default-value="img/@src" * description="RE pattern for excluding attributes from encode URL rewriting" * @cocoon:parameter name="include-name" * default-value=".&asterik;/@href|.&asterik;/@src|.&asterik;/@action" * description="RE pattern for including attributes from encode URL rewriting" * */ public class EncodeURLTransformer extends AbstractTransformer implements Configurable { /** * Configuration name for specifying excluding patterns, * ie exclude-name. * * @since */ public final static String EXCLUDE_NAME = "exclude-name"; /** * Configuration name for specifying including patterns, * ie include-name. * * @since */ public final static String INCLUDE_NAME = "include-name"; /** * Configuration default exclude pattern, * ie img/@src * * @since */ public final static String EXCLUDE_NAME_DEFAULT = "img/@src"; /** * Configuration default exclude pattern, * ie .*\/@href|.*\/@action|frame/@src * * @since */ public final static String INCLUDE_NAME_DEFAULT = ".*/@href|.*/@action|frame/@src"; private String includeNameConfigure = INCLUDE_NAME_DEFAULT; private String excludeNameConfigure = EXCLUDE_NAME_DEFAULT; private ElementAttributeMatching elementAttributeMatching; private Response response; private Session session; /** * Setup the transformer. * <p> * Setup include, and exclude patterns from the parameters * </p> * * @param resolver source resolver * @param objectModel sitemap objects * @param parameters request parameters * */ public void setup(SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws ProcessingException, SAXException, IOException { final Request request = ObjectModelHelper.getRequest(objectModel); this.session = request.getSession( false ); if ( null != this.session ) { if ( request.isRequestedSessionIdFromURL() ) { this.response = ObjectModelHelper.getResponse(objectModel); final String includeName = parameters.getParameter(EncodeURLTransformer.INCLUDE_NAME, this.includeNameConfigure); final String excludeName = parameters.getParameter(EncodeURLTransformer.EXCLUDE_NAME, this.excludeNameConfigure); try { this.elementAttributeMatching = new ElementAttributeMatching(includeName, excludeName); } catch (RESyntaxException reex) { final String message = "Cannot parse include-name: " + includeName + " " + "or exclude-name: " + excludeName + "!"; throw new ProcessingException(message, reex); } } else { // we don't need to encode this.session = null; } } } /** * BEGIN SitemapComponent methods * * @param configuration Description of Parameter * @exception ConfigurationException Description of Exception * @since */ public void configure(Configuration configuration) throws ConfigurationException { if (configuration != null) { Configuration child; child = configuration.getChild(EncodeURLTransformer.INCLUDE_NAME); this.includeNameConfigure = child.getValue(INCLUDE_NAME_DEFAULT); child = configuration.getChild(EncodeURLTransformer.EXCLUDE_NAME); this.excludeNameConfigure = child.getValue(EXCLUDE_NAME_DEFAULT); } if (this.includeNameConfigure == null) { String message = "Configure " + INCLUDE_NAME + "!"; throw new ConfigurationException(message); } if (this.excludeNameConfigure == null) { String message = "Configure " + EXCLUDE_NAME + "!"; throw new ConfigurationException(message); } } /** *Description of the Method * * @since */ public void recycle() { super.recycle(); this.response = null; this.session = null; this.elementAttributeMatching = null; } /** * Generate the unique key. * This key must be unique inside the space of this component. * * @return The generated key hashes the src */ public long generateKey() { if ( null == this.session ) { return 1; } return 0; } /** * Generate the validity object. * * @return The generated validity object or <code>null</code> if the * component is currently not cacheable. */ public CacheValidity generateValidity() { if ( null == this.session ) { return NOPCacheValidity.CACHE_VALIDITY; } return null; } /** * Start parsing an element * * @param uri of the element * @param name of the element * @param raw name of the element * @param attributes list * @exception SAXException Description of Exception * @since */ public void startElement(String uri, String name, String raw, Attributes attributes) throws SAXException { if (this.session != null && this.elementAttributeMatching != null) { String lname = name; if (attributes != null && attributes.getLength() > 0) { AttributesImpl new_attributes = new AttributesImpl(attributes); for (int i = 0; i < new_attributes.getLength(); i++) { String attr_lname = new_attributes.getLocalName(i); String value = new_attributes.getValue(i); if (elementAttributeMatching.matchesElementAttribute(lname, attr_lname)) { final String new_value = response.encodeURL( value ); if (getLogger().isDebugEnabled()) { this.getLogger().debug("element/@attribute matches: " + name + "/@" + attr_lname); this.getLogger().debug("encodeURL: " + value + " -> " + new_value); } new_attributes.setValue(i, new_value); } } // parent handles element using encoded attribute values super.contentHandler.startElement(uri, name, raw, new_attributes); return; } } // no match, parent handles element as-is super.contentHandler.startElement(uri, name, raw, attributes); } /** * A helper class for matching element names, and attribute names. * * <p> * For given include-name, exclude-name decide if element-attribute pair * matches. This class defines the precedence and matching algorithm. * </p> * * @author <a href="mailto:[EMAIL PROTECTED]">Bernhard Huber</a> * @version CVS $Id: EncodeURLTransformer.java,v 1.1 2002/03/14 07:09:50 cziegeler Exp $ */ public class ElementAttributeMatching { /** * Regular expression of including patterns * * @since */ protected RE includeNameRE; /** * Regular expression of excluding patterns * * @since */ protected RE excludeNameRE; /** *Constructor for the ElementAttributeMatching object * * @param includeName Description of Parameter * @param excludeName Description of Parameter * @exception RESyntaxException Description of Exception * @since */ public ElementAttributeMatching(String includeName, String excludeName) throws RESyntaxException { includeNameRE = new RE(includeName, RE.MATCH_CASEINDEPENDENT); excludeNameRE = new RE(excludeName, RE.MATCH_CASEINDEPENDENT); } /** * Return true iff element_name attr_name pair is not matched by exclude-name, * but is matched by include-name * * @param element_name * @param attr_name * @return boolean true iff value of attribute_name should get rewritten, else * false. * @since */ public boolean matchesElementAttribute(String element_name, String attr_name) { String element_attr_name = canonicalizeElementAttribute(element_name, attr_name); if (excludeNameRE != null && includeNameRE != null) { return !matchesExcludesElementAttribute(element_attr_name) && matchesIncludesElementAttribute(element_attr_name); } else { return false; } } /** * Build from elementname, and attribute name a single string. * <p> * String concatenated <code>element name + "/@" + attribute name</code> * is matched against the include and excluding patterns. * </p> * * @param element_name Description of Parameter * @param attr_name Description of Parameter * @return Description of the Returned Value * @since */ String canonicalizeElementAttribute(String element_name, String attr_name) { StringBuffer element_attr_name = new StringBuffer(); element_attr_name.append(element_name); element_attr_name.append("/@"); element_attr_name.append(attr_name); return element_attr_name.toString(); } /** * Return true iff element_name attr_name pair is matched by exclude-name. * * @param element_attr_name * @return boolean true iff exclude-name matches element_name, attr_name, else * false. * @since */ private boolean matchesExcludesElementAttribute(String element_attr_name) { boolean match = excludeNameRE.match(element_attr_name); return match; } /** * Return true iff element_name attr_name pair is matched by include-name. * * @param element_attr_name * @return boolean true iff include-name matches element_name, attr_name, else * false. * @since */ private boolean matchesIncludesElementAttribute(String element_attr_name) { boolean match = includeNameRE.match(element_attr_name); return match; } } } 1.4 +3 -14 xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/SunShine.java Index: SunShine.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/sunshine/SunShine.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SunShine.java 13 Mar 2002 17:53:22 -0000 1.3 +++ SunShine.java 14 Mar 2002 07:09:50 -0000 1.4 @@ -68,7 +68,6 @@ import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.RequestLifecycleComponent; -import org.apache.cocoon.environment.Context; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Request; @@ -76,7 +75,6 @@ import org.apache.cocoon.environment.Session; import org.apache.cocoon.environment.Source; import org.apache.cocoon.environment.SourceResolver; -import org.apache.cocoon.environment.http.HttpResponse; import org.apache.cocoon.xml.XMLConsumer; import org.w3c.dom.Attr; @@ -96,22 +94,13 @@ import org.apache.cocoon.sunshine.context.SimpleSessionContext; import org.apache.cocoon.sunshine.context.StandardSessionContextProvider; import org.apache.cocoon.sunshine.xml.XMLUtil; -//import org.apache.cocoon.sunshine.util.*; /** - * This is the basis sunShine component. + * This is the basic sunShine component. * * The main purpose of this component is session handling, maintaining contexts * and providing system management functions. - * - * This is the sunshine session object. Each user can have exactly one session - * to store information about this user on the web server. - * The session can be started programmatically by using the SunShine object - * or by specifying some xml tags for the sunshine transformer.<p> - * <p> - * The session information is divided into session contexts. Public session - * contexts are publicly available and private session contexts can only be - * accessed by using a private handle for the context. + * The session information is divided into session contexts. * * Transaction management<p> * </p> @@ -121,7 +110,7 @@ * allowed but if one thread wants to write, no other can read or write. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: SunShine.java,v 1.3 2002/03/13 17:53:22 ovidiu Exp $ + * @version CVS $Id: SunShine.java,v 1.4 2002/03/14 07:09:50 cziegeler Exp $ */ public final class SunShine extends AbstractLoggable 1.42 +3 -1 xml-cocoon2/src/webapp/sitemap.xmap Index: sitemap.xmap =================================================================== RCS file: /home/cvs/xml-cocoon2/src/webapp/sitemap.xmap,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- sitemap.xmap 13 Mar 2002 11:05:24 -0000 1.41 +++ sitemap.xmap 14 Mar 2002 07:09:50 -0000 1.42 @@ -91,7 +91,9 @@ <map:transformer name="readDOMsession" logger="sitemap.transformer.readDOMsession" src="org.apache.cocoon.transformation.ReadDOMSessionTransformer"/> - + <map:transformer name="encodeURL" logger="sitemap.transformer.encodeURL" + src="org.apache.cocoon.transformation.EncodeURLTransformer"/> + </map:transformers> <!--
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]