Author: siren
Date: Tue May  2 11:34:06 2006
New Revision: 399007

URL: http://svn.apache.org/viewcvs?rev=399007&view=rev
Log:
add simple preferences page, fixes for parsing and storing preferences

Modified:
    
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Preferences.java

Modified: 
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Preferences.java
URL: 
http://svn.apache.org/viewcvs/lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Preferences.java?rev=399007&r1=399006&r2=399007&view=diff
==============================================================================
--- 
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Preferences.java
 (original)
+++ 
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Preferences.java
 Tue May  2 11:34:06 2006
@@ -15,6 +15,9 @@
  */
 package org.apache.nutch.webapp.common;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
 import java.util.HashMap;
 import java.util.Locale;
 
@@ -22,6 +25,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.nutch.html.Entities;
+
 /**
  * Preferences represents (extendable) configuration object that is persistable
  * into user browser (as cookie)
@@ -39,6 +44,9 @@
   public static final String KEY_HITS_PER_DUP = "S";
 
   public static final String KEY_DUP_FIELD = "D";
+  
+  static final String KEYVALSEPARATOR="_";
+  static final String VALVALSEPARATOR="-";
 
   // Name of web ui cookie that stores users cutomized user preferences
   public static String COOKIE_NAME = "NUTCH";
@@ -60,7 +68,7 @@
    */
   public Locale getLocale(HttpServletRequest request) {
     if (containsKey(KEY_LOCALE))
-      return new Locale((String) defaults.get(KEY_LOCALE));
+      return new Locale((String) get(KEY_LOCALE));
     else
       return request.getLocale();
   }
@@ -68,8 +76,10 @@
   public static void setPreferencesCookie(HttpServletRequest request,
       HttpServletResponse response, Preferences prefs) {
     if (defaults.equals(prefs)) {
+      System.out.println("default qeuals prefs, removing");
       removeCookie(response);
     } else {
+      System.out.println("setting preferences to cookie");
       setPreferencesCookie(response, prefs);
     }
   }
@@ -107,19 +117,30 @@
   }
 
   public static Preferences parse(String data) {
+    return parse(data,VALVALSEPARATOR, KEYVALSEPARATOR);
+  }
+
+  public static Preferences parse(String data, String valueValueSeparator, 
String keyValueSeparator) {
+
+    System.out.println("data:" + data);
     Preferences p = new Preferences();
     p.putAll(defaults);
-    String[] dataitems = data.split(",");
+    String[] dataitems = data.split(valueValueSeparator);
+    System.out.println(dataitems.length + " dataitems submitted");
     for (int i = 0; i < dataitems.length; i++) {
-      String keyvalue[] = dataitems[0].split("=");
+      String keyvalue[] = dataitems[i].split(keyValueSeparator);
       if (keyvalue.length == 2) {
-        p.put(keyvalue[0], keyvalue[1]);
-        break;
+        try {
+          System.out.println("adding:" +  keyvalue[0] + "=" + keyvalue[1]);
+          p.put(keyvalue[0], URLDecoder.decode((String)keyvalue[1],"UTF-8"));
+        } catch (UnsupportedEncodingException e) {
+          e.printStackTrace();
+        }
       }
     }
     return p;
   }
-
+  
   public int getInt(String name, int defaultVal) {
     try {
       return get(name) == null ? defaultVal : Integer
@@ -142,11 +163,17 @@
     Object[] keys = keySet().toArray();
 
     for (int i = 0; i < keys.length; i++) {
-      txt.append(keys[i].toString()).append("=").append(get(keys[i]));
+      try {
+        
txt.append(keys[i].toString()).append(KEYVALSEPARATOR).append(URLEncoder.encode((String)get(keys[i]),"UTF-8"));
+      } catch (UnsupportedEncodingException e) {
+        e.printStackTrace();
+      }
       if (i < keys.length - 1)
-        txt.append(",");
+        txt.append(VALVALSEPARATOR);
     }
 
+    System.out.println("toString():" + txt.toString());
+    
     return txt.toString();
   }
 




-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Nutch-cvs mailing list
Nutch-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nutch-cvs

Reply via email to