Assembla home | Assembla project page
 

Changeset 158

Show
Ignore:
Timestamp:
08/16/08 18:21:23 (3 months ago)
Author:
restamon
Message:

Data picker enhancements

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • core/trunk/src/main/java/org/restafarian/core/servlets/SelectListServletBase.java

    r7 r158  
    2929 */ 
    3030public abstract class SelectListServletBase extends RestServletBase { 
     31        private static final String FIELD_MAP_REQ_ATTR_KEY = "select.list.data.field.map"; 
    3132        private String contextKey = ""; 
    3233        private String dataSourceName = ""; 
     
    4748                StringBuffer buffer = new StringBuffer(); 
    4849 
     50                req.setAttribute(FIELD_MAP_REQ_ATTR_KEY, getCurrentDataFields(req)); 
    4951                buffer.append("<?xml version=\"1.0\"?>\n"); 
    5052                buffer.append("<options size=\""); 
     
    100102 
    101103        /** 
     104         * <p>This method returns the current map of data fields.</p> 
     105         * 
     106         * @param req the <code>HttpServletRequest</code> object 
     107         * @return the current map of data fields 
     108         */ 
     109        protected Map getCurrentDataFields(HttpServletRequest req) { 
     110                return dataFields; 
     111        } 
     112 
     113        /** 
    102114         * <p>This method formats the options.</p> 
    103115         * 
     
    130142                } 
    131143 
     144                Map fields = (Map) req.getAttribute(FIELD_MAP_REQ_ATTR_KEY); 
    132145                for (int x=startIndex; x<endIndex; x++) { 
    133146                        int index = x + 1; 
     
    136149                        buffer.append(index); 
    137150                        buffer.append("\">\n"); 
    138                         Iterator i = dataFields.keySet().iterator(); 
     151                        Iterator i = fields.keySet().iterator(); 
    139152                        while (i.hasNext()) { 
    140153                                String fieldName = (String) i.next(); 
     
    183196                        results.put("accessCount", new Integer(accessCount.intValue() + 1)); 
    184197                } else { 
    185                         options = fetchOptions(startsWith, contains, orderBy); 
     198                        options = fetchOptions(req, startsWith, contains, orderBy); 
    186199                        if (options != null && options.size() > 0) { 
    187200                                Map results = new HashMap(); 
     
    210223         * <p>This method obtains the requested options from the data source.</p> 
    211224         * 
     225         * @param req the <code>HttpServletRequest</code> object 
    212226         * @param startsWith the "starts with" query parameter 
    213227         * @param contains the "contains" query parameter 
     
    215229         * @return the options 
    216230         */ 
    217         protected List fetchOptions(String startsWith, String contains, String orderBy) {  
     231        protected List fetchOptions(HttpServletRequest req, String startsWith, String contains, String orderBy) {  
    218232                List options = new ArrayList(); 
    219233 
     
    222236                Statement stmt = null; 
    223237                ResultSet rs = null; 
    224                 String qs = getQueryStatement(startsWith, contains, orderBy); 
     238                String qs = getQueryStatement(req, startsWith, contains, orderBy); 
    225239                Map items = new TreeMap(); 
     240                Map fields = (Map) req.getAttribute(FIELD_MAP_REQ_ATTR_KEY); 
    226241                try { 
    227242                        conn = dataSource.getConnection(); 
     
    231246                        while (rs.next()) { 
    232247                                Map thisItem = new HashMap(); 
    233                                 Iterator i = dataFields.keySet().iterator(); 
     248                                Iterator i = fields.keySet().iterator(); 
    234249                                while (i.hasNext()) { 
    235250                                        String fieldName = (String) i.next(); 
    236                                         String tableField = (String) dataFields.get(fieldName); 
     251                                        String tableField = (String) fields.get(fieldName); 
    237252                                        thisItem.put(fieldName, filter(rs.getString(tableField))); 
    238253                                } 
     
    294309         * <p>This method creates the SQL statement.</p> 
    295310         * 
     311         * @param req the <code>HttpServletRequest</code> object 
     312         * @param startsWith the "starts with" query parameter 
     313         * @param contains the "contains" query parameter 
     314         * @param orderBy the sort order 
     315         * @return the SQL statement 
     316         */ 
     317        protected String getQueryStatement(HttpServletRequest req, String startsWith, String contains, String orderBy) { 
     318                return getQueryStatement(startsWith, contains, orderBy); 
     319        } 
     320 
     321        /** 
     322         * <p>This method creates the SQL statement.</p> 
     323         * 
    296324         * @param startsWith the "starts with" query parameter 
    297325         * @param contains the "contains" query parameter 
     
    383411         * @return Returns the contextKey. 
    384412         */ 
    385         protected String getContextKey() { 
     413        public String getContextKey() { 
    386414                return contextKey; 
    387415        } 
     
    389417         * @param contextKey The contextKey to set. 
    390418         */ 
    391         protected void setContextKey(String contextKey) { 
     419        public void setContextKey(String contextKey) { 
    392420                this.contextKey = contextKey; 
    393421        } 
     
    395423         * @return Returns the dataFields. 
    396424         */ 
    397         protected Map getDataFields() { 
     425        public Map getDataFields() { 
    398426                return dataFields; 
    399427        } 
     
    401429         * @param dataFields The dataFields to set. 
    402430         */ 
    403         protected void setDataFields(Map dataFields) { 
     431        public void setDataFields(Map dataFields) { 
    404432                this.dataFields = dataFields; 
    405433        } 
     
    407435         * @return Returns the dataSourceName. 
    408436         */ 
    409         protected String getDataSourceName() { 
     437        public String getDataSourceName() { 
    410438                return dataSourceName; 
    411439        } 
     
    413441         * @param dataSourceName The dataSourceName to set. 
    414442         */ 
    415         protected void setDataSourceName(String dataSourceName) { 
     443        public void setDataSourceName(String dataSourceName) { 
    416444                this.dataSourceName = dataSourceName; 
    417445        } 
     
    419447         * @return Returns the defaultContains. 
    420448         */ 
    421         protected String getDefaultContains() { 
     449        public String getDefaultContains() { 
    422450                return defaultContains; 
    423451        } 
     
    425453         * @param defaultContains The defaultContains to set. 
    426454         */ 
    427         protected void setDefaultContains(String defaultContains) { 
     455        public void setDefaultContains(String defaultContains) { 
    428456                this.defaultContains = defaultContains; 
    429457        } 
     
    431459         * @return Returns the defaultOrderBy. 
    432460         */ 
    433         protected String getDefaultOrderBy() { 
     461        public String getDefaultOrderBy() { 
    434462                return defaultOrderBy; 
    435463        } 
     
    437465         * @param defaultOrderBy The defaultOrderBy to set. 
    438466         */ 
    439         protected void setDefaultOrderBy(String defaultOrderBy) { 
     467        public void setDefaultOrderBy(String defaultOrderBy) { 
    440468                this.defaultOrderBy = defaultOrderBy; 
    441469        } 
     
    443471         * @return Returns the defaultStartsWith. 
    444472         */ 
    445         protected String getDefaultStartsWith() { 
     473        public String getDefaultStartsWith() { 
    446474                return defaultStartsWith; 
    447475        } 
     
    449477         * @param defaultStartsWith The defaultStartsWith to set. 
    450478         */ 
    451         protected void setDefaultStartsWith(String defaultStartsWith) { 
     479        public void setDefaultStartsWith(String defaultStartsWith) { 
    452480                this.defaultStartsWith = defaultStartsWith; 
    453481        }