You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Ralph Goers <Ra...@dslextreme.com> on 2006/05/02 18:12:55 UTC

Re: svn commit: r398882 -/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transf ormation/EncodeURLTransformer.java

Thanks for doing this.  Did you also delete ElementAttributeMatching from
the util directory?


cziegeler@apache.org said:
> Author: cziegeler
> Date: Tue May  2 02:41:56 2006
> New Revision: 398882
>
> URL: http://svn.apache.org/viewcvs?rev=398882&view=rev
> Log:
> Merge changes from 2.1.x
>
> Modified:
>     cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/EncodeURLTransformer.java
>
> Modified:
> cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/EncodeURLTransformer.java
> URL:
> http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/EncodeURLTransformer.java?rev=398882&r1=398881&r2=398882&view=diff
> ==============================================================================
> ---
> cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/EncodeURLTransformer.java
> (original)
> +++
> cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transformation/EncodeURLTransformer.java
> Tue May  2 02:41:56 2006
> @@ -17,12 +17,14 @@
>
>  import java.io.IOException;
>  import java.util.Map;
> +import java.util.regex.Pattern;
> +import java.util.regex.PatternSyntaxException;
> +
>  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.util.ElementAttributeMatching;
>  import org.apache.cocoon.caching.CacheableProcessingComponent;
>  import org.apache.cocoon.environment.ObjectModelHelper;
>  import org.apache.cocoon.environment.Request;
> @@ -31,7 +33,6 @@
>  import org.apache.cocoon.environment.SourceResolver;
>  import org.apache.excalibur.source.SourceValidity;
>  import org.apache.excalibur.source.impl.validity.NOPValidity;
> -import org.apache.regexp.RESyntaxException;
>  import org.xml.sax.Attributes;
>  import org.xml.sax.SAXException;
>  import org.xml.sax.helpers.AttributesImpl;
> @@ -105,13 +106,13 @@
>       * Configuration default exclude pattern,
>       * ie img/@src
>       */
> -    public final static String EXCLUDE_NAME_DEFAULT = "img/@src";
> +    public final static String EXCLUDE_NAME_DEFAULT = "img/@src=";
>
>      /**
>       * Configuration default exclude pattern,
>       * ie .*\/@href|.*\/@action|frame/@src
>       */
> -    public final static String INCLUDE_NAME_DEFAULT =
> ".*/@href|.*/@action|frame/@src";
> +    public final static String INCLUDE_NAME_DEFAULT =
> ".*/@href=|.*/@action=|frame/@src=";
>
>      private String includeNameConfigure = INCLUDE_NAME_DEFAULT;
>      private String excludeNameConfigure = EXCLUDE_NAME_DEFAULT;
> @@ -168,7 +169,7 @@
>                                                                 this.excludeNameConfigure);
>              try {
>                  this.elementAttributeMatching = new
> ElementAttributeMatching(includeName, excludeName);
> -            } catch (RESyntaxException reex) {
> +            } catch (PatternSyntaxException reex) {
>                  final String message = "Cannot parse include-name: " +
> includeName + " " +
>                      "or exclude-name: " + excludeName + "!";
>                  throw new ProcessingException(message, reex);
> @@ -307,6 +308,108 @@
>              encoded_url = url;
>          }
>          return encoded_url;
> +    }
> +
> +    /**
> +     * 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:bh22351@i-one.at">Bernhard Huber</a>
> +     * @version    CVS $Id$
> +     */
> +    public static class ElementAttributeMatching {
> +        /**
> +         * Regular expression of including patterns
> +         *
> +         */
> +        protected Pattern includeNameRE;
> +        /**
> +         * Regular expression of excluding patterns
> +         *
> +         */
> +        protected Pattern excludeNameRE;
> +
> +
> +        /**
> +         *Constructor for the ElementAttributeMatching object
> +         *
> +         * @param  includeName            Description of Parameter
> +         * @param  excludeName            Description of Parameter
> +         * @exception  PatternSyntaxException  Description of Exception
> +         */
> +        public ElementAttributeMatching(String includeName, String
> excludeName) throws PatternSyntaxException {
> +            includeNameRE = Pattern.compile(includeName,
> Pattern.CASE_INSENSITIVE);
> +            excludeNameRE = Pattern.compile(excludeName,
> Pattern.CASE_INSENSITIVE);
> +        }
> +
> +
> +        /**
> +         * 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
> +         * @param value TODO
> +         *
> +         * @return               boolean true iff value of attribute_name
> should get rewritten, else
> +         *   false.
> +         */
> +        public boolean matchesElementAttribute(String element_name,
> String attr_name, String value) {
> +            String element_attr_name =
> canonicalizeElementAttribute(element_name, attr_name, value);
> +
> +            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
> +         * @param value The value
> +         *
> +         * @return               Description of the Returned Value
> +         */
> +        private String canonicalizeElementAttribute(String element_name,
> String attr_name, String value) {
> +            return element_name + "/@" + attr_name + "=" + value;
> +        }
> +
> +
> +        /**
> +         * 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.
> +         */
> +        private boolean matchesExcludesElementAttribute(String
> element_attr_name) {
> +            boolean match =
> excludeNameRE.matcher(element_attr_name).lookingAt();
> +            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.
> +         */
> +        private boolean matchesIncludesElementAttribute(String
> element_attr_name) {
> +            boolean match =
> includeNameRE.matcher(element_attr_name).lookingAt();
> +            return match;
> +        }
>      }
>  }
>
>
>
>


Re: svn commit: r398882 -/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transf ormation/EncodeURLTransformer.java

Posted by Ralph Goers <Ra...@dslextreme.com>.
Right. Thanks for reminding me as I had forgotten about it.

Ralph

Carsten Ziegeler wrote:

>Ralph Goers schrieb:
>  
>
>>Do you mean in general or this specific one?  I try to in general. This 
>>one is there under 2.1.9 as fixes-bug="COCOON-1742".  Speaking of which, 
>>now that this is also on trunk I can close it.
>>
>>    
>>
>I meant this specific one. As far as I followed this, there was a bug in the
>2.1.9 release and you fixed this recently. So it might be worth adding this,
>so people upgrading to 2.1.10 will now that this one is fixed.
>
>Carsten
>  
>


Re: svn commit: r398882 -/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transf ormation/EncodeURLTransformer.java

Posted by Carsten Ziegeler <cz...@apache.org>.
Ralph Goers schrieb:
> Do you mean in general or this specific one?  I try to in general. This 
> one is there under 2.1.9 as fixes-bug="COCOON-1742".  Speaking of which, 
> now that this is also on trunk I can close it.
> 
I meant this specific one. As far as I followed this, there was a bug in the
2.1.9 release and you fixed this recently. So it might be worth adding this,
so people upgrading to 2.1.10 will now that this one is fixed.

Carsten
-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/

Re: svn commit: r398882 -/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transf ormation/EncodeURLTransformer.java

Posted by Ralph Goers <Ra...@dslextreme.com>.
Do you mean in general or this specific one?  I try to in general. This 
one is there under 2.1.9 as fixes-bug="COCOON-1742".  Speaking of which, 
now that this is also on trunk I can close it.

Ralph

Carsten Ziegeler wrote:
> Ralph Goers wrote
>   
>> Thanks for doing this.  Did you also delete ElementAttributeMatching from
>> the util directory?
>>
>>     
> Done now, thanks for the hint.
>
> Btw, could you please add an entry to status.xml in 2.1.x for your changes?
>
> Thanks
> Carsten
>   

Re: svn commit: r398882 -/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transf ormation/EncodeURLTransformer.java

Posted by Carsten Ziegeler <cz...@apache.org>.
Ralph Goers wrote
> Thanks for doing this.  Did you also delete ElementAttributeMatching from
> the util directory?
> 
Done now, thanks for the hint.

Btw, could you please add an entry to status.xml in 2.1.x for your changes?

Thanks
Carsten
-- 
Carsten Ziegeler - Open Source Group, S&N AG
http://www.s-und-n.de
http://www.osoco.org/weblogs/rael/