You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by so...@apache.org on 2007/11/19 17:56:32 UTC
svn commit: r596365 [4/5] - in /myfaces/portlet-bridge/trunk:
api/src/main/java/javax/portlet/faces/
api/src/main/java/javax/portlet/faces/component/
impl/src/main/java/org/apache/myfaces/portlet/faces/bridge/wrapper/
impl/src/main/java/org/apache/myfa...
Modified: myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java?rev=596365&r1=596364&r2=596365&view=diff
==============================================================================
--- myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java (original)
+++ myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/QueryString.java Mon Nov 19 08:56:29 2007
@@ -1,502 +1,502 @@
-/* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.myfaces.portlet.faces.util;
-
-import java.io.UnsupportedEncodingException;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * A class encapsulating an HTTP query string.
- */
-public final class QueryString
-{
- private String mQueryString;
- private String mCharacterEncoding;
- private Map mParameterMap;
- private List mParameterList;
- private List mParameterNames;
-
- /**
- * Construct a <code>QueryString</code> from a pre-encoded string.
- */
- public QueryString(String queryString, String characterEncoding)
- {
- mQueryString = queryString;
- mCharacterEncoding = characterEncoding;
- }
-
- /**
- * Makes a copy of an existing <code>QueryString</code>.
- */
- public QueryString(QueryString source)
- {
- mQueryString = source.mQueryString;
- mCharacterEncoding = source.mCharacterEncoding;
- if (source.mParameterList != null)
- {
- mParameterList = new ArrayList(source.mParameterList);
- }
- }
-
- /**
- * Constructs an empty query string (parameters may be added later).
- */
- public QueryString(String characterEncoding)
- {
- mCharacterEncoding = characterEncoding;
- }
-
- /**
- * Constructs a query string from an old-fashioned array of PRE-ENCODED name-value pairs
- */
- public QueryString(String[][] args, String characterEncoding)
- {
- this(characterEncoding);
- for (String[] element : args)
- {
- addParameter(element[0], element[1], true);
- }
- }
-
- /**
- * Constructs a query string from a list of PRE-ENCODED name-value pairs
- */
- public QueryString(List params, String characterEncoding)
- {
- this(characterEncoding);
-
- Iterator pairs = params.iterator();
- while (pairs.hasNext())
- {
- String[] pair = (String[]) pairs.next();
- addParameter(pair[0], pair[1], true);
- }
- }
-
- /**
- * Converts this object into an encoded query string.
- */
- @Override
- public String toString()
- {
- // Use appendTo to concatenate the parameters together
- if (mQueryString == null)
- {
- appendTo(new SimpleStringBuffer(200));
- }
- return mQueryString;
- }
-
- /**
- * Appends the contents of this object to the given buffer in encoded query string form.
- *
- * @param buff
- * the buffer to append to
- */
- public void appendTo(SimpleStringBuffer buff)
- {
- // If we don't have a cached query string yet, generate it
- if (mQueryString == null)
- {
- // Remember the start position in the buffer, so that we can also
- // cache the
- // concatenated string in mQueryString
- int startPos = buff.length();
- Iterator i;
- if (mParameterList != null && (i = mParameterList.iterator()).hasNext())
- {
- Parameter param = (Parameter) i.next();
- buff.append(param.getEncodedName()).append('=').append(param.getEncodedValue());
- while (i.hasNext())
- {
- param = (Parameter) i.next();
- buff.append('&').append(param.getEncodedName()).append('=')
- .append(param.getEncodedValue());
- }
- mQueryString = buff.substring(startPos);
- }
- // If we don't have any parameters at all, cache the empty string
- else
- {
- mQueryString = "";
- }
- }
- // If we have a cached query string, reuse it
- else
- {
- buff.append(mQueryString);
- }
- }
-
- public Enumeration getParameterNames()
- {
- initParameterMap();
- return Collections.enumeration(mParameterNames);
- }
-
- public String getParameter(String name)
- {
- initParameterMap();
- List values = (List) mParameterMap.get(name);
- return values == null ? null : ((Parameter) values.get(0)).getValue();
- }
-
- public Enumeration getParameterValues(String name)
- {
- initParameterMap();
- List params = (List) mParameterMap.get(name);
- if (params == null)
- {
- return Collections.enumeration(Collections.EMPTY_LIST);
- }
- List values = new ArrayList(params.size());
- Iterator i = params.iterator();
- Parameter param;
- while (i.hasNext())
- {
- param = (Parameter) i.next();
- values.add(param.getValue());
- }
- return Collections.enumeration(values);
- }
-
- public void addParameter(String name, String value)
- {
- addParameter(name, value, false);
- }
-
- public void addParameter(String name, String value, boolean isEncoded)
- {
- if (value == null)
- {
- return;
- }
- initParameterList();
-
- // Invalidate the query string
- mQueryString = null;
-
- // Update the parameter list
- Parameter param = new Parameter(name, value, isEncoded);
- mParameterList.add(param);
-
- // Update the parameter map if it is initialized
- if (mParameterMap != null)
- {
- String decodedName = param.getName();
- List values = (List) mParameterMap.get(decodedName);
- if (values == null)
- {
- values = new ArrayList(4);
- mParameterMap.put(decodedName, values);
- // Only add UNIQUE parameter names (preserving order)
- mParameterNames.add(decodedName);
- }
- values.add(param);
- }
- }
-
- public void setParameter(String name, String value)
- {
- setParameter(name, value, false);
- }
-
- public void setParameter(String name, String value, boolean isEncoded)
- {
- if (value == null)
- {
- removeParameter(name, isEncoded);
- return;
- }
- initParameterMap();
-
- // Invalidate the query string
- mQueryString = null;
-
- // Update the map
- Parameter param = new Parameter(name, value, isEncoded);
- String decodedName = param.getName();
- List values = (List) mParameterMap.get(decodedName);
- if (values == null)
- {
- values = new ArrayList(4);
- mParameterMap.put(decodedName, values);
- // Only add UNIQUE parameter names (preserving order)
- mParameterNames.add(decodedName);
- mParameterList.add(param);
- }
- else
- {
- values.clear();
-
- // First, replace the existing occurence of the parameter
- int i = mParameterList.indexOf(param);
- mParameterList.set(i, param);
-
- // Now, remove any subsequent occurrences
- int j;
- while ((j = mParameterList.lastIndexOf(param)) > i)
- {
- mParameterList.remove(j);
- }
- }
- values.add(param);
- }
-
- public String removeParameter(String name)
- {
- return removeParameter(name, false);
- }
-
- public String removeParameter(String name, boolean isEncoded)
- {
- initParameterList();
-
- // Invalidate the query string
- mQueryString = null;
-
- // Create a template parameter for comparisons, so that we can avoid
- // decoding all parameter names in the list
- Parameter templateParam = new Parameter(name, "", isEncoded);
-
- // Update the parameter list
- Iterator i = mParameterList.iterator();
- Parameter param = null, firstParam = null;
- while (i.hasNext())
- {
- param = (Parameter) i.next();
- // Compare the parameter with our template (only the template name
- // will
- // be encoded / decoded if necessary)
- if (templateParam.equals(param))
- {
- if (firstParam == null)
- {
- firstParam = param;
- }
- i.remove();
- }
- }
-
- // Update the map, if it is initialized and we found a parameter
- if (mParameterMap != null && firstParam != null)
- {
- String decodedName = templateParam.getName();
- List values = (List) mParameterMap.remove(decodedName);
- if (values != null)
- {
- mParameterNames.remove(decodedName);
- }
- }
-
- return firstParam == null ? null : isEncoded ? firstParam.getEncodedValue()
- : firstParam.getValue();
- }
-
- private void initParameterMap()
- {
- if (mParameterMap == null)
- {
- initParameterList();
-
- mParameterMap = new HashMap(30);
- mParameterNames = new ArrayList(30);
- if (mParameterList.size() == 0)
- {
- return;
- }
- String decodedName;
- Parameter param;
- List values;
- Iterator i = mParameterList.iterator();
- while (i.hasNext())
- {
- param = (Parameter) i.next();
- decodedName = param.getName();
- values = (List) mParameterMap.get(decodedName);
- if (values == null)
- {
- values = new ArrayList(4);
- mParameterMap.put(decodedName, values);
- // Only add UNIQUE parameter names (preserving order)
- mParameterNames.add(decodedName);
- }
- values.add(param);
- }
- }
- }
-
- private void initParameterList()
- {
- if (mParameterList == null)
- {
- mParameterList = new ArrayList(30);
- int length;
- if (mQueryString == null || (length = mQueryString.length()) == 0)
- {
- return;
- }
- Parameter param;
- int lastPos = 0, nextPos, sepPos;
- do
- {
- nextPos = mQueryString.indexOf('&', lastPos);
- if (nextPos == -1)
- {
- nextPos = length;
- }
- sepPos = mQueryString.indexOf('=', lastPos);
- if (sepPos != -1 && sepPos < nextPos)
- {
- param = new Parameter(mQueryString.substring(lastPos, sepPos),
- mQueryString.substring(sepPos + 1, nextPos), true);
- }
- else
- {
- param = new Parameter(mQueryString.substring(lastPos, nextPos), "", true);
- }
- mParameterList.add(param);
- lastPos = nextPos + 1;
- } while (nextPos < length);
- }
- }
-
- private class Parameter
- {
- private String mName;
- private String mEncodedName;
-
- private String mValue;
- private String mEncodedValue;
-
- public Parameter(String name, String value, boolean encoded)
- {
- if (encoded)
- {
- mEncodedName = name;
- mEncodedValue = value;
- }
- else
- {
- mName = name;
- mValue = value;
- }
- }
-
- public String getName()
- {
- if (mName == null)
- {
- try
- {
- mName = HTTPUtils.decode(mEncodedName, mCharacterEncoding);
- }
- catch (UnsupportedEncodingException uee)
- {
- handleUnsupportedEncoding();
- }
- }
- return mName;
- }
-
- public String getEncodedName()
- {
- if (mEncodedName == null)
- {
- try
- {
- mEncodedName = HTTPUtils.encode(mName, mCharacterEncoding);
- }
- catch (UnsupportedEncodingException uee)
- {
- handleUnsupportedEncoding();
- }
- }
- return mEncodedName;
- }
-
- public String getValue()
- {
- if (mValue == null)
- {
- try
- {
- mValue = HTTPUtils.decode(mEncodedValue, mCharacterEncoding);
- }
- catch (UnsupportedEncodingException uee)
- {
- handleUnsupportedEncoding();
- }
- }
- return mValue;
- }
-
- public String getEncodedValue()
- {
- if (mEncodedValue == null)
- {
- try
- {
- mEncodedValue = HTTPUtils.encode(mValue, mCharacterEncoding);
- }
- catch (UnsupportedEncodingException uee)
- {
- handleUnsupportedEncoding();
- }
- }
- return mEncodedValue;
- }
-
- /**
- * Compares two parameters for name equality.
- *
- * Attempts not to invoke any lazy encoding or decoding in the passed in parameter - only in
- * this one.
- */
- @Override
- public boolean equals(Object o)
- {
- if (o == null || !(o instanceof Parameter))
- {
- return false;
- }
- Parameter p1 = (Parameter) o;
- return p1.mName != null && getName().equals(p1.mName) || p1.mEncodedName != null
- && getEncodedName().equals(p1.mEncodedName);
- }
- }
-
- private void handleUnsupportedEncoding()
- {
- throw new IllegalArgumentException(
- new SimpleStringBuffer(100)
- .append(
- "Unrecognized character encoding \"")
- .append(mCharacterEncoding)
- .append('"').toString());
- }
-}
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.myfaces.portlet.faces.util;
+
+import java.io.UnsupportedEncodingException;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A class encapsulating an HTTP query string.
+ */
+public final class QueryString
+{
+ private String mQueryString;
+ private String mCharacterEncoding;
+ private Map mParameterMap;
+ private List mParameterList;
+ private List mParameterNames;
+
+ /**
+ * Construct a <code>QueryString</code> from a pre-encoded string.
+ */
+ public QueryString(String queryString, String characterEncoding)
+ {
+ mQueryString = queryString;
+ mCharacterEncoding = characterEncoding;
+ }
+
+ /**
+ * Makes a copy of an existing <code>QueryString</code>.
+ */
+ public QueryString(QueryString source)
+ {
+ mQueryString = source.mQueryString;
+ mCharacterEncoding = source.mCharacterEncoding;
+ if (source.mParameterList != null)
+ {
+ mParameterList = new ArrayList(source.mParameterList);
+ }
+ }
+
+ /**
+ * Constructs an empty query string (parameters may be added later).
+ */
+ public QueryString(String characterEncoding)
+ {
+ mCharacterEncoding = characterEncoding;
+ }
+
+ /**
+ * Constructs a query string from an old-fashioned array of PRE-ENCODED name-value pairs
+ */
+ public QueryString(String[][] args, String characterEncoding)
+ {
+ this(characterEncoding);
+ for (String[] element : args)
+ {
+ addParameter(element[0], element[1], true);
+ }
+ }
+
+ /**
+ * Constructs a query string from a list of PRE-ENCODED name-value pairs
+ */
+ public QueryString(List params, String characterEncoding)
+ {
+ this(characterEncoding);
+
+ Iterator pairs = params.iterator();
+ while (pairs.hasNext())
+ {
+ String[] pair = (String[]) pairs.next();
+ addParameter(pair[0], pair[1], true);
+ }
+ }
+
+ /**
+ * Converts this object into an encoded query string.
+ */
+ @Override
+ public String toString()
+ {
+ // Use appendTo to concatenate the parameters together
+ if (mQueryString == null)
+ {
+ appendTo(new SimpleStringBuffer(200));
+ }
+ return mQueryString;
+ }
+
+ /**
+ * Appends the contents of this object to the given buffer in encoded query string form.
+ *
+ * @param buff
+ * the buffer to append to
+ */
+ public void appendTo(SimpleStringBuffer buff)
+ {
+ // If we don't have a cached query string yet, generate it
+ if (mQueryString == null)
+ {
+ // Remember the start position in the buffer, so that we can also
+ // cache the
+ // concatenated string in mQueryString
+ int startPos = buff.length();
+ Iterator i;
+ if (mParameterList != null && (i = mParameterList.iterator()).hasNext())
+ {
+ Parameter param = (Parameter) i.next();
+ buff.append(param.getEncodedName()).append('=').append(param.getEncodedValue());
+ while (i.hasNext())
+ {
+ param = (Parameter) i.next();
+ buff.append('&').append(param.getEncodedName()).append('=')
+ .append(param.getEncodedValue());
+ }
+ mQueryString = buff.substring(startPos);
+ }
+ // If we don't have any parameters at all, cache the empty string
+ else
+ {
+ mQueryString = "";
+ }
+ }
+ // If we have a cached query string, reuse it
+ else
+ {
+ buff.append(mQueryString);
+ }
+ }
+
+ public Enumeration getParameterNames()
+ {
+ initParameterMap();
+ return Collections.enumeration(mParameterNames);
+ }
+
+ public String getParameter(String name)
+ {
+ initParameterMap();
+ List values = (List) mParameterMap.get(name);
+ return values == null ? null : ((Parameter) values.get(0)).getValue();
+ }
+
+ public Enumeration getParameterValues(String name)
+ {
+ initParameterMap();
+ List params = (List) mParameterMap.get(name);
+ if (params == null)
+ {
+ return Collections.enumeration(Collections.EMPTY_LIST);
+ }
+ List values = new ArrayList(params.size());
+ Iterator i = params.iterator();
+ Parameter param;
+ while (i.hasNext())
+ {
+ param = (Parameter) i.next();
+ values.add(param.getValue());
+ }
+ return Collections.enumeration(values);
+ }
+
+ public void addParameter(String name, String value)
+ {
+ addParameter(name, value, false);
+ }
+
+ public void addParameter(String name, String value, boolean isEncoded)
+ {
+ if (value == null)
+ {
+ return;
+ }
+ initParameterList();
+
+ // Invalidate the query string
+ mQueryString = null;
+
+ // Update the parameter list
+ Parameter param = new Parameter(name, value, isEncoded);
+ mParameterList.add(param);
+
+ // Update the parameter map if it is initialized
+ if (mParameterMap != null)
+ {
+ String decodedName = param.getName();
+ List values = (List) mParameterMap.get(decodedName);
+ if (values == null)
+ {
+ values = new ArrayList(4);
+ mParameterMap.put(decodedName, values);
+ // Only add UNIQUE parameter names (preserving order)
+ mParameterNames.add(decodedName);
+ }
+ values.add(param);
+ }
+ }
+
+ public void setParameter(String name, String value)
+ {
+ setParameter(name, value, false);
+ }
+
+ public void setParameter(String name, String value, boolean isEncoded)
+ {
+ if (value == null)
+ {
+ removeParameter(name, isEncoded);
+ return;
+ }
+ initParameterMap();
+
+ // Invalidate the query string
+ mQueryString = null;
+
+ // Update the map
+ Parameter param = new Parameter(name, value, isEncoded);
+ String decodedName = param.getName();
+ List values = (List) mParameterMap.get(decodedName);
+ if (values == null)
+ {
+ values = new ArrayList(4);
+ mParameterMap.put(decodedName, values);
+ // Only add UNIQUE parameter names (preserving order)
+ mParameterNames.add(decodedName);
+ mParameterList.add(param);
+ }
+ else
+ {
+ values.clear();
+
+ // First, replace the existing occurence of the parameter
+ int i = mParameterList.indexOf(param);
+ mParameterList.set(i, param);
+
+ // Now, remove any subsequent occurrences
+ int j;
+ while ((j = mParameterList.lastIndexOf(param)) > i)
+ {
+ mParameterList.remove(j);
+ }
+ }
+ values.add(param);
+ }
+
+ public String removeParameter(String name)
+ {
+ return removeParameter(name, false);
+ }
+
+ public String removeParameter(String name, boolean isEncoded)
+ {
+ initParameterList();
+
+ // Invalidate the query string
+ mQueryString = null;
+
+ // Create a template parameter for comparisons, so that we can avoid
+ // decoding all parameter names in the list
+ Parameter templateParam = new Parameter(name, "", isEncoded);
+
+ // Update the parameter list
+ Iterator i = mParameterList.iterator();
+ Parameter param = null, firstParam = null;
+ while (i.hasNext())
+ {
+ param = (Parameter) i.next();
+ // Compare the parameter with our template (only the template name
+ // will
+ // be encoded / decoded if necessary)
+ if (templateParam.equals(param))
+ {
+ if (firstParam == null)
+ {
+ firstParam = param;
+ }
+ i.remove();
+ }
+ }
+
+ // Update the map, if it is initialized and we found a parameter
+ if (mParameterMap != null && firstParam != null)
+ {
+ String decodedName = templateParam.getName();
+ List values = (List) mParameterMap.remove(decodedName);
+ if (values != null)
+ {
+ mParameterNames.remove(decodedName);
+ }
+ }
+
+ return firstParam == null ? null : isEncoded ? firstParam.getEncodedValue()
+ : firstParam.getValue();
+ }
+
+ private void initParameterMap()
+ {
+ if (mParameterMap == null)
+ {
+ initParameterList();
+
+ mParameterMap = new HashMap(30);
+ mParameterNames = new ArrayList(30);
+ if (mParameterList.size() == 0)
+ {
+ return;
+ }
+ String decodedName;
+ Parameter param;
+ List values;
+ Iterator i = mParameterList.iterator();
+ while (i.hasNext())
+ {
+ param = (Parameter) i.next();
+ decodedName = param.getName();
+ values = (List) mParameterMap.get(decodedName);
+ if (values == null)
+ {
+ values = new ArrayList(4);
+ mParameterMap.put(decodedName, values);
+ // Only add UNIQUE parameter names (preserving order)
+ mParameterNames.add(decodedName);
+ }
+ values.add(param);
+ }
+ }
+ }
+
+ private void initParameterList()
+ {
+ if (mParameterList == null)
+ {
+ mParameterList = new ArrayList(30);
+ int length;
+ if (mQueryString == null || (length = mQueryString.length()) == 0)
+ {
+ return;
+ }
+ Parameter param;
+ int lastPos = 0, nextPos, sepPos;
+ do
+ {
+ nextPos = mQueryString.indexOf('&', lastPos);
+ if (nextPos == -1)
+ {
+ nextPos = length;
+ }
+ sepPos = mQueryString.indexOf('=', lastPos);
+ if (sepPos != -1 && sepPos < nextPos)
+ {
+ param = new Parameter(mQueryString.substring(lastPos, sepPos),
+ mQueryString.substring(sepPos + 1, nextPos), true);
+ }
+ else
+ {
+ param = new Parameter(mQueryString.substring(lastPos, nextPos), "", true);
+ }
+ mParameterList.add(param);
+ lastPos = nextPos + 1;
+ } while (nextPos < length);
+ }
+ }
+
+ private class Parameter
+ {
+ private String mName;
+ private String mEncodedName;
+
+ private String mValue;
+ private String mEncodedValue;
+
+ public Parameter(String name, String value, boolean encoded)
+ {
+ if (encoded)
+ {
+ mEncodedName = name;
+ mEncodedValue = value;
+ }
+ else
+ {
+ mName = name;
+ mValue = value;
+ }
+ }
+
+ public String getName()
+ {
+ if (mName == null)
+ {
+ try
+ {
+ mName = HTTPUtils.decode(mEncodedName, mCharacterEncoding);
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ handleUnsupportedEncoding();
+ }
+ }
+ return mName;
+ }
+
+ public String getEncodedName()
+ {
+ if (mEncodedName == null)
+ {
+ try
+ {
+ mEncodedName = HTTPUtils.encode(mName, mCharacterEncoding);
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ handleUnsupportedEncoding();
+ }
+ }
+ return mEncodedName;
+ }
+
+ public String getValue()
+ {
+ if (mValue == null)
+ {
+ try
+ {
+ mValue = HTTPUtils.decode(mEncodedValue, mCharacterEncoding);
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ handleUnsupportedEncoding();
+ }
+ }
+ return mValue;
+ }
+
+ public String getEncodedValue()
+ {
+ if (mEncodedValue == null)
+ {
+ try
+ {
+ mEncodedValue = HTTPUtils.encode(mValue, mCharacterEncoding);
+ }
+ catch (UnsupportedEncodingException uee)
+ {
+ handleUnsupportedEncoding();
+ }
+ }
+ return mEncodedValue;
+ }
+
+ /**
+ * Compares two parameters for name equality.
+ *
+ * Attempts not to invoke any lazy encoding or decoding in the passed in parameter - only in
+ * this one.
+ */
+ @Override
+ public boolean equals(Object o)
+ {
+ if (o == null || !(o instanceof Parameter))
+ {
+ return false;
+ }
+ Parameter p1 = (Parameter) o;
+ return p1.mName != null && getName().equals(p1.mName) || p1.mEncodedName != null
+ && getEncodedName().equals(p1.mEncodedName);
+ }
+ }
+
+ private void handleUnsupportedEncoding()
+ {
+ throw new IllegalArgumentException(
+ new SimpleStringBuffer(100)
+ .append(
+ "Unrecognized character encoding \"")
+ .append(mCharacterEncoding)
+ .append('"').toString());
+ }
+}
Modified: myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/SimpleStringBuffer.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/SimpleStringBuffer.java?rev=596365&r1=596364&r2=596365&view=diff
==============================================================================
--- myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/SimpleStringBuffer.java (original)
+++ myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/SimpleStringBuffer.java Mon Nov 19 08:56:29 2007
@@ -1,530 +1,530 @@
-/* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.myfaces.portlet.faces.util;
-
-/**
- * A non synchronized StringBuffer object that mimmicks the functionality of java.lang.StringBuffer.
- */
-public final class SimpleStringBuffer
-{
- private char mValue[];
- private int mLength;
-
- public SimpleStringBuffer()
- {
- this(16);
- }
-
- public SimpleStringBuffer(int length)
- {
- mValue = new char[length];
- }
-
- public SimpleStringBuffer(String str)
- {
- this(str.length() + 16);
- append(str);
- }
-
- /**
- * Returns the length (character count) of this string buffer.
- *
- * @return the number of characters in this string buffer.
- */
- public int length()
- {
- return mLength;
- }
-
- /**
- * Returns the current capacity of the String buffer. The capacity is the amount of storage
- * available for newly inserted characters; beyond which an allocation will occur.
- *
- * @return the current capacity of this string buffer.
- */
- public int capacity()
- {
- return mValue.length;
- }
-
- /**
- * Ensures that the capacity of the buffer is at least equal to the specified minimum. If the
- * current capacity of this string buffer is less than the argument, then a new internal buffer is
- * allocated with greater capacity. The new capacity is the larger of:
- * <ul>
- * <li>The <code>minimumCapacity</code> argument.
- * <li>Twice the old capacity, plus <code>2</code>.
- * </ul>
- * If the <code>minimumCapacity</code> argument is nonpositive, this method takes no action and
- * simply returns.
- *
- * @param minimumCapacity
- * the minimum desired capacity.
- */
- public void ensureCapacity(int minimumCapacity)
- {
- if (minimumCapacity > mValue.length)
- {
- int newCapacity = (mValue.length + 1) * 2;
- if (minimumCapacity > newCapacity)
- {
- newCapacity = minimumCapacity;
- }
-
- char newValue[] = new char[newCapacity];
- System.arraycopy(mValue, 0, newValue, 0, mLength);
- mValue = newValue;
-
- // Debug Facility that dumps the stack trace when
- // the buffer grows allowing sizing to be tweaked!
- // SHOULD BE COMMENTED OUT
- // printStackTrace(new Throwable());
- }
- }
-
- public void setLength(int newLength)
- {
- if (newLength < 0)
- {
- throw new StringIndexOutOfBoundsException(newLength);
- }
-
- if (newLength > mValue.length)
- {
- ensureCapacity(newLength);
- }
-
- if (mLength < newLength)
- {
- for (; mLength < newLength; mLength++)
- {
- mValue[mLength] = '\0';
- }
- }
- else
- {
- mLength = newLength;
- }
- }
-
- public char charAt(int index)
- {
- if (index < 0 || index >= mLength)
- {
- throw new StringIndexOutOfBoundsException(index);
- }
- return mValue[index];
- }
-
- public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
- {
- if (srcBegin < 0 || srcBegin >= mLength)
- {
- throw new StringIndexOutOfBoundsException(srcBegin);
- }
-
- if (srcEnd < 0 || srcEnd > mLength)
- {
- throw new StringIndexOutOfBoundsException(srcEnd);
- }
-
- if (srcBegin < srcEnd)
- {
- System.arraycopy(mValue, srcBegin, dst, dstBegin, srcEnd - srcBegin);
- }
- }
-
- public void setCharAt(int index, char ch)
- {
- if (index < 0 || index >= mLength)
- {
- throw new StringIndexOutOfBoundsException(index);
- }
- mValue[index] = ch;
- }
-
- public SimpleStringBuffer append(Object obj)
- {
- return append(String.valueOf(obj));
- }
-
- public SimpleStringBuffer append(String str)
- {
- if (str == null)
- {
- str = String.valueOf(str);
- }
-
- int len = str.length();
- int newcount = mLength + len;
- if (newcount > mValue.length)
- {
- ensureCapacity(newcount);
- }
- str.getChars(0, len, mValue, mLength);
- mLength = newcount;
- return this;
- }
-
- public SimpleStringBuffer append(char[] str)
- {
- int len = str.length;
- int newcount = mLength + len;
- if (newcount > mValue.length)
- {
- ensureCapacity(newcount);
- }
- System.arraycopy(str, 0, mValue, mLength, len);
- mLength = newcount;
- return this;
- }
-
- public SimpleStringBuffer append(char[] str, int offset, int len)
- {
- int newcount = mLength + len;
- if (newcount > mValue.length)
- {
- ensureCapacity(newcount);
- }
- System.arraycopy(str, offset, mValue, mLength, len);
- mLength = newcount;
- return this;
- }
-
- public SimpleStringBuffer append(boolean b)
- {
- return append(String.valueOf(b));
- }
-
- public SimpleStringBuffer append(char c)
- {
- int newcount = mLength + 1;
- if (newcount > mValue.length)
- {
- ensureCapacity(newcount);
- }
- mValue[mLength++] = c;
- return this;
- }
-
- /**
- */
- public SimpleStringBuffer append(int i)
- {
- return append(String.valueOf(i));
- }
-
- /**
- */
- public SimpleStringBuffer append(long l)
- {
- return append(String.valueOf(l));
- }
-
- /**
- */
- public SimpleStringBuffer append(float f)
- {
- return append(String.valueOf(f));
- }
-
- /**
- */
- public SimpleStringBuffer append(double d)
- {
- return append(String.valueOf(d));
- }
-
- /**
- */
- public SimpleStringBuffer insert(int offset, Object obj)
- {
- return insert(offset, String.valueOf(obj));
- }
-
- /**
- */
- public SimpleStringBuffer insert(int offset, String str)
- {
- if (offset < 0 || offset > mLength)
- {
- throw new StringIndexOutOfBoundsException();
- }
- int len = str.length();
- int newcount = mLength + len;
- if (newcount > mValue.length)
- {
- ensureCapacity(newcount);
- }
- System.arraycopy(mValue, offset, mValue, offset + len, mLength - offset);
- str.getChars(0, len, mValue, offset);
- mLength = newcount;
- return this;
- }
-
- /**
- */
- public SimpleStringBuffer insert(int offset, char[] str)
- {
- if (offset < 0 || offset > mLength)
- {
- throw new StringIndexOutOfBoundsException();
- }
- int len = str.length;
- int newcount = mLength + len;
- if (newcount > mValue.length)
- {
- ensureCapacity(newcount);
- }
- System.arraycopy(mValue, offset, mValue, offset + len, mLength - offset);
- System.arraycopy(str, 0, mValue, offset, len);
- mLength = newcount;
- return this;
- }
-
- /**
- */
- public SimpleStringBuffer insert(int offset, boolean b)
- {
- return insert(offset, String.valueOf(b));
- }
-
- /**
- */
- public SimpleStringBuffer insert(int offset, char c)
- {
- int newcount = mLength + 1;
- if (newcount > mValue.length)
- {
- ensureCapacity(newcount);
- }
- System.arraycopy(mValue, offset, mValue, offset + 1, mLength - offset);
- mValue[offset] = c;
- mLength = newcount;
- return this;
- }
-
- /**
- */
- public SimpleStringBuffer insert(int offset, int i)
- {
- return insert(offset, String.valueOf(i));
- }
-
- /**
- */
- public SimpleStringBuffer insert(int offset, long l)
- {
- return insert(offset, String.valueOf(l));
- }
-
- /**
- */
- public SimpleStringBuffer insert(int offset, float f)
- {
- return insert(offset, String.valueOf(f));
- }
-
- /**
- */
- public SimpleStringBuffer insert(int offset, double d)
- {
- return insert(offset, String.valueOf(d));
- }
-
- /**
- * Removes the characters in a substring of this <code>
- * SimpleStringBuffer</code>. The substring
- * begins at the specified <code>start</code> and extends to the character at index
- * <code>end</code> - 1 or to the end of the SimpleStringBuffer if no such character exists. If
- * start is equal to end, no changes are made.
- *
- * @param start -
- * the beginning index, inclusive
- * @param end -
- * the ending index, exclusive
- *
- * @return This simple string buffer
- * @exception StringIndexOutOfBoundsException -
- * if start is negative, greater than <code>length()</code>, or greater than
- * <code>end</code>.
- *
- */
- public SimpleStringBuffer delete(int start, int end)
- {
- if (start < 0)
- {
- throw new StringIndexOutOfBoundsException(start);
- }
- if (end > mLength)
- {
- end = mLength;
- }
- if (start > end)
- {
- throw new StringIndexOutOfBoundsException();
- }
- int numChars = end - start;
- if (numChars > 0)
- {
- System.arraycopy(mValue, start + numChars, mValue, start, mLength - end);
- mLength -= numChars;
- }
- return this;
- }
-
- /**
- * Removes the character at the specified position in this <code>SimpleStringBuffer</code>
- * (shortening the <code>SimpleStringBuffer</code> by one character).
- *
- * @param index -
- * index of the character to remove
- *
- * @return This simple string buffer
- * @exception StringIndexOutOfBoundsException -
- * if the <code>index</code> is negative or greater than or equal to
- * <code>length()</code>.
- *
- */
- public SimpleStringBuffer deleteCharAt(int index)
- {
- if (index < 0 || index >= mLength)
- {
- throw new StringIndexOutOfBoundsException();
- }
- System.arraycopy(mValue, index + 1, mValue, index, mLength - index - 1);
- mLength--;
- return this;
- }
-
- /**
- * Replaces the characters in a substring of this <code>SimpleStringBuffer</code> with
- * characters in the specified String. The substring begins at the specified start and extends to
- * the character at index <code>end</code> - 1 or to the end of the
- * <code>SimpleStringBuffer</code> if no such character exists. First the characters in the
- * substring are removed and then the specified String is inserted at start. (The
- * <code>SimpleStringBuffer</code> will be lengthened to accommodate the specified String if
- * necessary.)
- *
- * @param start -
- * the beginning index, inclusive
- * @param end -
- * the ending index, exclusive
- * @param str -
- * string that will replace previous contents
- *
- * @return This simple string buffer
- * @exception StringIndexOutOfBoundsException -
- * if start is negative, greater than <code>length()</code>, or greater than
- * <code>end</code>.
- *
- */
- public SimpleStringBuffer replace(int start, int end, String str)
- {
- if (start < 0)
- {
- throw new StringIndexOutOfBoundsException(start);
- }
- if (end > mLength)
- {
- end = mLength;
- }
- if (start > end)
- {
- throw new StringIndexOutOfBoundsException();
- }
-
- int numChars = str.length();
- int newLength = mLength + numChars - (end - start);
-
- if (newLength > mValue.length)
- {
- ensureCapacity(newLength);
- }
- System.arraycopy(mValue, end, mValue, start + numChars, mLength - end);
-
- str.getChars(0, numChars, mValue, start);
- mLength = newLength;
-
- return this;
- }
-
- /**
- * Returns a new <code>String</code> that contains a subsequence of characters currently
- * contained in this <code>SimpleStringBuffer</code>.The substring begins at the specified
- * index and extends to the end of the <code>StringBuffer</code>.
- *
- * @param start
- * The beginning index, inclusive.
- * @return The new string.
- * @exception StringIndexOutOfBoundsException
- * if <code>start</code> is less than zero, or greater than the length of this
- * <code>StringBuffer</code>.
- */
- public String substring(int start)
- {
- return substring(start, mLength);
- }
-
- /**
- * Returns a new <code>String</code> that contains a subsequence of characters currently
- * contained in this <code>SimpleStringBuffer</code>. The substring begins at the specified
- * <code>start</code> and extends to the character at index <code>end -
- * 1</code>.
- *
- * @param start
- * The beginning index, inclusive.
- * @param end
- * The ending index, exclusive.
- * @return The new string.
- * @exception StringIndexOutOfBoundsException
- * if <code>start</code> or <code>end</code> are negative or greater than
- * <code>length()</code>, or <code>start</code> is greater than <code>end</code>.
- */
- public String substring(int start, int end)
- {
- if (start < 0)
- {
- throw new StringIndexOutOfBoundsException(start);
- }
- if (end > mLength)
- {
- throw new StringIndexOutOfBoundsException(end);
- }
- if (start > end)
- {
- throw new StringIndexOutOfBoundsException(end - start);
- }
- return new String(mValue, start, end - start);
- }
-
- /**
- */
- @Override
- public String toString()
- {
- return new String(getValue(), 0, length());
- }
-
- public char[] getValue()
- {
- return mValue;
- }
-}
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.myfaces.portlet.faces.util;
+
+/**
+ * A non synchronized StringBuffer object that mimmicks the functionality of java.lang.StringBuffer.
+ */
+public final class SimpleStringBuffer
+{
+ private char mValue[];
+ private int mLength;
+
+ public SimpleStringBuffer()
+ {
+ this(16);
+ }
+
+ public SimpleStringBuffer(int length)
+ {
+ mValue = new char[length];
+ }
+
+ public SimpleStringBuffer(String str)
+ {
+ this(str.length() + 16);
+ append(str);
+ }
+
+ /**
+ * Returns the length (character count) of this string buffer.
+ *
+ * @return the number of characters in this string buffer.
+ */
+ public int length()
+ {
+ return mLength;
+ }
+
+ /**
+ * Returns the current capacity of the String buffer. The capacity is the amount of storage
+ * available for newly inserted characters; beyond which an allocation will occur.
+ *
+ * @return the current capacity of this string buffer.
+ */
+ public int capacity()
+ {
+ return mValue.length;
+ }
+
+ /**
+ * Ensures that the capacity of the buffer is at least equal to the specified minimum. If the
+ * current capacity of this string buffer is less than the argument, then a new internal buffer is
+ * allocated with greater capacity. The new capacity is the larger of:
+ * <ul>
+ * <li>The <code>minimumCapacity</code> argument.
+ * <li>Twice the old capacity, plus <code>2</code>.
+ * </ul>
+ * If the <code>minimumCapacity</code> argument is nonpositive, this method takes no action and
+ * simply returns.
+ *
+ * @param minimumCapacity
+ * the minimum desired capacity.
+ */
+ public void ensureCapacity(int minimumCapacity)
+ {
+ if (minimumCapacity > mValue.length)
+ {
+ int newCapacity = (mValue.length + 1) * 2;
+ if (minimumCapacity > newCapacity)
+ {
+ newCapacity = minimumCapacity;
+ }
+
+ char newValue[] = new char[newCapacity];
+ System.arraycopy(mValue, 0, newValue, 0, mLength);
+ mValue = newValue;
+
+ // Debug Facility that dumps the stack trace when
+ // the buffer grows allowing sizing to be tweaked!
+ // SHOULD BE COMMENTED OUT
+ // printStackTrace(new Throwable());
+ }
+ }
+
+ public void setLength(int newLength)
+ {
+ if (newLength < 0)
+ {
+ throw new StringIndexOutOfBoundsException(newLength);
+ }
+
+ if (newLength > mValue.length)
+ {
+ ensureCapacity(newLength);
+ }
+
+ if (mLength < newLength)
+ {
+ for (; mLength < newLength; mLength++)
+ {
+ mValue[mLength] = '\0';
+ }
+ }
+ else
+ {
+ mLength = newLength;
+ }
+ }
+
+ public char charAt(int index)
+ {
+ if (index < 0 || index >= mLength)
+ {
+ throw new StringIndexOutOfBoundsException(index);
+ }
+ return mValue[index];
+ }
+
+ public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
+ {
+ if (srcBegin < 0 || srcBegin >= mLength)
+ {
+ throw new StringIndexOutOfBoundsException(srcBegin);
+ }
+
+ if (srcEnd < 0 || srcEnd > mLength)
+ {
+ throw new StringIndexOutOfBoundsException(srcEnd);
+ }
+
+ if (srcBegin < srcEnd)
+ {
+ System.arraycopy(mValue, srcBegin, dst, dstBegin, srcEnd - srcBegin);
+ }
+ }
+
+ public void setCharAt(int index, char ch)
+ {
+ if (index < 0 || index >= mLength)
+ {
+ throw new StringIndexOutOfBoundsException(index);
+ }
+ mValue[index] = ch;
+ }
+
+ public SimpleStringBuffer append(Object obj)
+ {
+ return append(String.valueOf(obj));
+ }
+
+ public SimpleStringBuffer append(String str)
+ {
+ if (str == null)
+ {
+ str = String.valueOf(str);
+ }
+
+ int len = str.length();
+ int newcount = mLength + len;
+ if (newcount > mValue.length)
+ {
+ ensureCapacity(newcount);
+ }
+ str.getChars(0, len, mValue, mLength);
+ mLength = newcount;
+ return this;
+ }
+
+ public SimpleStringBuffer append(char[] str)
+ {
+ int len = str.length;
+ int newcount = mLength + len;
+ if (newcount > mValue.length)
+ {
+ ensureCapacity(newcount);
+ }
+ System.arraycopy(str, 0, mValue, mLength, len);
+ mLength = newcount;
+ return this;
+ }
+
+ public SimpleStringBuffer append(char[] str, int offset, int len)
+ {
+ int newcount = mLength + len;
+ if (newcount > mValue.length)
+ {
+ ensureCapacity(newcount);
+ }
+ System.arraycopy(str, offset, mValue, mLength, len);
+ mLength = newcount;
+ return this;
+ }
+
+ public SimpleStringBuffer append(boolean b)
+ {
+ return append(String.valueOf(b));
+ }
+
+ public SimpleStringBuffer append(char c)
+ {
+ int newcount = mLength + 1;
+ if (newcount > mValue.length)
+ {
+ ensureCapacity(newcount);
+ }
+ mValue[mLength++] = c;
+ return this;
+ }
+
+ /**
+ */
+ public SimpleStringBuffer append(int i)
+ {
+ return append(String.valueOf(i));
+ }
+
+ /**
+ */
+ public SimpleStringBuffer append(long l)
+ {
+ return append(String.valueOf(l));
+ }
+
+ /**
+ */
+ public SimpleStringBuffer append(float f)
+ {
+ return append(String.valueOf(f));
+ }
+
+ /**
+ */
+ public SimpleStringBuffer append(double d)
+ {
+ return append(String.valueOf(d));
+ }
+
+ /**
+ */
+ public SimpleStringBuffer insert(int offset, Object obj)
+ {
+ return insert(offset, String.valueOf(obj));
+ }
+
+ /**
+ */
+ public SimpleStringBuffer insert(int offset, String str)
+ {
+ if (offset < 0 || offset > mLength)
+ {
+ throw new StringIndexOutOfBoundsException();
+ }
+ int len = str.length();
+ int newcount = mLength + len;
+ if (newcount > mValue.length)
+ {
+ ensureCapacity(newcount);
+ }
+ System.arraycopy(mValue, offset, mValue, offset + len, mLength - offset);
+ str.getChars(0, len, mValue, offset);
+ mLength = newcount;
+ return this;
+ }
+
+ /**
+ */
+ public SimpleStringBuffer insert(int offset, char[] str)
+ {
+ if (offset < 0 || offset > mLength)
+ {
+ throw new StringIndexOutOfBoundsException();
+ }
+ int len = str.length;
+ int newcount = mLength + len;
+ if (newcount > mValue.length)
+ {
+ ensureCapacity(newcount);
+ }
+ System.arraycopy(mValue, offset, mValue, offset + len, mLength - offset);
+ System.arraycopy(str, 0, mValue, offset, len);
+ mLength = newcount;
+ return this;
+ }
+
+ /**
+ */
+ public SimpleStringBuffer insert(int offset, boolean b)
+ {
+ return insert(offset, String.valueOf(b));
+ }
+
+ /**
+ */
+ public SimpleStringBuffer insert(int offset, char c)
+ {
+ int newcount = mLength + 1;
+ if (newcount > mValue.length)
+ {
+ ensureCapacity(newcount);
+ }
+ System.arraycopy(mValue, offset, mValue, offset + 1, mLength - offset);
+ mValue[offset] = c;
+ mLength = newcount;
+ return this;
+ }
+
+ /**
+ */
+ public SimpleStringBuffer insert(int offset, int i)
+ {
+ return insert(offset, String.valueOf(i));
+ }
+
+ /**
+ */
+ public SimpleStringBuffer insert(int offset, long l)
+ {
+ return insert(offset, String.valueOf(l));
+ }
+
+ /**
+ */
+ public SimpleStringBuffer insert(int offset, float f)
+ {
+ return insert(offset, String.valueOf(f));
+ }
+
+ /**
+ */
+ public SimpleStringBuffer insert(int offset, double d)
+ {
+ return insert(offset, String.valueOf(d));
+ }
+
+ /**
+ * Removes the characters in a substring of this <code>
+ * SimpleStringBuffer</code>. The substring
+ * begins at the specified <code>start</code> and extends to the character at index
+ * <code>end</code> - 1 or to the end of the SimpleStringBuffer if no such character exists. If
+ * start is equal to end, no changes are made.
+ *
+ * @param start -
+ * the beginning index, inclusive
+ * @param end -
+ * the ending index, exclusive
+ *
+ * @return This simple string buffer
+ * @exception StringIndexOutOfBoundsException -
+ * if start is negative, greater than <code>length()</code>, or greater than
+ * <code>end</code>.
+ *
+ */
+ public SimpleStringBuffer delete(int start, int end)
+ {
+ if (start < 0)
+ {
+ throw new StringIndexOutOfBoundsException(start);
+ }
+ if (end > mLength)
+ {
+ end = mLength;
+ }
+ if (start > end)
+ {
+ throw new StringIndexOutOfBoundsException();
+ }
+ int numChars = end - start;
+ if (numChars > 0)
+ {
+ System.arraycopy(mValue, start + numChars, mValue, start, mLength - end);
+ mLength -= numChars;
+ }
+ return this;
+ }
+
+ /**
+ * Removes the character at the specified position in this <code>SimpleStringBuffer</code>
+ * (shortening the <code>SimpleStringBuffer</code> by one character).
+ *
+ * @param index -
+ * index of the character to remove
+ *
+ * @return This simple string buffer
+ * @exception StringIndexOutOfBoundsException -
+ * if the <code>index</code> is negative or greater than or equal to
+ * <code>length()</code>.
+ *
+ */
+ public SimpleStringBuffer deleteCharAt(int index)
+ {
+ if (index < 0 || index >= mLength)
+ {
+ throw new StringIndexOutOfBoundsException();
+ }
+ System.arraycopy(mValue, index + 1, mValue, index, mLength - index - 1);
+ mLength--;
+ return this;
+ }
+
+ /**
+ * Replaces the characters in a substring of this <code>SimpleStringBuffer</code> with
+ * characters in the specified String. The substring begins at the specified start and extends to
+ * the character at index <code>end</code> - 1 or to the end of the
+ * <code>SimpleStringBuffer</code> if no such character exists. First the characters in the
+ * substring are removed and then the specified String is inserted at start. (The
+ * <code>SimpleStringBuffer</code> will be lengthened to accommodate the specified String if
+ * necessary.)
+ *
+ * @param start -
+ * the beginning index, inclusive
+ * @param end -
+ * the ending index, exclusive
+ * @param str -
+ * string that will replace previous contents
+ *
+ * @return This simple string buffer
+ * @exception StringIndexOutOfBoundsException -
+ * if start is negative, greater than <code>length()</code>, or greater than
+ * <code>end</code>.
+ *
+ */
+ public SimpleStringBuffer replace(int start, int end, String str)
+ {
+ if (start < 0)
+ {
+ throw new StringIndexOutOfBoundsException(start);
+ }
+ if (end > mLength)
+ {
+ end = mLength;
+ }
+ if (start > end)
+ {
+ throw new StringIndexOutOfBoundsException();
+ }
+
+ int numChars = str.length();
+ int newLength = mLength + numChars - (end - start);
+
+ if (newLength > mValue.length)
+ {
+ ensureCapacity(newLength);
+ }
+ System.arraycopy(mValue, end, mValue, start + numChars, mLength - end);
+
+ str.getChars(0, numChars, mValue, start);
+ mLength = newLength;
+
+ return this;
+ }
+
+ /**
+ * Returns a new <code>String</code> that contains a subsequence of characters currently
+ * contained in this <code>SimpleStringBuffer</code>.The substring begins at the specified
+ * index and extends to the end of the <code>StringBuffer</code>.
+ *
+ * @param start
+ * The beginning index, inclusive.
+ * @return The new string.
+ * @exception StringIndexOutOfBoundsException
+ * if <code>start</code> is less than zero, or greater than the length of this
+ * <code>StringBuffer</code>.
+ */
+ public String substring(int start)
+ {
+ return substring(start, mLength);
+ }
+
+ /**
+ * Returns a new <code>String</code> that contains a subsequence of characters currently
+ * contained in this <code>SimpleStringBuffer</code>. The substring begins at the specified
+ * <code>start</code> and extends to the character at index <code>end -
+ * 1</code>.
+ *
+ * @param start
+ * The beginning index, inclusive.
+ * @param end
+ * The ending index, exclusive.
+ * @return The new string.
+ * @exception StringIndexOutOfBoundsException
+ * if <code>start</code> or <code>end</code> are negative or greater than
+ * <code>length()</code>, or <code>start</code> is greater than <code>end</code>.
+ */
+ public String substring(int start, int end)
+ {
+ if (start < 0)
+ {
+ throw new StringIndexOutOfBoundsException(start);
+ }
+ if (end > mLength)
+ {
+ throw new StringIndexOutOfBoundsException(end);
+ }
+ if (start > end)
+ {
+ throw new StringIndexOutOfBoundsException(end - start);
+ }
+ return new String(mValue, start, end - start);
+ }
+
+ /**
+ */
+ @Override
+ public String toString()
+ {
+ return new String(getValue(), 0, length());
+ }
+
+ public char[] getValue()
+ {
+ return mValue;
+ }
+}
Modified: myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/TextUtils.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/TextUtils.java?rev=596365&r1=596364&r2=596365&view=diff
==============================================================================
--- myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/TextUtils.java (original)
+++ myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/TextUtils.java Mon Nov 19 08:56:29 2007
@@ -1,102 +1,102 @@
-/* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.myfaces.portlet.faces.util;
-
-import java.text.MessageFormat;
-import java.util.ResourceBundle;
-
-// TODO once we figure out which class is shipped with the 2.0 container
-// we'll be using that class instead
-// Borrowed from oracle.portlet.utils
-
-public class TextUtils
-{
-
- public static final String getString(ResourceBundle bundle, String key, Object[] args)
- {
- return formatMessage(bundle.getString(key), args);
- }
-
- public static final String getString(ResourceBundle bundle, String key)
- {
- return formatMessage(bundle.getString(key), null);
- }
-
- public static final String formatMessage(String message, Object[] args)
- {
- if (args != null)
- {
- return MessageFormat.format(message, args);
- }
- else
- {
- return message;
- }
- }
-
- /**
- * Provides the "global substring search and replace" functionality missing from the JDK.
- *
- * @param orig
- * the original string to process
- * @param search
- * the substring to search for in <code>orig</code>
- * @param replace
- * the string to replace all occurrences of <code>search</code> with
- * @return copy of <code>orig</code> with all occurrences of <code>search</code> replaced by
- * <code>replace</code>
- */
- public static final String globalReplace(String orig, String search, String replace)
- {
- // OPTIMIZATION: Return original string if it doesn't contain the search
- // string
- int searchLen = search.length();
- if (searchLen == 0)
- {
- return orig;
- }
- int nextPos = orig.indexOf(search);
- if (nextPos == -1)
- {
- return orig;
- }
- int origLen = orig.length();
- int startPos = 0;
- SimpleStringBuffer result = new SimpleStringBuffer(origLen + 100);
-
- // Use 'do' loop, because we know the search string occurs at least once
- do
- {
- if (nextPos > startPos)
- {
- result.append(orig.substring(startPos, nextPos));
- }
- result.append(replace);
- startPos = nextPos + searchLen;
- } while (startPos < origLen && (nextPos = orig.indexOf(search, startPos)) != -1);
-
- if (startPos < origLen)
- {
- result.append(orig.substring(startPos));
- }
-
- return result.toString();
- }
-}
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.myfaces.portlet.faces.util;
+
+import java.text.MessageFormat;
+import java.util.ResourceBundle;
+
+// TODO once we figure out which class is shipped with the 2.0 container
+// we'll be using that class instead
+// Borrowed from oracle.portlet.utils
+
+public class TextUtils
+{
+
+ public static final String getString(ResourceBundle bundle, String key, Object[] args)
+ {
+ return formatMessage(bundle.getString(key), args);
+ }
+
+ public static final String getString(ResourceBundle bundle, String key)
+ {
+ return formatMessage(bundle.getString(key), null);
+ }
+
+ public static final String formatMessage(String message, Object[] args)
+ {
+ if (args != null)
+ {
+ return MessageFormat.format(message, args);
+ }
+ else
+ {
+ return message;
+ }
+ }
+
+ /**
+ * Provides the "global substring search and replace" functionality missing from the JDK.
+ *
+ * @param orig
+ * the original string to process
+ * @param search
+ * the substring to search for in <code>orig</code>
+ * @param replace
+ * the string to replace all occurrences of <code>search</code> with
+ * @return copy of <code>orig</code> with all occurrences of <code>search</code> replaced by
+ * <code>replace</code>
+ */
+ public static final String globalReplace(String orig, String search, String replace)
+ {
+ // OPTIMIZATION: Return original string if it doesn't contain the search
+ // string
+ int searchLen = search.length();
+ if (searchLen == 0)
+ {
+ return orig;
+ }
+ int nextPos = orig.indexOf(search);
+ if (nextPos == -1)
+ {
+ return orig;
+ }
+ int origLen = orig.length();
+ int startPos = 0;
+ SimpleStringBuffer result = new SimpleStringBuffer(origLen + 100);
+
+ // Use 'do' loop, because we know the search string occurs at least once
+ do
+ {
+ if (nextPos > startPos)
+ {
+ result.append(orig.substring(startPos, nextPos));
+ }
+ result.append(replace);
+ startPos = nextPos + searchLen;
+ } while (startPos < origLen && (nextPos = orig.indexOf(search, startPos)) != -1);
+
+ if (startPos < origLen)
+ {
+ result.append(orig.substring(startPos));
+ }
+
+ return result.toString();
+ }
+}
Modified: myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/URLUtils.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/URLUtils.java?rev=596365&r1=596364&r2=596365&view=diff
==============================================================================
--- myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/URLUtils.java (original)
+++ myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/URLUtils.java Mon Nov 19 08:56:29 2007
@@ -1,146 +1,146 @@
-/* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.myfaces.portlet.faces.util;
-
-public class URLUtils
-{
-
- /**
- * Borrowed from package oracle.adfinternal.view.faces.share.url.EncoderUtils
- */
- public static String appendURLArguments(StringBuffer buffer, String baseURL,
- String[] keysAndValues)
- {
-
- // Bug 1814825: the anchor has to stay on the end.
- int anchorIndex = baseURL.indexOf('#');
-
- if (anchorIndex >= 0)
- {
- buffer.append(baseURL.substring(0, anchorIndex));
- }
- else
- {
- buffer.append(baseURL);
- }
-
- boolean queryAppended = baseURL.indexOf('?') >= 0;
-
- for (int i = 0; i < keysAndValues.length; i += 2)
- {
- String value = keysAndValues[i + 1];
- if (value != null)
- {
- // only append '?' at start if the URL doesn't already contain
- // arguments
- if (!queryAppended)
- {
- queryAppended = true;
- buffer.append('?');
- }
- else
- {
- buffer.append('&');
- }
-
- buffer.append(keysAndValues[i]);
- buffer.append('=');
- buffer.append(value);
- }
- }
-
- String beforeEncode = buffer.toString();
- return beforeEncode;
- }
-
- /**
- * Borrowed from package oracle.adfinternal.view.faces.share.url.EncoderUtils
- */
- public static String appendURLArguments(String baseURL, String[] keysAndValues)
- {
- // buffer length = base + separators + keys + values
- int bufferLength = baseURL.length() + keysAndValues.length;
- for (int i = 0; i < keysAndValues.length; i += 2)
- {
- String value = keysAndValues[i + 1];
- if (value != null)
- {
- bufferLength += keysAndValues[i].length() + value.length();
- }
- }
-
- StringBuffer buffer = new StringBuffer(bufferLength);
-
- return appendURLArguments(buffer, baseURL, keysAndValues);
- }
-
- public static String convertFromRelative(String currentPath, String relativeLoc)
- throws IllegalArgumentException
- {
- // determine if and how many levels we must walk up the currentPath
- int levels = 0;
- int i = 0, length = relativeLoc.length();
- while (i + 1 < length)
- {
- if (relativeLoc.charAt(i) != '.')
- {
- break;
- }
- else if (relativeLoc.charAt(i) == '.' && relativeLoc.charAt(i + 1) == '/')
- {
- // no new level but prune the ./
- i += 2;
- }
- else if (i + 2 < length && relativeLoc.charAt(i) == '.' && relativeLoc.charAt(i + 1) == '.'
- && relativeLoc.charAt(i + 2) == '/')
- {
- levels += 1;
- i += 3;
- }
- }
-
- StringBuffer sb = new StringBuffer(currentPath);
- if (currentPath.endsWith("/"))
- {
- sb = sb.deleteCharAt(currentPath.length() - 1);
- }
- for (int j = 0; j < levels; j++)
- {
- int loc = sb.lastIndexOf("/");
- if (loc < 0)
- {
- throw new IllegalArgumentException("Location: " + relativeLoc
- + "Can't be made relative to: " + currentPath);
- }
- sb = sb.delete(loc, sb.length());
- }
-
- // now sb should contain root path without trailing / so add one
- sb = sb.append("/");
-
- // now add the portion of the relativeLoc that doesn't contain
- // the relative references
- sb = sb.append(relativeLoc.substring(i));
-
- return sb.toString();
-
- }
-
-}
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.myfaces.portlet.faces.util;
+
+public class URLUtils
+{
+
+ /**
+ * Borrowed from package oracle.adfinternal.view.faces.share.url.EncoderUtils
+ */
+ public static String appendURLArguments(StringBuffer buffer, String baseURL,
+ String[] keysAndValues)
+ {
+
+ // Bug 1814825: the anchor has to stay on the end.
+ int anchorIndex = baseURL.indexOf('#');
+
+ if (anchorIndex >= 0)
+ {
+ buffer.append(baseURL.substring(0, anchorIndex));
+ }
+ else
+ {
+ buffer.append(baseURL);
+ }
+
+ boolean queryAppended = baseURL.indexOf('?') >= 0;
+
+ for (int i = 0; i < keysAndValues.length; i += 2)
+ {
+ String value = keysAndValues[i + 1];
+ if (value != null)
+ {
+ // only append '?' at start if the URL doesn't already contain
+ // arguments
+ if (!queryAppended)
+ {
+ queryAppended = true;
+ buffer.append('?');
+ }
+ else
+ {
+ buffer.append('&');
+ }
+
+ buffer.append(keysAndValues[i]);
+ buffer.append('=');
+ buffer.append(value);
+ }
+ }
+
+ String beforeEncode = buffer.toString();
+ return beforeEncode;
+ }
+
+ /**
+ * Borrowed from package oracle.adfinternal.view.faces.share.url.EncoderUtils
+ */
+ public static String appendURLArguments(String baseURL, String[] keysAndValues)
+ {
+ // buffer length = base + separators + keys + values
+ int bufferLength = baseURL.length() + keysAndValues.length;
+ for (int i = 0; i < keysAndValues.length; i += 2)
+ {
+ String value = keysAndValues[i + 1];
+ if (value != null)
+ {
+ bufferLength += keysAndValues[i].length() + value.length();
+ }
+ }
+
+ StringBuffer buffer = new StringBuffer(bufferLength);
+
+ return appendURLArguments(buffer, baseURL, keysAndValues);
+ }
+
+ public static String convertFromRelative(String currentPath, String relativeLoc)
+ throws IllegalArgumentException
+ {
+ // determine if and how many levels we must walk up the currentPath
+ int levels = 0;
+ int i = 0, length = relativeLoc.length();
+ while (i + 1 < length)
+ {
+ if (relativeLoc.charAt(i) != '.')
+ {
+ break;
+ }
+ else if (relativeLoc.charAt(i) == '.' && relativeLoc.charAt(i + 1) == '/')
+ {
+ // no new level but prune the ./
+ i += 2;
+ }
+ else if (i + 2 < length && relativeLoc.charAt(i) == '.' && relativeLoc.charAt(i + 1) == '.'
+ && relativeLoc.charAt(i + 2) == '/')
+ {
+ levels += 1;
+ i += 3;
+ }
+ }
+
+ StringBuffer sb = new StringBuffer(currentPath);
+ if (currentPath.endsWith("/"))
+ {
+ sb = sb.deleteCharAt(currentPath.length() - 1);
+ }
+ for (int j = 0; j < levels; j++)
+ {
+ int loc = sb.lastIndexOf("/");
+ if (loc < 0)
+ {
+ throw new IllegalArgumentException("Location: " + relativeLoc
+ + "Can't be made relative to: " + currentPath);
+ }
+ sb = sb.delete(loc, sb.length());
+ }
+
+ // now sb should contain root path without trailing / so add one
+ sb = sb.append("/");
+
+ // now add the portion of the relativeLoc that doesn't contain
+ // the relative references
+ sb = sb.append(relativeLoc.substring(i));
+
+ return sb.toString();
+
+ }
+
+}
Modified: myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/LocalesIterator.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/LocalesIterator.java?rev=596365&r1=596364&r2=596365&view=diff
==============================================================================
--- myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/LocalesIterator.java (original)
+++ myfaces/portlet-bridge/trunk/impl/src/main/java/org/apache/myfaces/portlet/faces/util/map/LocalesIterator.java Mon Nov 19 08:56:29 2007
@@ -1,48 +1,48 @@
-/* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.myfaces.portlet.faces.util.map;
-
-import java.util.Enumeration;
-import java.util.Iterator;
-
-public class LocalesIterator implements Iterator
-{
- private Enumeration mLocales;
-
- public LocalesIterator(Enumeration locales)
- {
- mLocales = locales;
- }
-
- public boolean hasNext()
- {
- return mLocales.hasMoreElements();
- }
-
- public Object next()
- {
- return mLocales.nextElement();
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-}
+/* Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.myfaces.portlet.faces.util.map;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+public class LocalesIterator implements Iterator
+{
+ private Enumeration mLocales;
+
+ public LocalesIterator(Enumeration locales)
+ {
+ mLocales = locales;
+ }
+
+ public boolean hasNext()
+ {
+ return mLocales.hasMoreElements();
+ }
+
+ public Object next()
+ {
+ return mLocales.nextElement();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+}