[portal-commits] JBoss Portal SVN: r5750 - in trunk: common/src/main/org/jboss/portal/common common/src/main/org/jboss/portal/common/text common/src/main/org/jboss/portal/common/util common/src/main/org/jboss/portal/test/common server/src/main/org/jboss/portal/server/servlet

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Mon Dec 4 10:03:54 EST 2006


Author: julien at jboss.com
Date: 2006-12-04 10:03:42 -0500 (Mon, 04 Dec 2006)
New Revision: 5750

Added:
   trunk/common/src/main/org/jboss/portal/common/text/
   trunk/common/src/main/org/jboss/portal/common/text/CharBuffer.java
   trunk/common/src/main/org/jboss/portal/common/text/FastURLEncoder.java
Removed:
   trunk/common/src/main/org/jboss/portal/common/util/CharBuffer.java
   trunk/common/src/main/org/jboss/portal/common/util/FastURLEncoder.java
Modified:
   trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java
   trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java
   trunk/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java
Log:
moved text oriented utils into org.jboss.portal.common.text package

Copied: trunk/common/src/main/org/jboss/portal/common/text/CharBuffer.java (from rev 5746, trunk/common/src/main/org/jboss/portal/common/util/CharBuffer.java)
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/CharBuffer.java	2006-11-30 22:53:29 UTC (rev 5746)
+++ trunk/common/src/main/org/jboss/portal/common/text/CharBuffer.java	2006-12-04 15:03:42 UTC (rev 5750)
@@ -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.text;
+
+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/text/FastURLEncoder.java (from rev 5746, trunk/common/src/main/org/jboss/portal/common/util/FastURLEncoder.java)
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/FastURLEncoder.java	2006-11-30 22:53:29 UTC (rev 5746)
+++ trunk/common/src/main/org/jboss/portal/common/text/FastURLEncoder.java	2006-12-04 15:03:42 UTC (rev 5750)
@@ -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.text;
+
+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;
+      }
+   }
+}

Deleted: trunk/common/src/main/org/jboss/portal/common/util/CharBuffer.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/CharBuffer.java	2006-12-04 13:38:17 UTC (rev 5749)
+++ trunk/common/src/main/org/jboss/portal/common/util/CharBuffer.java	2006-12-04 15:03:42 UTC (rev 5750)
@@ -1,198 +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.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;
-      }
-   }
-
-}

Deleted: trunk/common/src/main/org/jboss/portal/common/util/FastURLEncoder.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/FastURLEncoder.java	2006-12-04 13:38:17 UTC (rev 5749)
+++ trunk/common/src/main/org/jboss/portal/common/util/FastURLEncoder.java	2006-12-04 15:03:42 UTC (rev 5750)
@@ -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.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;
-      }
-   }
-}

Modified: trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java	2006-12-04 13:38:17 UTC (rev 5749)
+++ trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java	2006-12-04 15:03:42 UTC (rev 5750)
@@ -23,8 +23,8 @@
 package org.jboss.portal.test.common;
 
 import junit.framework.TestCase;
-import org.jboss.portal.common.util.CharBuffer;
-import org.jboss.portal.common.util.FastURLEncoder;
+import org.jboss.portal.common.text.CharBuffer;
+import org.jboss.portal.common.text.FastURLEncoder;
 
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>

Modified: trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java	2006-12-04 13:38:17 UTC (rev 5749)
+++ trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java	2006-12-04 15:03:42 UTC (rev 5750)
@@ -22,7 +22,7 @@
  ******************************************************************************/
 package org.jboss.portal.test.common;
 
-import org.jboss.portal.common.util.FastURLEncoder;
+import org.jboss.portal.common.text.FastURLEncoder;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;

Modified: trunk/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java	2006-12-04 13:38:17 UTC (rev 5749)
+++ trunk/server/src/main/org/jboss/portal/server/servlet/PortalServlet.java	2006-12-04 15:03:42 UTC (rev 5750)
@@ -29,8 +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.util.FastURLEncoder;
-import org.jboss.portal.common.util.CharBuffer;
+import org.jboss.portal.common.text.FastURLEncoder;
+import org.jboss.portal.common.text.CharBuffer;
 import org.jboss.portal.server.PortalConstants;
 import org.jboss.portal.server.RequestController;
 import org.jboss.portal.server.RequestControllerDispatcher;




More information about the portal-commits mailing list