You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/05/29 19:34:10 UTC
svn commit: r780041 - in /incubator/pivot/trunk/web:
src/pivot/web/Query.java src/pivot/web/QueryDictionary.java
src/pivot/web/server/QueryServlet.java
test/pivot/web/test/QueryDictionaryTest.java
test/pivot/web/test/WebQueryTestClient.java
Author: tvolkert
Date: Fri May 29 17:34:09 2009
New Revision: 780041
URL: http://svn.apache.org/viewvc?rev=780041&view=rev
Log:
Separated QueryDictionary out into its own file
Added:
incubator/pivot/trunk/web/src/pivot/web/QueryDictionary.java
Modified:
incubator/pivot/trunk/web/src/pivot/web/Query.java
incubator/pivot/trunk/web/src/pivot/web/server/QueryServlet.java
incubator/pivot/trunk/web/test/pivot/web/test/QueryDictionaryTest.java
incubator/pivot/trunk/web/test/pivot/web/test/WebQueryTestClient.java
Modified: incubator/pivot/trunk/web/src/pivot/web/Query.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/src/pivot/web/Query.java?rev=780041&r1=780040&r2=780041&view=diff
==============================================================================
--- incubator/pivot/trunk/web/src/pivot/web/Query.java (original)
+++ incubator/pivot/trunk/web/src/pivot/web/Query.java Fri May 29 17:34:09 2009
@@ -97,108 +97,6 @@
}
/**
- * Represents a collection of keyed data associated with a query. Allows
- * multiple values to be set against a given key.
- *
- * @author brindy
- */
- public static final class QueryDictionary implements Dictionary<String, String>,
- Iterable<String> {
- private HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
-
- public String get(String key) {
- ArrayList<String> list = map.get(key);
- if (list != null && list.getLength() > 0) {
- return list.get(0);
- }
- return null;
- }
-
- public String get(String key, int index) {
- ArrayList<String> list = map.get(key);
- if (list == null || list.getLength() <= index) {
- throw new IndexOutOfBoundsException();
- }
- return list.get(index);
- }
-
- public String put(String key, String value) {
- ArrayList<String> list = new ArrayList<String>();
- list.add(value);
-
- ArrayList<String> previous = map.put(key, list);
- if (previous != null && previous.getLength() > 0) {
- return previous.get(0);
- }
-
- return null;
- }
-
- public int add(String key, String value) {
- ArrayList<String> list = map.get(key);
- if (list == null) {
- put(key, value);
- return 0;
- }
-
- list.add(value);
- return list.getLength() - 1;
- }
-
- public void insert(String key, String value, int index) {
- ArrayList<String> list = map.get(key);
-
- // e.g if index = 0 and length = 0, throw an exception
- if (list == null || list.getLength() <= index) {
- throw new IndexOutOfBoundsException();
- }
-
- list.insert(value, index);
- }
-
- public String remove(String key) {
- ArrayList<String> list = map.remove(key);
- if (list != null && list.getLength() > 0) {
- return list.get(0);
- }
-
- return null;
- }
-
- public String remove(String key, int index) {
- ArrayList<String> list = map.get(key);
- if (list == null || list.getLength() <= index) {
- throw new IndexOutOfBoundsException();
- }
- return list.get(index);
- }
-
- public void clear() {
- map.clear();
- }
-
- public boolean containsKey(String key) {
- return map.containsKey(key);
- }
-
- public boolean isEmpty() {
- return map.isEmpty();
- }
-
- public int getLength(String key) {
- ArrayList<String> list = map.get(key);
- if (list == null) {
- return 0;
- }
- return list.getLength();
- }
-
- public Iterator<String> iterator() {
- return map.iterator();
- }
- }
-
- /**
* Query listener list.
*
* @author tvolkert
Added: incubator/pivot/trunk/web/src/pivot/web/QueryDictionary.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/src/pivot/web/QueryDictionary.java?rev=780041&view=auto
==============================================================================
--- incubator/pivot/trunk/web/src/pivot/web/QueryDictionary.java (added)
+++ incubator/pivot/trunk/web/src/pivot/web/QueryDictionary.java Fri May 29 17:34:09 2009
@@ -0,0 +1,124 @@
+/*
+ * 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 pivot.web;
+
+import java.util.Iterator;
+
+import pivot.collections.ArrayList;
+import pivot.collections.Dictionary;
+import pivot.collections.HashMap;
+
+/**
+ * Represents a collection of keyed data associated with a query. Allows
+ * multiple values to be set against a given key.
+ *
+ * @author brindy
+ */
+public final class QueryDictionary implements Dictionary<String, String>, Iterable<String> {
+ private HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
+
+ public String get(String key) {
+ ArrayList<String> list = map.get(key);
+ if (list != null && list.getLength() > 0) {
+ return list.get(0);
+ }
+ return null;
+ }
+
+ public String get(String key, int index) {
+ ArrayList<String> list = map.get(key);
+ if (list == null || list.getLength() <= index) {
+ throw new IndexOutOfBoundsException();
+ }
+ return list.get(index);
+ }
+
+ public String put(String key, String value) {
+ ArrayList<String> list = new ArrayList<String>();
+ list.add(value);
+
+ ArrayList<String> previous = map.put(key, list);
+ if (previous != null && previous.getLength() > 0) {
+ return previous.get(0);
+ }
+
+ return null;
+ }
+
+ public int add(String key, String value) {
+ ArrayList<String> list = map.get(key);
+ if (list == null) {
+ put(key, value);
+ return 0;
+ }
+
+ list.add(value);
+ return list.getLength() - 1;
+ }
+
+ public void insert(String key, String value, int index) {
+ ArrayList<String> list = map.get(key);
+
+ // e.g if index = 0 and length = 0, throw an exception
+ if (list == null || list.getLength() <= index) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ list.insert(value, index);
+ }
+
+ public String remove(String key) {
+ ArrayList<String> list = map.remove(key);
+ if (list != null && list.getLength() > 0) {
+ return list.get(0);
+ }
+
+ return null;
+ }
+
+ public String remove(String key, int index) {
+ ArrayList<String> list = map.get(key);
+ if (list == null || list.getLength() <= index) {
+ throw new IndexOutOfBoundsException();
+ }
+ return list.get(index);
+ }
+
+ public void clear() {
+ map.clear();
+ }
+
+ public boolean containsKey(String key) {
+ return map.containsKey(key);
+ }
+
+ public boolean isEmpty() {
+ return map.isEmpty();
+ }
+
+ public int getLength(String key) {
+ ArrayList<String> list = map.get(key);
+ if (list == null) {
+ return 0;
+ }
+ return list.getLength();
+ }
+
+ public Iterator<String> iterator() {
+ return map.iterator();
+ }
+}
Modified: incubator/pivot/trunk/web/src/pivot/web/server/QueryServlet.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/src/pivot/web/server/QueryServlet.java?rev=780041&r1=780040&r2=780041&view=diff
==============================================================================
--- incubator/pivot/trunk/web/src/pivot/web/server/QueryServlet.java (original)
+++ incubator/pivot/trunk/web/src/pivot/web/server/QueryServlet.java Fri May 29 17:34:09 2009
@@ -36,7 +36,7 @@
import pivot.serialization.SerializationException;
import pivot.serialization.Serializer;
import pivot.util.Base64;
-import pivot.web.Query;
+import pivot.web.QueryDictionary;
/**
* Abstract base class for web query servlets. It is the server counterpart to
@@ -99,9 +99,9 @@
private boolean determineContentLength = false;
- private Query.QueryDictionary parameters = new Query.QueryDictionary();
- private Query.QueryDictionary requestHeaders = new Query.QueryDictionary();
- private Query.QueryDictionary responseHeaders = new Query.QueryDictionary();
+ private QueryDictionary parameters = new QueryDictionary();
+ private QueryDictionary requestHeaders = new QueryDictionary();
+ private QueryDictionary responseHeaders = new QueryDictionary();
private Serializer<?> serializer = new JSONSerializer();
@@ -225,7 +225,7 @@
* Returns the servlet's parameter dictionary, which holds the values
* passed in the HTTP request query string.
*/
- public Query.QueryDictionary getParameters() {
+ public QueryDictionary getParameters() {
return parameters;
}
@@ -233,7 +233,7 @@
* Returns the servlet's request header dictionary, which holds the HTTP
* request headers.
*/
- public Query.QueryDictionary getRequestHeaders() {
+ public QueryDictionary getRequestHeaders() {
return requestHeaders;
}
@@ -241,7 +241,7 @@
* Returns the servlet's response header dictionary, which holds the HTTP
* response headers that will be sent back to the client.
*/
- public Query.QueryDictionary getResponseHeaders() {
+ public QueryDictionary getResponseHeaders() {
return responseHeaders;
}
Modified: incubator/pivot/trunk/web/test/pivot/web/test/QueryDictionaryTest.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/test/pivot/web/test/QueryDictionaryTest.java?rev=780041&r1=780040&r2=780041&view=diff
==============================================================================
--- incubator/pivot/trunk/web/test/pivot/web/test/QueryDictionaryTest.java (original)
+++ incubator/pivot/trunk/web/test/pivot/web/test/QueryDictionaryTest.java Fri May 29 17:34:09 2009
@@ -21,12 +21,12 @@
import junit.framework.TestCase;
import pivot.web.Query;
-import pivot.web.Query.QueryDictionary;
+import pivot.web.QueryDictionary;
public class QueryDictionaryTest extends TestCase {
public void testQueryDictionary() {
- QueryDictionary dict = new Query.QueryDictionary();
+ QueryDictionary dict = new QueryDictionary();
assertNull(dict.get("key"));
Modified: incubator/pivot/trunk/web/test/pivot/web/test/WebQueryTestClient.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/web/test/pivot/web/test/WebQueryTestClient.java?rev=780041&r1=780040&r2=780041&view=diff
==============================================================================
--- incubator/pivot/trunk/web/test/pivot/web/test/WebQueryTestClient.java (original)
+++ incubator/pivot/trunk/web/test/pivot/web/test/WebQueryTestClient.java Fri May 29 17:34:09 2009
@@ -28,7 +28,7 @@
import pivot.web.DeleteQuery;
import pivot.web.PostQuery;
import pivot.web.PutQuery;
-import pivot.web.Query.QueryDictionary;
+import pivot.web.QueryDictionary;
public class WebQueryTestClient {
final static boolean useProxy = true;