[jboss-svn-commits] JBoss Portal SVN: r5658 - in trunk: common common/src/main/org/jboss/portal/common/net common/src/main/org/jboss/portal/common/util common/src/main/org/jboss/portal/test/common core/src/main/org/jboss/portal/core/portlet/cms core/src/main/org/jboss/portal/core/portlet/cms/admin server/src/main/org/jboss/portal/server server/src/main/org/jboss/portal/server/impl server/src/main/org/jboss/portal/server/request server/src/main/org/jboss/portal/server/servlet
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 15 10:03:16 EST 2006
Author: julien at jboss.com
Date: 2006-11-15 10:02:57 -0500 (Wed, 15 Nov 2006)
New Revision: 5658
Added:
trunk/common/src/main/org/jboss/portal/common/util/CharBuffer.java
trunk/common/src/main/org/jboss/portal/common/util/FastURLEncoder.java
trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java
Removed:
trunk/common/src/main/org/jboss/portal/common/net/FastURLEncoder.java
Modified:
trunk/common/build.xml
trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java
trunk/core/src/main/org/jboss/portal/core/portlet/cms/CMSPortlet.java
trunk/core/src/main/org/jboss/portal/core/portlet/cms/admin/CMSAdminPortlet.java
trunk/server/src/main/org/jboss/portal/server/ServerInvocationContext.java
trunk/server/src/main/org/jboss/portal/server/ServerResponse.java
trunk/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java
trunk/server/src/main/org/jboss/portal/server/request/URLContext.java
trunk/server/src/main/org/jboss/portal/server/request/URLFormat.java
trunk/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java
Log:
added a char buffer that can reuse char array and be can be reused for the duration of the request, instead of using a string buffer.
Modified: trunk/common/build.xml
===================================================================
--- trunk/common/build.xml 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/common/build.xml 2006-11-15 15:02:57 UTC (rev 5658)
@@ -223,6 +223,7 @@
<test todir="${test.reports}" name="org.jboss.portal.test.common.ImplodeTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.Application_XWWWFormURLEncodedFormatTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.BufferedStreamTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.CharBufferTestCase"/>
</x-test>
<x-classpath>
<pathelement location="${build.classes}"/>
Deleted: trunk/common/src/main/org/jboss/portal/common/net/FastURLEncoder.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/net/FastURLEncoder.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/common/src/main/org/jboss/portal/common/net/FastURLEncoder.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -1,133 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.common.net;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
-/**
- * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class FastURLEncoder
-{
-
- /** . */
- private String encoding;
-
- /** . */
- private char[][] table;
-
- /** . */
- private int from;
-
- /** . */
- private int to;
-
- public FastURLEncoder(String encoding, int from, int to) throws UnsupportedEncodingException, IllegalArgumentException
- {
- if (encoding == null)
- {
- throw new IllegalArgumentException("No encoding provided");
- }
- if (to <= from)
- {
- throw new IllegalArgumentException("Bad range [" + from + "," + to + "[");
- }
- if (from < 0)
- {
- throw new IllegalArgumentException("Lower bound cannot be negative " + to);
- }
-
- //
- this.encoding = encoding;
- this.from = from;
- this.to = to;
- this.table = new char[to - from][];
-
- //
- for (int c = (to - 1);c >= from;c--)
- {
- String v = URLEncoder.encode(Character.toString((char)c), encoding);
- table[c - from] = v.toCharArray();
- }
- }
-
- public String encode(String s) throws UnsupportedEncodingException, IllegalArgumentException
- {
- StringBuffer tmp = new StringBuffer();
- encode(s, tmp);
- return tmp.toString();
- }
-
- public void encode(String s, StringBuffer out) throws IllegalArgumentException
- {
- if (s == null)
- {
- throw new IllegalArgumentException();
- }
- if (out == null)
- {
- throw new IllegalArgumentException();
- }
- for (int i = 0;i < s.length();i++)
- {
- char c = s.charAt(i);
- if (c >= from && c < to)
- {
- out.append(table[c - from]);
- }
- else
- {
- try
- {
- out.append(URLEncoder.encode(Character.toString(c), encoding));
- }
- catch (UnsupportedEncodingException e)
- {
- // That should never happen has the encoding validity is check at construction time
- throw new Error(e);
- }
- }
- }
- }
-
- public String toString()
- {
- return "FastURLEncoder[" + encoding + ",[" + from + "," + to + "]]";
- }
-
- public static FastURLEncoder create(String encoding, int from, int to) throws IllegalArgumentException
- {
- try
- {
- return new FastURLEncoder(encoding, from, to);
- }
- catch (UnsupportedEncodingException e)
- {
- IllegalArgumentException iae = new IllegalArgumentException();
- iae.initCause(e);
- throw iae;
- }
- }
-}
Added: trunk/common/src/main/org/jboss/portal/common/util/CharBuffer.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/CharBuffer.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/common/src/main/org/jboss/portal/common/util/CharBuffer.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -0,0 +1,198 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.util;
+
+import java.net.URLEncoder;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class CharBuffer
+{
+
+ /** . */
+ protected char[] buffer;
+
+ /** . */
+ protected int length;
+
+ public CharBuffer(int size)
+ {
+ if (size < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.buffer = new char[size];
+ this.length = 0;
+ }
+
+ public CharBuffer()
+ {
+ this.buffer = new char[512];
+ this.length = 0;
+ }
+
+ public CharBuffer append(String s)
+ {
+ if (s == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ appendNoCheck(s);
+ return this;
+ }
+
+ public CharBuffer append(String s, FastURLEncoder encoder)
+ {
+ if (s == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (encoder == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ for (int i = 0;i < s.length();i++)
+ {
+ char c = s.charAt(i);
+ if (c >= encoder.from && c < encoder.to)
+ {
+ appendNoCheck(encoder.table[c - encoder.from]);
+ }
+ else
+ {
+ try
+ {
+ appendNoCheck(URLEncoder.encode(Character.toString(c), encoder.encoding));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // That should never happen has the encoding validity is check at construction time
+ throw new Error(e);
+ }
+ }
+ }
+ return this;
+ }
+
+ public CharBuffer append(char[] chars)
+ {
+ if (chars == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ appendNoCheck(chars);
+ return this;
+ }
+
+ public CharBuffer append(char c)
+ {
+ ensureCapacity(length + 1);
+ buffer[length++] = c;
+ return this;
+ }
+
+ public String asString()
+ {
+ return new String(buffer, 0, length);
+ }
+
+ public int getCapacity()
+ {
+ return buffer.length;
+ }
+
+ public int getLength()
+ {
+ return length;
+ }
+
+ public void setLength(int length)
+ {
+ if (length < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.length = length;
+
+ //
+ if (length > buffer.length)
+ {
+ char[] tmp = new char[length];
+ System.arraycopy(buffer, 0, tmp, 0, buffer.length);
+ buffer = tmp;
+ }
+ }
+
+ public void reset()
+ {
+ this.length = 0;
+ }
+
+ protected final void appendNoCheck(char[] chars)
+ {
+ ensureCapacity(length + chars.length);
+ if (chars.length < 10)
+ {
+ for (int i = 0;i < chars.length;i++)
+ {
+ buffer[length++] = chars[i];
+ }
+ }
+ else
+ {
+ System.arraycopy(chars, 0, buffer, length, chars.length);
+ length += chars.length;
+ }
+ }
+
+ protected final void appendNoCheck(String s)
+ {
+ ensureCapacity(length + s.length());
+ s.getChars(0, s.length(), buffer, length);
+ length += s.length();
+ }
+
+ /**
+ * Can be subclassed to provide a customized implementation.
+ */
+ protected void ensureCapacity(int minimumCapacity)
+ {
+ int capacity = buffer.length;
+ if (capacity < minimumCapacity)
+ {
+ while (capacity < minimumCapacity)
+ {
+ capacity = capacity * 2 + 1;
+ }
+ char[] tmp = new char[capacity];
+ System.arraycopy(buffer, 0, tmp, 0, length);
+ buffer = tmp;
+ }
+ }
+
+}
Copied: trunk/common/src/main/org/jboss/portal/common/util/FastURLEncoder.java (from rev 5644, trunk/common/src/main/org/jboss/portal/common/net/FastURLEncoder.java)
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/net/FastURLEncoder.java 2006-11-14 07:06:34 UTC (rev 5644)
+++ trunk/common/src/main/org/jboss/portal/common/util/FastURLEncoder.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -0,0 +1,133 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.util;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class FastURLEncoder
+{
+
+ /** . */
+ protected final String encoding;
+
+ /** . */
+ protected final char[][] table;
+
+ /** . */
+ protected final int from;
+
+ /** . */
+ protected final int to;
+
+ public FastURLEncoder(String encoding, int from, int to) throws UnsupportedEncodingException, IllegalArgumentException
+ {
+ if (encoding == null)
+ {
+ throw new IllegalArgumentException("No encoding provided");
+ }
+ if (to <= from)
+ {
+ throw new IllegalArgumentException("Bad range [" + from + "," + to + "[");
+ }
+ if (from < 0)
+ {
+ throw new IllegalArgumentException("Lower bound cannot be negative " + to);
+ }
+
+ //
+ this.encoding = encoding;
+ this.from = from;
+ this.to = to;
+ this.table = new char[to - from][];
+
+ //
+ for (int c = (to - 1);c >= from;c--)
+ {
+ String v = URLEncoder.encode(Character.toString((char)c), encoding);
+ table[c - from] = v.toCharArray();
+ }
+ }
+
+ public String encode(String s) throws UnsupportedEncodingException, IllegalArgumentException
+ {
+ StringBuffer tmp = new StringBuffer();
+ encode(s, tmp);
+ return tmp.toString();
+ }
+
+ public void encode(String s, StringBuffer out) throws IllegalArgumentException
+ {
+ if (s == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (out == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ for (int i = 0;i < s.length();i++)
+ {
+ char c = s.charAt(i);
+ if (c >= from && c < to)
+ {
+ out.append(table[c - from]);
+ }
+ else
+ {
+ try
+ {
+ out.append(URLEncoder.encode(Character.toString(c), encoding));
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ // That should never happen has the encoding validity is check at construction time
+ throw new Error(e);
+ }
+ }
+ }
+ }
+
+ public String toString()
+ {
+ return "FastURLEncoder[" + encoding + ",[" + from + "," + to + "]]";
+ }
+
+ public static FastURLEncoder create(String encoding, int from, int to) throws IllegalArgumentException
+ {
+ try
+ {
+ return new FastURLEncoder(encoding, from, to);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ IllegalArgumentException iae = new IllegalArgumentException();
+ iae.initCause(e);
+ throw iae;
+ }
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -0,0 +1,118 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.util.CharBuffer;
+import org.jboss.portal.common.util.FastURLEncoder;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class CharBufferTestCase extends TestCase
+{
+
+ private FastURLEncoder encoder = FastURLEncoder.create("utf-8", 0, 512);
+
+ public void testUTF8EncodedStringAppend()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ buffer.append("/ a$\u0400", encoder);
+ assertEquals("%2F+a%24%D0%80", buffer.asString());
+ }
+
+ public void testStringAppend()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ buffer.append("abc");
+ assertEquals("abc", buffer.asString());
+ }
+
+ public void testCharArrayAppend()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ buffer.append("abc".toCharArray());
+ assertEquals("abc", buffer.asString());
+ }
+
+ public void testCharsAppend()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ buffer.append('a').append('b').append('c');
+ assertEquals("abc", buffer.asString());
+ }
+
+ public void testReset()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ buffer.append("abc".toCharArray());
+ assertEquals("abc", buffer.asString());
+ buffer.reset();
+ buffer.append("def".toCharArray());
+ assertEquals("def", buffer.asString());
+ }
+
+ public void testCharArrayAppendThrowsIAE()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ try
+ {
+ buffer.append((char[])null);
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testStringAppendThrowsIAE()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ try
+ {
+ buffer.append((String)null);
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testUTF8EncodedAppendThrowsIAE()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ try
+ {
+ buffer.append(null, encoder);
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ try
+ {
+ buffer.append("abc", null);
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+}
Modified: trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.test.common;
-import org.jboss.portal.common.net.FastURLEncoder;
+import org.jboss.portal.common.util.FastURLEncoder;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
Modified: trunk/core/src/main/org/jboss/portal/core/portlet/cms/CMSPortlet.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/portlet/cms/CMSPortlet.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/core/src/main/org/jboss/portal/core/portlet/cms/CMSPortlet.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -30,11 +30,8 @@
import org.jboss.portal.cms.util.FileUtil;
import org.jboss.portal.core.cms.StreamContentCommand;
import org.jboss.portal.core.controller.ControllerContext;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.spi.PortletInvocationContext;
import org.jboss.portal.server.request.URLContext;
import org.jboss.portal.server.request.URLFormat;
-import org.jboss.portlet.JBossRenderResponse;
import org.jboss.portlet.JBossRenderRequest;
import javax.portlet.GenericPortlet;
@@ -121,6 +118,8 @@
private static final Pattern STRIP_TAGS_PATTERN = Pattern.compile(HTMLStripperRegex, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
+ static final URLFormat RELATIVE_SERVLET_ENCODED_URL_FORMAT = URLFormat.newInstance(true, true);
+
/** Our path to jsp pages */
static final String CMS_JSP_PATH = "/WEB-INF/jsp/cms";
@@ -258,7 +257,7 @@
{
StreamContentCommand cmd = new StreamContentCommand(path);
ControllerContext cc = req.getControllerContext();
- return cc.encodeURL(cmd, URLContext.newInstance(false, false), URLFormat.RELATIVE_ENC);
+ return cc.encodeURL(cmd, URLContext.newInstance(false, false), RELATIVE_SERVLET_ENCODED_URL_FORMAT);
}
public void doHelp(RenderRequest req, RenderResponse resp) throws IOException, PortletException
Modified: trunk/core/src/main/org/jboss/portal/core/portlet/cms/admin/CMSAdminPortlet.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/portlet/cms/admin/CMSAdminPortlet.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/core/src/main/org/jboss/portal/core/portlet/cms/admin/CMSAdminPortlet.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -945,6 +945,10 @@
{
StreamContentCommand cmd = new StreamContentCommand(path);
ControllerContext cc = req.getControllerContext();
- return cc.encodeURL(cmd, URLContext.newInstance(false, false), URLFormat.RELATIVE_ENC);
+ return cc.encodeURL(cmd, NON_SECURE_NON_AUTH_URL_CONTEXT, RELATIVE_SERVLET_ENCODED_URL_FORMAT);
}
+
+ static final URLContext NON_SECURE_NON_AUTH_URL_CONTEXT = URLContext.newInstance(false, false);
+
+ static final URLFormat RELATIVE_SERVLET_ENCODED_URL_FORMAT = URLFormat.newInstance(true, true);
}
\ No newline at end of file
Modified: trunk/server/src/main/org/jboss/portal/server/ServerInvocationContext.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/ServerInvocationContext.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/server/src/main/org/jboss/portal/server/ServerInvocationContext.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -78,5 +78,5 @@
* @param format
* @return the encoded url
*/
- String encodeURL(ServerURL url, URLContext context, URLFormat format);
+ String renderURL(ServerURL url, URLContext context, URLFormat format);
}
Modified: trunk/server/src/main/org/jboss/portal/server/ServerResponse.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/ServerResponse.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/server/src/main/org/jboss/portal/server/ServerResponse.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -33,6 +33,9 @@
public class ServerResponse
{
+ /** Default format which is relative and servlet encoded. */
+ protected static final URLFormat DEFAULT_FORMAT = URLFormat.newInstance(true, true);
+
/** The server request. */
protected ServerRequest req;
@@ -73,16 +76,16 @@
public String encodeURL(ServerURL url)
{
- return invocationCtx.encodeURL(url, invocationCtx.getURLContext(), URLFormat.RELATIVE_ENC);
+ return invocationCtx.renderURL(url, invocationCtx.getURLContext(), DEFAULT_FORMAT);
}
public String encodeURL(ServerURL url, URLFormat format)
{
if (format == null)
{
- format = URLFormat.RELATIVE_ENC;
+ format = DEFAULT_FORMAT;
}
- return invocationCtx.encodeURL(url, invocationCtx.getURLContext(), format);
+ return invocationCtx.renderURL(url, invocationCtx.getURLContext(), format);
}
public String encodeURL(ServerURL url, URLContext context, URLFormat format)
@@ -93,9 +96,9 @@
}
if (format == null)
{
- format = URLFormat.RELATIVE_ENC;
+ format = DEFAULT_FORMAT;
}
- return invocationCtx.encodeURL(url, context, format);
+ return invocationCtx.renderURL(url, context, format);
}
public String encodeURL(ServerURL url, URLContext context)
@@ -104,6 +107,6 @@
{
context = invocationCtx.getURLContext();
}
- return invocationCtx.encodeURL(url, context, URLFormat.RELATIVE_ENC);
+ return invocationCtx.renderURL(url, context, DEFAULT_FORMAT);
}
}
Modified: trunk/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -66,6 +66,9 @@
/** The url context. */
private URLContext urlContext;
+ /** . */
+ private PortalServlet.Buffer[] buffers;
+
public ServerInvocationContextImpl(
HttpServletRequest req,
HttpServletResponse resp,
@@ -94,6 +97,7 @@
this.bodyParameterMap = bodyParameterMap;
this.urlContext = urlContext;
this.mediaType = mediaType;
+ this.buffers = new PortalServlet.Buffer[16];
//
addResolver(ServerInvocation.REQUEST_SCOPE, new RequestAttributeResolver(req));
@@ -122,7 +126,6 @@
return urlContext;
}
-
public Map getQueryParameterMap()
{
return queryParameterMap;
@@ -143,9 +146,14 @@
return portalContextPath;
}
- public String encodeURL(ServerURL url, URLContext context, URLFormat format)
+ public String renderURL(ServerURL url, URLContext context, URLFormat format)
{
- PortalServlet.Buffer buffer = new PortalServlet.Buffer(req, resp, context, format);
+ int index = context.getMask() << 2 | format.getMask();
+ if (buffers[index] == null)
+ {
+ buffers[index] = new PortalServlet.Buffer(req, resp, context, format);
+ }
+ PortalServlet.Buffer buffer = buffers[index];
return buffer.toString(url);
}
}
Modified: trunk/server/src/main/org/jboss/portal/server/request/URLContext.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/request/URLContext.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/server/src/main/org/jboss/portal/server/request/URLContext.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -32,25 +32,32 @@
{
/** . */
- public static final URLContext NORMAL = new URLContext(false, false);
+ public static final int SEC_MASK = 0x01;
/** . */
- public static final URLContext SEC = new URLContext(true, false);
+ public static final int AUTH_MASK = 0x02;
/** . */
- public static final URLContext AUTH = new URLContext(false, true);
+ private final int mask;
/** . */
- public static final URLContext AUTHSEC = new URLContext(true, true);
-
- /** . */
private final boolean secure;
/** . */
private final boolean authenticated;
+ /** . */
+ private static final URLContext[] contexts = new URLContext[]
+ {
+ new URLContext(false, false),
+ new URLContext(true, false),
+ new URLContext(false, true),
+ new URLContext(true, true),
+ };
+
private URLContext(boolean secure, boolean authenticated)
{
+ this.mask = (secure ? SEC_MASK : 0) | (authenticated ? AUTH_MASK : 0);
this.secure = secure;
this.authenticated = authenticated;
}
@@ -65,29 +72,19 @@
return authenticated;
}
+ public int getMask()
+ {
+ return mask;
+ }
+
+ public static URLContext newInstance(int mask)
+ {
+ return contexts[mask];
+ }
+
public static URLContext newInstance(boolean secure, boolean authenticated)
{
- if (secure)
- {
- if (authenticated)
- {
- return AUTHSEC;
- }
- else
- {
- return SEC;
- }
- }
- else
- {
- if (authenticated)
- {
- return AUTH;
- }
- else
- {
- return NORMAL;
- }
- }
+ int mask = (secure ? SEC_MASK : 0) | (authenticated ? AUTH_MASK : 0);
+ return contexts[mask];
}
}
Modified: trunk/server/src/main/org/jboss/portal/server/request/URLFormat.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/request/URLFormat.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/server/src/main/org/jboss/portal/server/request/URLFormat.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -30,27 +30,34 @@
{
/** . */
- public static final URLFormat NONRELATIVE_NONENC = new URLFormat(false, false);
+ public static final int RELATIVE_MASK = 0x01;
/** . */
- public static final URLFormat RELATIVE_NONENC = new URLFormat(true, false);
+ public static final int SERVLET_ENCODED_MASK = 0x02;
/** . */
- public static final URLFormat RELATIVE_ENC = new URLFormat(true, true);
+ private static final URLFormat[] formats = new URLFormat[]
+ {
+ new URLFormat(false, false),
+ new URLFormat(true, false),
+ new URLFormat(false, true),
+ new URLFormat(true, true),
+ };
/** . */
- public static final URLFormat NONRELATIVE_ENC = new URLFormat(false, true);
+ private final int mask;
/** . */
- private boolean relative;
+ private final boolean relative;
/** . */
- private boolean encoded;
+ private final boolean servletEncoded;
private URLFormat(boolean relative, boolean encoded)
{
+ this.mask = (relative ? RELATIVE_MASK : 0) | (encoded ? SERVLET_ENCODED_MASK : 0);
this.relative = relative;
- this.encoded = encoded;
+ this.servletEncoded = encoded;
}
public boolean isRelative()
@@ -58,34 +65,24 @@
return relative;
}
- public boolean isEncoded()
+ public boolean isServletEncoded()
{
- return encoded;
+ return servletEncoded;
}
+ public int getMask()
+ {
+ return mask;
+ }
+
+ public static URLFormat newInstance(int mask)
+ {
+ return formats[mask];
+ }
+
public static URLFormat newInstance(boolean relative, boolean encoded)
{
- if (relative)
- {
- if (encoded)
- {
- return RELATIVE_ENC;
- }
- else
- {
- return RELATIVE_NONENC;
- }
- }
- else
- {
- if (encoded)
- {
- return NONRELATIVE_ENC;
- }
- else
- {
- return NONRELATIVE_NONENC;
- }
- }
+ int mask = (relative ? RELATIVE_MASK : 0) | (encoded ? SERVLET_ENCODED_MASK : 0);
+ return formats[mask];
}
}
Modified: trunk/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java 2006-11-15 11:44:42 UTC (rev 5657)
+++ trunk/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java 2006-11-15 15:02:57 UTC (rev 5658)
@@ -29,7 +29,8 @@
import org.jboss.portal.common.invocation.InvocationException;
import org.jboss.portal.common.util.Exceptions;
import org.jboss.portal.common.util.URLTools;
-import org.jboss.portal.common.net.FastURLEncoder;
+import org.jboss.portal.common.util.FastURLEncoder;
+import org.jboss.portal.common.util.CharBuffer;
import org.jboss.portal.server.PortalConstants;
import org.jboss.portal.server.RequestController;
import org.jboss.portal.server.RequestControllerDispatcher;
@@ -435,18 +436,23 @@
}
}
- public static class Buffer
+ public static class Buffer extends CharBuffer
{
- private HttpServletRequest req;
+ /** . */
+ private final HttpServletRequest req;
- private HttpServletResponse resp;
+ /** . */
+ private final HttpServletResponse resp;
- private URLContext context;
+ /** . */
+ private final URLContext context;
- private URLFormat format;
+ /** . */
+ private final URLFormat format;
- private StringBuffer buffer = new StringBuffer(256);
+ /** . */
+ private final int prefixLength;
public Buffer(HttpServletRequest req, HttpServletResponse resp, URLContext context, URLFormat format)
{
@@ -454,17 +460,13 @@
this.resp = resp;
this.context = context;
this.format = format;
- init();
- }
- private void init()
- {
//
if (!format.isRelative())
{
- buffer.append(req.getScheme());
- buffer.append("://");
- buffer.append(req.getServerName());
+ append(req.getScheme());
+ append("://");
+ append(req.getServerName());
//
int port = req.getServerPort();
@@ -472,49 +474,46 @@
{
if (port != 443)
{
- buffer.append(":");
- buffer.append(Integer.toString(port));
+ append(":");
+ append(Integer.toString(port));
}
}
else if (port != 80)
{
- buffer.append(":");
- buffer.append(Integer.toString(port));
+ append(":");
+ append(Integer.toString(port));
}
}
// Append the context path
- buffer.append(req.getContextPath());
+ append(req.getContextPath());
// Append the servlet path
- if (context.isAuthenticated())
+ switch(context.getMask())
{
- if (context.getSecure())
- {
- buffer.append("/authsec");
- }
- else
- {
- buffer.append("/auth");
- }
+ case URLContext.AUTH_MASK + URLContext.SEC_MASK:
+ append("/authsec");
+ break;
+ case URLContext.AUTH_MASK:
+ append("/auth");
+ break;
+ case URLContext.SEC_MASK:
+ append("/sec");
+ break;
}
- else
- {
- if (context.getSecure())
- {
- buffer.append("/sec");
- }
- else
- {
- buffer.append("");
- }
- }
+
+ // Save the prefix length
+ this.prefixLength = length;
}
+
public String toString(ServerURL url)
{
+ // Reset the prefix length
+ this.length = prefixLength;
+
// julien : check UTF-8 is ok and should not be dependant on the response charset
- buffer.append(url.getPortalRequestPath());
+ append(url.getPortalRequestPath());
//
boolean first = true;
@@ -526,19 +525,19 @@
for (int j = 0; j < values.length; j++)
{
String value = values[j];
- buffer.append(first ? "?" : "&");
- urlEncoder.encode(name, buffer);
- buffer.append("=");
- urlEncoder.encode(value, buffer);
+ append(first ? '?' : '&');
+ append(name, urlEncoder);
+ append('=');
+ append(value, urlEncoder);
first = false;
}
}
- //
- String s = buffer.toString();
+ // Stringify
+ String s = asString();
- //
- if (format.isEncoded())
+ // Let the servlet rewrite the URL if necessary
+ if (format.isServletEncoded())
{
s = resp.encodeURL(s);
}
More information about the jboss-svn-commits
mailing list