[gatein-commits] gatein SVN: r2318 - in components/wsrp/trunk: common/src/main/java/org/gatein/wsrp and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Mar 19 12:35:57 EDT 2010
Author: chris.laprun at jboss.com
Date: 2010-03-19 12:35:56 -0400 (Fri, 19 Mar 2010)
New Revision: 2318
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPRewritingConstants.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java
components/wsrp/trunk/pom.xml
Log:
- GTNWSRP-11: Faster implementation based on new partial matching in TextTools. This new implementation
doesn't need to scan the markup several times resulting in less memory used and RenderHandlerTestCase
execution time going from 18+ seconds to around 5.2 seconds.
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java 2010-03-19 16:26:02 UTC (rev 2317)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPPortletURL.java 2010-03-19 16:35:56 UTC (rev 2318)
@@ -126,6 +126,11 @@
public static WSRPPortletURL create(String encodedURL, Set<String> customModes, Set<String> customWindowStates)
{
+ return create(encodedURL, customModes, customWindowStates, false);
+ }
+
+ public static WSRPPortletURL create(String encodedURL, Set<String> customModes, Set<String> customWindowStates, boolean noBoundaries)
+ {
if (log.isDebugEnabled())
{
log.debug("Trying to build a WSRPPortletURL from <" + encodedURL + ">");
@@ -140,61 +145,64 @@
boolean extraAfterEnd = false;
String extra = null;
- // URL needs to start wsrp_rewrite? and end with /wsrp_rewrite in strict validation mode
- if (!encodedURL.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE))
+ if (!noBoundaries)
{
- throw new IllegalArgumentException(encodedURL + " does not start with " + WSRPRewritingConstants.BEGIN_WSRP_REWRITE);
- }
- if (!encodedURL.endsWith(WSRPRewritingConstants.END_WSRP_REWRITE))
- {
- // first remove prefix only (as suffix is not at the end of the string)
- encodedURL = encodedURL.substring(WSRPRewritingConstants.WSRP_REWRITE_PREFIX_LENGTH);
-
- // end token should be marked by the first / in the URL and extract it
- int endTokenIndex = encodedURL.indexOf('/');
- if (endTokenIndex < 0)
+ // URL needs to start wsrp_rewrite? and end with /wsrp_rewrite in strict validation mode
+ if (!encodedURL.startsWith(WSRPRewritingConstants.BEGIN_WSRP_REWRITE))
{
- throw new IllegalArgumentException(originalURL + " does not contain " + WSRPRewritingConstants.END_WSRP_REWRITE);
+ throw new IllegalArgumentException(encodedURL + " does not start with " + WSRPRewritingConstants.BEGIN_WSRP_REWRITE);
}
+ if (!encodedURL.endsWith(WSRPRewritingConstants.END_WSRP_REWRITE))
+ {
+ // first remove prefix only (as suffix is not at the end of the string)
+ encodedURL = encodedURL.substring(WSRPRewritingConstants.WSRP_REWRITE_PREFIX_LENGTH);
- encodedURL = encodedURL.substring(0, endTokenIndex)
- + encodedURL.substring(endTokenIndex + WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
+ // end token should be marked by the first / in the URL and extract it
+ int endTokenIndex = encodedURL.indexOf('/');
+ if (endTokenIndex < 0)
+ {
+ throw new IllegalArgumentException(originalURL + " does not contain " + WSRPRewritingConstants.END_WSRP_REWRITE);
+ }
- /*
- we need to deal with the case when a WSRP URL is concatenated to a context path using something similar to:
- renderResponse.encodeURL(renderRequest.getContextPath()) in which case, there should be a slash still present.
- How to process further depends on whether we're in strict mode or not...
- */
- int concatenationIndex = encodedURL.indexOf('/');
+ encodedURL = encodedURL.substring(0, endTokenIndex)
+ + encodedURL.substring(endTokenIndex + WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
- if (strict && concatenationIndex != endTokenIndex)
- {
- // in strict mode, the only character available after the end token is the concatenating slash
- throw new IllegalArgumentException(encodedURL + " does not end with "
- + WSRPRewritingConstants.END_WSRP_REWRITE + " or does not appear to be a valid concatenation of URLs.");
- }
- else
- {
- // deal with extra characters: this should only happen when the URL is concatenated to form a longer one
- // hence, it should be possible to have param-value pairs followed by a slash '/' then characters.
- // Anything after the slash will be kept as is, uninterpreted.
- if (concatenationIndex != -1)
+ /*
+ we need to deal with the case when a WSRP URL is concatenated to a context path using something similar to:
+ renderResponse.encodeURL(renderRequest.getContextPath()) in which case, there should be a slash still present.
+ How to process further depends on whether we're in strict mode or not...
+ */
+ int concatenationIndex = encodedURL.indexOf('/');
+
+ if (strict && concatenationIndex != endTokenIndex)
{
- String tmp = encodedURL;
- encodedURL = encodedURL.substring(0, concatenationIndex);
- extra = tmp.substring(concatenationIndex);
+ // in strict mode, the only character available after the end token is the concatenating slash
+ throw new IllegalArgumentException(encodedURL + " does not end with "
+ + WSRPRewritingConstants.END_WSRP_REWRITE + " or does not appear to be a valid concatenation of URLs.");
}
+ else
+ {
+ // deal with extra characters: this should only happen when the URL is concatenated to form a longer one
+ // hence, it should be possible to have param-value pairs followed by a slash '/' then characters.
+ // Anything after the slash will be kept as is, uninterpreted.
+ if (concatenationIndex != -1)
+ {
+ String tmp = encodedURL;
+ encodedURL = encodedURL.substring(0, concatenationIndex);
+ extra = tmp.substring(concatenationIndex);
+ }
- // remember that we should position the extra params after the end token
- extraAfterEnd = true;
+ // remember that we should position the extra params after the end token
+ extraAfterEnd = true;
+ }
}
+ else
+ {
+ // remove prefix and suffix
+ encodedURL = encodedURL.substring(WSRPRewritingConstants.WSRP_REWRITE_PREFIX_LENGTH,
+ encodedURL.length() - WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
+ }
}
- else
- {
- // remove prefix and suffix
- encodedURL = encodedURL.substring(WSRPRewritingConstants.WSRP_REWRITE_PREFIX_LENGTH,
- encodedURL.length() - WSRPRewritingConstants.WSRP_REWRITE_SUFFIX_LENGTH);
- }
// next param should be the url type
if (!encodedURL.startsWith(WSRPRewritingConstants.URL_TYPE_NAME + EQUALS))
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPRewritingConstants.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPRewritingConstants.java 2010-03-19 16:26:02 UTC (rev 2317)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPRewritingConstants.java 2010-03-19 16:35:56 UTC (rev 2318)
@@ -33,13 +33,14 @@
public final class WSRPRewritingConstants
{
- private static final String WSRP_REWRITE = "wsrp_rewrite";
+ public static final String WSRP_REWRITE = "wsrp_rewrite";
+ public static final String BEGIN_WSRP_REWRITE_END = "?";
/**
* 10.2.1 <p>All portlet URLs (i.e. those the Consumer needs to rewrite) are demarcated in the markup by a token
* (wsrp_rewrite) both at the start (with a "?" appended to clearly delimit the start of the name/value pairs).</p>
*/
- public static final String BEGIN_WSRP_REWRITE = WSRP_REWRITE + "?";
+ public static final String BEGIN_WSRP_REWRITE = WSRP_REWRITE + BEGIN_WSRP_REWRITE_END;
public static final int WSRP_REWRITE_PREFIX_LENGTH = 13;
@@ -154,6 +155,7 @@
*/
public static final String SECURE_URL = "wsrp-secureURL";
+ public static final String WSRP_REWRITE_TOKEN_END = "_";
/**
* 10.3.1 Consumer Rewriting (Namespace encoding) <p>The Portlet can prefix the token with "wsrp_rewrite_". The
* Consumer will locate such markers and MUST replace them with a prefix that is unique to this instance of this
@@ -162,7 +164,7 @@
* is legal for at least the JavaScript and VBScript scripting languages and CSS class names. This permits the
* independent testing of most generated markup fragments.</p>
*/
- public static final String WSRP_REWRITE_TOKEN = WSRP_REWRITE + "_";
+ public static final String WSRP_REWRITE_TOKEN = WSRP_REWRITE + WSRP_REWRITE_TOKEN_END;
/** Opening token for URL parameters. See 10.2.2. */
public static final String REWRITE_PARAMETER_OPEN = "{";
@@ -177,9 +179,13 @@
static final String ENC_CLOSE = "%7D";
/* Constants for Resource URL processing todo: remove? */
- public static final String FAKE_RESOURCE_START = "GTN_RES_REW=";
- public static final String FAKE_RESOURCE_REQ_REW = "GTN_REQ_REW";
- public static final String FAKE_RESOURCE_URL = FAKE_RESOURCE_START + "{wsrp-url}" + FAKE_RESOURCE_REQ_REW + "{wsrp-requiresRewrite}";
+ public static final String RESOURCE_URL_DELIMITER = "*";
+ public static final String FAKE_RESOURCE_START = WSRP_REWRITE + RESOURCE_URL_DELIMITER;
+ public static final String FAKE_RESOURCE_REQ_REW = RESOURCE_URL_DELIMITER;
+ public static final String WSRP_URL = REWRITE_PARAMETER_OPEN + RESOURCE_URL + REWRITE_PARAMETER_CLOSE;
+ public static final String WSRP_REQUIRES_REWRITE = REWRITE_PARAMETER_OPEN + RESOURCE_REQUIRES_REWRITE + REWRITE_PARAMETER_CLOSE;
+ public static final String FAKE_RESOURCE_URL = FAKE_RESOURCE_START + WSRP_URL + RESOURCE_URL_DELIMITER +
+ WSRP_REQUIRES_REWRITE + END_WSRP_REWRITE;
public static final String GTNRESOURCE = "gtnresource";
private WSRPRewritingConstants()
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-03-19 16:26:02 UTC (rev 2317)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/RenderHandler.java 2010-03-19 16:35:56 UTC (rev 2318)
@@ -63,7 +63,6 @@
{
private static final org.gatein.pc.api.cache.CacheControl DEFAULT_CACHE_CONTROL = new org.gatein.pc.api.cache.CacheControl(0, CacheScope.PRIVATE, null);
- public static final ResourceURLRewriter GENERATOR = new ResourceURLRewriter();
protected RenderHandler(WSRPConsumerImpl consumer)
{
@@ -195,24 +194,8 @@
{
// fix-me: how to deal with fragment header? => interceptor?
- // Replace rewrite token by namespace
- markup = TextTools.replace(markup, WSRPRewritingConstants.WSRP_REWRITE_TOKEN, namespace + '_');
-
- markup = URLTools.replaceURLsBy(markup, GENERATOR);
-
- // replace URL marked for rewriting by proper ones
markup = TextTools.replaceBoundedString(
markup,
- WSRPRewritingConstants.BEGIN_WSRP_REWRITE,
- WSRPRewritingConstants.END_WSRP_REWRITE,
- new OldResourceURLStringReplacementGenerator(context, target, format, consumer.getProducerInfo()),
- true,
- false
- );
-
-/*
- markup = TextTools.replaceBoundedString(
- markup,
WSRPRewritingConstants.WSRP_REWRITE,
WSRPRewritingConstants.END_WSRP_REWRITE,
new ResourceURLStringReplacementGenerator(namespace, context, target, format, consumer.getProducerInfo()),
@@ -220,7 +203,6 @@
false,
true
);
-*/
return markup;
}
@@ -261,47 +243,6 @@
return result;
}
- static class OldResourceURLStringReplacementGenerator implements TextTools.StringReplacementGenerator
- {
- private final PortletInvocationContext context;
- private final URLFormat format;
- private final Set<String> supportedCustomModes;
- private final Set<String> supportedCustomWindowStates;
- private final String serverAddress;
- private final String portletApplicationName;
-
- private OldResourceURLStringReplacementGenerator(PortletInvocationContext context, org.gatein.pc.api.PortletContext target, URLFormat format, ProducerInfo info)
- {
- this.context = context;
- this.format = format;
- supportedCustomModes = info.getSupportedCustomModes();
- supportedCustomWindowStates = info.getSupportedCustomWindowStates();
- serverAddress = info.getEndpointConfigurationInfo().getRemoteHostAddress();
- portletApplicationName = target.getApplicationName();
- }
-
- public String getReplacementFor(String match)
- {
- WSRPPortletURL portletURL = WSRPPortletURL.create(match, supportedCustomModes, supportedCustomWindowStates);
- if (portletURL instanceof WSRPResourceURL)
- {
- WSRPResourceURL resource = (WSRPResourceURL)portletURL;
- String replacement = getResourceURL(match, resource);
-
- // if the URL starts with /, prepend the remote host address and the portlet application name so that we
- // can attempt to create a remotely available URL
- if (replacement.startsWith(URLTools.SLASH))
- {
- replacement = WSRPResourceURL.createAbsoluteURLFrom(replacement, serverAddress, portletApplicationName);
- }
-
- return replacement;
- }
- return context.renderURL(portletURL, format);
- }
- }
-
-/*
static class ResourceURLStringReplacementGenerator implements TextTools.StringReplacementGenerator
{
private final PortletInvocationContext context;
@@ -331,7 +272,6 @@
// we have a resource URL coming from a template so extract URL
int index = match.lastIndexOf(WSRPRewritingConstants.RESOURCE_URL_DELIMITER);
- */
/*
// todo: right now, no need to extract value of require rewrite..
String requireRewriteStr = match.substring(index + URL_DELIMITER_LENGTH);
@@ -340,9 +280,8 @@
{
// FIX-ME: do something
log.debug("Required re-writing but this is not yet implemented...");
- }*//*
+ }*/
-
match = match.substring(URL_DELIMITER_LENGTH, index);
return URLTools.decodeXWWWFormURL(match);
}
@@ -370,7 +309,6 @@
return replacement;
- */
/*
todo: use this code to reactivate primitive use of resources
// get the parsed URL and add marker to it so that the consumer can know it needs to be intercepted
@@ -397,7 +335,7 @@
catch (Exception e)
{
throw new IllegalArgumentException("Cannot parse specified Resource as a URI: " + url);
- }*//*
+ }*/
}
@@ -410,37 +348,7 @@
}
}
}
-*/
- static class ResourceURLRewriter extends URLTools.URLReplacementGenerator
- {
- public String getReplacementFor(int currentIndex, URLTools.URLMatch currentMatch)
- {
- String urlAsString = currentMatch.getURLAsString();
- int beginning = urlAsString.indexOf(WSRPRewritingConstants.FAKE_RESOURCE_START);
- if (beginning != -1)
- {
- int index = urlAsString.lastIndexOf(WSRPRewritingConstants.FAKE_RESOURCE_REQ_REW);
-
- /*String requireRewriteStr = urlAsString.substring(
- index + WSRPRewritingConstants.FAKE_RESOURCE_REQ_REW.length(),
- urlAsString.indexOf(WSRPRewritingConstants.END_WSRP_REWRITE)
- );
- boolean requireRewrite = Boolean.valueOf(requireRewriteStr);
- if (requireRewrite)
- {
- // FIX-ME: do something
- log.debug("Required re-writing but this is not yet implemented...");
- }*/
-
- urlAsString = urlAsString.substring(WSRPRewritingConstants.FAKE_RESOURCE_START.length(), index);
- return URLTools.decodeXWWWFormURL(urlAsString);
- }
-
- return urlAsString;
- }
- }
-
private static String getResourceURL(String urlAsString, WSRPResourceURL resource)
{
String resourceURL = resource.getResourceURL().toExternalForm();
Modified: components/wsrp/trunk/pom.xml
===================================================================
--- components/wsrp/trunk/pom.xml 2010-03-19 16:26:02 UTC (rev 2317)
+++ components/wsrp/trunk/pom.xml 2010-03-19 16:35:56 UTC (rev 2318)
@@ -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>
More information about the gatein-commits
mailing list