KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > projector > processor > table > TableHandler


1 package org.apache.slide.projector.processor.table;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import org.apache.slide.projector.Context;
7 import org.apache.slide.projector.Processor;
8 import org.apache.slide.projector.Result;
9 import org.apache.slide.projector.Store;
10 import org.apache.slide.projector.URI;
11 import org.apache.slide.projector.descriptor.NumberValueDescriptor;
12 import org.apache.slide.projector.descriptor.ParameterDescriptor;
13 import org.apache.slide.projector.descriptor.ResultDescriptor;
14 import org.apache.slide.projector.descriptor.StateDescriptor;
15 import org.apache.slide.projector.descriptor.StringValueDescriptor;
16 import org.apache.slide.projector.engine.ProcessorManager;
17 import org.apache.slide.projector.i18n.ParameterMessage;
18 import org.apache.slide.projector.util.StoreHelper;
19 import org.apache.slide.projector.value.MapValue;
20 import org.apache.slide.projector.value.NullValue;
21 import org.apache.slide.projector.value.Value;
22
23 /**
24  * @version $Revision: 1.4 $
25  */

26
27 public class TableHandler implements Processor {
28     final static String JavaDoc URL = "tableHandler";
29
30     final static String JavaDoc OK = "id";
31
32     final static String JavaDoc ID = "id";
33     final static String JavaDoc STORE = "store";
34     final static String JavaDoc TARGET_POSITION = "targetPosition";
35     final static String JavaDoc CURRENT_POSITION = "currentPosition";
36     final static String JavaDoc SORTED_BY= "sortedBy";
37     final static String JavaDoc ORDER= "order";
38     final static String JavaDoc SIZE= "size";
39     final static String JavaDoc EXPAND = "expand";
40     final static String JavaDoc EXPANDED = "expanded";
41     final static String JavaDoc COLLAPSE = "collapse";
42     final static String JavaDoc COLLAPSED = "collapsed";
43
44     final static String JavaDoc ASCENDING= "ascending";
45     final static String JavaDoc DESCENDING= "descending";
46
47     final static ParameterDescriptor[] parameterDescirptors = new ParameterDescriptor[] {
48         new ParameterDescriptor(ID, new ParameterMessage("tableHandler/id"), new StringValueDescriptor()),
49         new ParameterDescriptor(TARGET_POSITION, new ParameterMessage("tableHandler/targetPosition"), new NumberValueDescriptor(), NullValue.NULL),
50         new ParameterDescriptor(SORTED_BY, new ParameterMessage("tableHandler/sortedBy"), new StringValueDescriptor(), NullValue.NULL),
51         new ParameterDescriptor(ORDER, new ParameterMessage("tableHandler/order"), new StringValueDescriptor(new String JavaDoc[] {ASCENDING, DESCENDING}), NullValue.NULL),
52         new ParameterDescriptor(STORE, new ParameterMessage("tableHandler/store"), new StringValueDescriptor(Store.stores)),
53         new ParameterDescriptor(EXPAND, new ParameterMessage("tableHandler/expand"), new StringValueDescriptor(), NullValue.NULL),
54         new ParameterDescriptor(COLLAPSE, new ParameterMessage("tableHandler/collapse"), new StringValueDescriptor(), NullValue.NULL)
55     };
56
57     public Result process(Map JavaDoc parameter, Context context) throws Exception JavaDoc {
58         String JavaDoc id = parameter.get(ID).toString();
59         Store store = context.getStore(StoreHelper.getStoreByName(parameter.get(STORE).toString()));
60         MapValue idResource = (MapValue)store.get(id);
61         Value targetPosition = (Value)parameter.get(TARGET_POSITION);
62         Value sortedBy = (Value)parameter.get(SORTED_BY);
63         Value order = (Value)parameter.get(ORDER);
64         Value expand = (Value)parameter.get(EXPAND);
65         Value collapse = (Value)parameter.get(COLLAPSE);
66         Map JavaDoc tableMap;
67         if ( idResource == null) {
68             tableMap = new HashMap JavaDoc();
69             idResource = new MapValue(tableMap);
70             store.put(id, idResource);
71         } else {
72             tableMap = idResource.getMap();
73         }
74         if ( targetPosition != NullValue.NULL ) {
75             tableMap.put(CURRENT_POSITION, targetPosition);
76         }
77         if ( sortedBy != NullValue.NULL ) {
78             tableMap.put(SORTED_BY, sortedBy);
79         }
80         if ( order != NullValue.NULL ) {
81             tableMap.put(ORDER, order);
82         }
83         if ( collapse != NullValue.NULL || expand != NullValue.NULL ) {
84             MapValue sizeValue = (MapValue)tableMap.get(SIZE);
85             Map JavaDoc size;
86             if ( sizeValue == null ) {
87                 size = new HashMap JavaDoc();
88                 tableMap.put(SIZE, new MapValue(size));
89             } else {
90                 size = sizeValue.getMap();
91             }
92             if ( collapse != NullValue.NULL ) {
93                 size.put(collapse.toString(), COLLAPSED);
94             }
95             if ( expand != NullValue.NULL ) {
96                 size.put(expand.toString(), EXPANDED);
97             }
98         }
99         URI bookmark = (URI)context.getBookmark();
100         if ( bookmark != null ) {
101             return ProcessorManager.getInstance().process(bookmark, parameter, context);
102         } else {
103             return Result.OK;
104         }
105     }
106
107     public ParameterDescriptor[] getParameterDescriptors() {
108         return parameterDescirptors;
109     }
110
111     public ResultDescriptor getResultDescriptor() {
112         return new ResultDescriptor(new StateDescriptor[] { StateDescriptor.OK_DESCRIPTOR });
113     }
114 }
Popular Tags