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/MarkupProcessor.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java
components/wsrp/trunk/pom.xml
Log:
- Since new versions of components are going to be released, replaced duplicated code in
MarkupProcessor by call to TextTools and use 2.0.1-GA-SNAPSHOT version of common.
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/MarkupProcessor.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/MarkupProcessor.java 2010-04-26
12:18:27 UTC (rev 2777)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/MarkupProcessor.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 <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
*/
-public class MarkupProcessor
+public class MarkupProcessor implements TextTools.StringReplacementGenerator
{
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 found in common
module, copied here to avoid
- * having to release a new version of the module TODO: REMOVE when a new 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 String prefix,
final String suffix, final MarkupProcessor generator,
- final boolean replaceIfBoundedStringEmpty,
final boolean keepBoundaries, final boolean suffixIsOptional)
- {
- if (ParameterValidation.isNullOrEmpty(initial))
- {
- return initial;
- }
-
- ParameterValidation.throwIllegalArgExceptionIfNull(generator,
"StringReplacementGenerator");
-
- ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(prefix,
"prefix", "Tools.replaceBoundedString");
-
- StringBuilder tmp = new StringBuilder(initial);
- int prefixIndex = tmp.indexOf(prefix);
- final int prefixLength = prefix.length();
- boolean suffixAbsent = suffix == null;
-
- // nothing to do if didn't ask for an optional suffix and we have one and
it's not present in our string
- if (!suffixIsOptional && suffix != null && tmp.indexOf(suffix) ==
-1)
- {
- return initial;
- }
-
- // loop as long as we can find an instance of prefix in the String
- while (prefixIndex != -1)
- {
- int suffixIndex;
- if (suffixAbsent)
- {
- // replace prefix with replacement
- if (keepBoundaries)
- {
- // just insert replacement for prefix
- tmp.insert(prefixIndex + prefixLength, generator.getReplacementFor(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 = tmp.indexOf(prefix, prefixIndex + prefixLength);
- }
- else
- {
- // look for suffix
- suffixIndex = tmp.indexOf(suffix, prefixIndex);
-
- if (suffixIndex == -1)
- {
- // we haven't found suffix in the rest of the String so don't look
for it again
- suffixAbsent = true;
- continue;
- }
- else
- {
- if (suffixIsOptional)
- {
- // if suffix is optional, look for potential next prefix instance that
we'd need to replace
- int nextPrefixIndex = tmp.indexOf(prefix, prefixIndex + prefixLength);
-
- if (nextPrefixIndex != -1 && nextPrefixIndex <=
suffixIndex)
- {
- // we've found an in-between prefix, use it as the suffix for
the current match
- // delete prefix then insert remplacement instead
- tmp.delete(prefixIndex, prefixIndex + prefixLength);
- String replacement = generator.getReplacementFor(prefix, prefix,
suffix);
- tmp.insert(prefixIndex, replacement);
-
- prefixIndex = nextPrefixIndex - prefixLength +
replacement.length();
- continue;
- }
- }
-
- // we don't care about empty bounded strings or prefix and suffix
don't delimit an empty String => replace!
- if (replaceIfBoundedStringEmpty || suffixIndex != prefixIndex +
prefixLength)
- {
- String match = tmp.substring(prefixIndex + prefixLength, suffixIndex);
- if (keepBoundaries)
- {
- if (suffix != null)
- {
- // delete only match
- tmp.delete(prefixIndex + prefixLength, suffixIndex);
- }
- else
- {
- // delete nothing
- }
- tmp.insert(prefixIndex + prefixLength,
generator.getReplacementFor(match, prefix, suffix));
- }
- else
- {
- int suffixLength = suffix != null ? suffix.length() : 0;
-
- if (suffix != 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(match, prefix,
suffix));
- }
- }
- }
-
- prefixIndex = tmp.indexOf(prefix, prefixIndex + prefixLength);
-
- }
- }
-
- return tmp.toString();
- }
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java 2010-04-26
12:18:27 UTC (rev 2777)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.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 = markup.replaceFirst("%3ftimeout%3d.*%2f", "%2f");
- markup = MarkupProcessor.replaceBoundedString(
+ markup = TextTools.replaceBoundedString(
markup,
WSRPRewritingConstants.WSRP_REWRITE,
WSRPRewritingConstants.END_WSRP_REWRITE,
Modified: components/wsrp/trunk/pom.xml
===================================================================
--- 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.
-->
-<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -47,7 +48,7 @@
<properties>
<version.gatein.pc>2.1.0-GA</version.gatein.pc>
- <version.gatein.common>2.0.0-GA</version.gatein.common>
+ <version.gatein.common>2.0.1-GA-SNAPSHOT</version.gatein.common>
<version.gatein.wci>2.0.0-GA</version.gatein.wci>
<version.jsf>1.2_12</version.jsf>