From do-not-reply at jboss.org Mon Apr 26 09:57:22 2010 Content-Type: multipart/mixed; boundary="===============3247694139130379516==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: gatein-commits at lists.jboss.org Subject: [gatein-commits] gatein SVN: r2778 - in components/wsrp/trunk: consumer/src/main/java/org/gatein/wsrp/consumer and 1 other directory. Date: Mon, 26 Apr 2010 09:57:22 -0400 Message-ID: <201004261357.o3QDvM4Z027431@svn01.web.mwc.hst.phx2.redhat.com> --===============3247694139130379516== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: chris.laprun(a)jboss.com Date: 2010-04-26 09:57:21 -0400 (Mon, 26 Apr 2010) New Revision: 2778 Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/Ma= rkupProcessor.java components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/Re= nderHandler.java components/wsrp/trunk/pom.xml Log: - Since new versions of components are going to be released, replaced dupli= cated code in MarkupProcessor by call to TextTools and use 2.0.1-GA-SNAPSHO= T version of common. Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/cons= umer/MarkupProcessor.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/M= arkupProcessor.java 2010-04-26 12:18:27 UTC (rev 2777) +++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/M= arkupProcessor.java 2010-04-26 13:57:21 UTC (rev 2778) @@ -23,7 +23,7 @@ = package org.gatein.wsrp.consumer; = -import org.gatein.common.util.ParameterValidation; +import org.gatein.common.text.TextTools; import org.gatein.pc.api.URLFormat; import org.gatein.pc.api.spi.PortletInvocationContext; import org.gatein.wsrp.WSRPPortletURL; @@ -36,7 +36,7 @@ * @author Chris Laprun * @version $Revision$ */ -public class MarkupProcessor +public class MarkupProcessor implements TextTools.StringReplacementGenerat= or { private final PortletInvocationContext context; private final URLFormat format; @@ -87,137 +87,4 @@ // right now the resourceURL should be output as is, because it will= be used directly but it really should be encoded return resourceURL; } - - /** - * TODO: This is a copy of the TextTools.replaceBoundedString method fo= und in common module, copied here to avoid - * having to release a new version of the module TODO: REMOVE when a ne= w version of common is released. - * - * @param initial - * @param prefix - * @param suffix - * @param generator - * @param replaceIfBoundedStringEmpty - * @param keepBoundaries - * @param suffixIsOptional - * @return - */ - public static String replaceBoundedString(final String initial, final S= tring prefix, final String suffix, final MarkupProcessor generator, - final boolean replaceIfBounde= dStringEmpty, final boolean keepBoundaries, final boolean suffixIsOptional) - { - if (ParameterValidation.isNullOrEmpty(initial)) - { - return initial; - } - - ParameterValidation.throwIllegalArgExceptionIfNull(generator, "Strin= gReplacementGenerator"); - - ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(prefix, "p= refix", "Tools.replaceBoundedString"); - - StringBuilder tmp =3D new StringBuilder(initial); - int prefixIndex =3D tmp.indexOf(prefix); - final int prefixLength =3D prefix.length(); - boolean suffixAbsent =3D suffix =3D=3D null; - - // nothing to do if didn't ask for an optional suffix and we have on= e and it's not present in our string - if (!suffixIsOptional && suffix !=3D null && tmp.indexOf(suffix) =3D= =3D -1) - { - return initial; - } - - // loop as long as we can find an instance of prefix in the String - while (prefixIndex !=3D -1) - { - int suffixIndex; - if (suffixAbsent) - { - // replace prefix with replacement - if (keepBoundaries) - { - // just insert replacement for prefix - tmp.insert(prefixIndex + prefixLength, generator.getReplace= mentFor(prefix, prefix, suffix)); - } - else - { - // delete prefix then insert remplacement instead - tmp.delete(prefixIndex, prefixIndex + prefixLength); - tmp.insert(prefixIndex, generator.getReplacementFor(prefix,= prefix, suffix)); - } - - // new lookup starting position - prefixIndex =3D tmp.indexOf(prefix, prefixIndex + prefixLength= ); - } - else - { - // look for suffix - suffixIndex =3D tmp.indexOf(suffix, prefixIndex); - - if (suffixIndex =3D=3D -1) - { - // we haven't found suffix in the rest of the String so don= 't look for it again - suffixAbsent =3D true; - continue; - } - else - { - if (suffixIsOptional) - { - // if suffix is optional, look for potential next prefix= instance that we'd need to replace - int nextPrefixIndex =3D tmp.indexOf(prefix, prefixIndex = + prefixLength); - - if (nextPrefixIndex !=3D -1 && nextPrefixIndex <=3D suff= ixIndex) - { - // we've found an in-between prefix, use it as the su= ffix for the current match - // delete prefix then insert remplacement instead - tmp.delete(prefixIndex, prefixIndex + prefixLength); - String replacement =3D generator.getReplacementFor(pr= efix, prefix, suffix); - tmp.insert(prefixIndex, replacement); - - prefixIndex =3D nextPrefixIndex - prefixLength + repl= acement.length(); - continue; - } - } - - // we don't care about empty bounded strings or prefix and = suffix don't delimit an empty String =3D> replace! - if (replaceIfBoundedStringEmpty || suffixIndex !=3D prefixI= ndex + prefixLength) - { - String match =3D tmp.substring(prefixIndex + prefixLengt= h, suffixIndex); - if (keepBoundaries) - { - if (suffix !=3D null) - { - // delete only match - tmp.delete(prefixIndex + prefixLength, suffixIndex= ); - } - else - { - // delete nothing - } - tmp.insert(prefixIndex + prefixLength, generator.getR= eplacementFor(match, prefix, suffix)); - } - else - { - int suffixLength =3D suffix !=3D null ? suffix.length= () : 0; - - if (suffix !=3D null) - { - // if we have a suffix, delete everything between = start of prefix and end of suffix - tmp.delete(prefixIndex, suffixIndex + suffixLength= ); - } - else - { - // only delete prefix - tmp.delete(prefixIndex, prefixIndex + prefixLength= ); - } - tmp.insert(prefixIndex, generator.getReplacementFor(m= atch, prefix, suffix)); - } - } - } - - prefixIndex =3D tmp.indexOf(prefix, prefixIndex + prefixLength= ); - - } - } - - return tmp.toString(); - } } Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/cons= umer/RenderHandler.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/R= enderHandler.java 2010-04-26 12:18:27 UTC (rev 2777) +++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/R= enderHandler.java 2010-04-26 13:57:21 UTC (rev 2778) @@ -23,6 +23,7 @@ = package org.gatein.wsrp.consumer; = +import org.gatein.common.text.TextTools; import org.gatein.pc.api.PortletInvokerException; import org.gatein.pc.api.URLFormat; import org.gatein.pc.api.cache.CacheScope; @@ -192,7 +193,7 @@ // todo: remove, this is a work-around for GTNWSRP-12 markup =3D markup.replaceFirst("%3ftimeout%3d.*%2f", "%2f"); = - markup =3D MarkupProcessor.replaceBoundedString( + markup =3D TextTools.replaceBoundedString( markup, WSRPRewritingConstants.WSRP_REWRITE, WSRPRewritingConstants.END_WSRP_REWRITE, Modified: components/wsrp/trunk/pom.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- components/wsrp/trunk/pom.xml 2010-04-26 12:18:27 UTC (rev 2777) +++ components/wsrp/trunk/pom.xml 2010-04-26 13:57:21 UTC (rev 2778) @@ -21,7 +21,8 @@ ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org. --> = - + = 4.0.0 = @@ -47,7 +48,7 @@ = 2.1.0-GA - 2.0.0-GA + 2.0.1-GA-SNAPSHOT 2.0.0-GA = 1.2_12 --===============3247694139130379516==--