001package net.sf.jkniv.whinstone.couchdb.statement; 002 003import java.io.UnsupportedEncodingException; 004import java.net.URLEncoder; 005 006public class QueryParam 007{ 008 private String name; 009 private boolean quote; 010 011 public QueryParam(String name) 012 { 013 this(name, false); 014 } 015 016 public QueryParam(String name, boolean quote) 017 { 018 this.name = name; 019 this.quote = quote; 020 } 021 022 public String name() 023 { 024 return name; 025 } 026 027 public String getValue(Object v) 028 { 029 if (quote) 030 return encode("\"" +v.toString()+ "\"") ; 031 032 return v.toString(); 033 } 034 035 private String encode(String v) 036 { 037 try 038 { 039 return URLEncoder.encode(v,"UTF-8"); 040 } 041 catch (UnsupportedEncodingException e) 042 { 043 // TODO Auto-generated catch block 044 e.printStackTrace(); 045 } 046 return null; 047 } 048 049}