cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Goers" <Ralph.Go...@dslextreme.com>
Subject Re: svn commit: r398882 -/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/transf ormation/EncodeURLTransformer.java
Date Tue, 02 May 2006 16:12:55 GMT
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;
> +        }
>      }
>  }
>
>
>
>


Mime
View raw message