dflorey     2004/06/21 09:00:25

  Modified:    proposals/projector/src/java/org/apache/slide/projector/processor/table
                        TablePager.java TableGenerator.java
                        TableHandler.java TableMapRenderer.java
               proposals/projector/src/java/org/apache/slide/projector/value
                        ObjectValue.java LocaleValue.java StringValue.java
               
proposals/projector/src/java/org/apache/slide/projector/processor/process
                        ParameterConfiguration.java
               proposals/projector/src/java/org/apache/slide/projector/processor/query
                        ResultResolver.java
  Log:
  Improved table handling (column based table generation & ordering)
  
  Revision  Changes    Path
  1.7       +5 -7      
jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/table/TablePager.java
  
  Index: TablePager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/table/TablePager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TablePager.java   17 Jun 2004 14:54:56 -0000      1.6
  +++ TablePager.java   21 Jun 2004 16:00:25 -0000      1.7
  @@ -20,10 +20,11 @@
    * @version $Revision$
    */
   public class TablePager extends TemplateRenderer {
  -    public final static String SHOW_RANGE = "showRange";
  +     public final static String SHOW_RANGE = "showRange";
       public final static String RANGE = "range";
       public final static String PARAMETER = "parameter";
   
  +    final private static String HANDLER = "handler";
       public final static String TOTAL_PAGES = "totalPages";
       public final static String CURRENT_PAGE = "currentPage";
       public final static String FIRST_ITEM = "firstItem";
  @@ -32,9 +33,6 @@
   
       public final static String FAILED = "failed";
   
  -    protected final static String HANDLER = "tableHandler";
  -    protected final static String HANDLER_URL = "handler";
  -
       protected final static String PRE_FRAGMENT = "pre";
       protected final static String POST_FRAGMENT = "post";
       protected final static String FIRST_FRAGMENT = "first";
  @@ -68,7 +66,7 @@
           Map parameter = ((MapValue)parameters.get(PARAMETER)).getMap();
           boolean showRange = 
((BooleanValue)parameters.get(SHOW_RANGE)).booleanValue();
           int range = ((NumberValue)parameters.get(RANGE)).getNumber().intValue();
  -        String handlerUrl = 
ProcessorManager.getInstance().process(ProcessorManager.URL, HANDLER, 
context).toString();
  +        String handlerUrl = 
ProcessorManager.getInstance().process(ProcessorManager.URL, TableHandler.URL, 
context).toString();
           String id = parameters.get(TableHandler.ID).toString();
           String storeName = parameters.get(TableHandler.STORE).toString();
           Store store = context.getStore(StoreHelper.getStoreByName(storeName));
  @@ -177,7 +175,7 @@
                }
                
           }
  -        parameters.put(HANDLER_URL, new StringValue(handlerBuffer.toString()));
  +        parameters.put(HANDLER, new StringValue(handlerBuffer.toString()));
           parameters.put(FIRST_ITEM, new NumberValue(new Integer(i+1)));
           parameters.put(LAST_ITEM, new NumberValue(new Integer(lastItem)));
       }
  
  
  
  1.4       +131 -100  
jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/table/TableGenerator.java
  
  Index: TableGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/table/TableGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TableGenerator.java       17 Jun 2004 14:54:56 -0000      1.3
  +++ TableGenerator.java       21 Jun 2004 16:00:25 -0000      1.4
  @@ -1,19 +1,29 @@
   package org.apache.slide.projector.processor.table;
   
  +import org.apache.slide.projector.descriptor.ArrayValueDescriptor;
  +import org.apache.slide.projector.descriptor.BooleanValueDescriptor;
  +import org.apache.slide.projector.descriptor.MapValueDescriptor;
   import org.apache.slide.projector.descriptor.ParameterDescriptor;
  -import org.apache.slide.projector.descriptor.NumberValueDescriptor;
  +import org.apache.slide.projector.descriptor.StringValueDescriptor;
  +import org.apache.slide.projector.engine.ProcessorManager;
  +import org.apache.slide.projector.util.StoreHelper;
   import org.apache.slide.projector.value.*;
   import org.apache.slide.projector.ConfigurationException;
   import org.apache.slide.projector.ProcessException;
   import org.apache.slide.projector.Result;
   import org.apache.slide.projector.Context;
  -import org.apache.slide.projector.processor.TemplateMapRenderer;
  +import org.apache.slide.projector.Store;
   import org.apache.slide.projector.processor.SimpleProcessor;
   import org.apache.slide.projector.i18n.ParameterMessage;
   import org.apache.slide.projector.i18n.ErrorMessage;
   
  -import java.util.Map;
  +import java.io.IOException;
  +import java.util.ArrayList;
  +import java.util.Arrays;
  +import java.util.Comparator;
   import java.util.Iterator;
  +import java.util.List;
  +import java.util.Map;
   import java.util.HashMap;
   
   /**
  @@ -22,66 +32,62 @@
    */
   
   public class TableGenerator extends TableMapRenderer {
  -    final private static String HEADER_FRAGMENT = "header";
  -    final private static String FOOTER_FRAGMENT = "footer";
  -    final private static String FIRST_FRAGMENT = "first";
  -    final private static String LAST_FRAGMENT = "last";
  -    final private static String EVEN_FRAGMENT = "even";
  -    final private static String DEFAULT_FRAGMENT = "default";
  -    final private static String EMPTY_FRAGMENT = "empty";
  +    final static String PARAMETER = "parameter";
  +
       final private static String COLUMN_FRAGMENT = "column";
       final private static String HEADER_COLUMN_FRAGMENT = "header column";
  -
  +    final private static String SORTABLE_HEADER_COLUMN_FRAGMENT = "sortable header 
column";
  +    final private static String ASCENDING_HEADER_COLUMN_FRAGMENT = "ascending 
header column";
  +    final private static String DESCENDING_HEADER_COLUMN_FRAGMENT = "descending 
header column";
  +    final private static String RESIZABLE_HEADER_COLUMN_FRAGMENT = "resizable 
header column";
  +
  +    final private static String COLUMNS_PARAMETER = "columns";
  +    final private static String RESIZABLE = "resizable";
  +    final private static String SORTABLE = "sortable";
  +    final private static String HEADER = "header";
  +    final private static String KEY = "key";
  +    
       final private static String HEADERS = "headers";
       final private static String COLUMNS = "columns";
   
       final private static String VALUE = "value";
  +    final private static String HANDLER = "handler";
   
  -    final private static String OFFSET = "offset";
  -    final private static String LENGTH = "length";
  -
  -    private Template headerTemplate;
  -    private Template footerTemplate;
  -    private Template firstTemplate;
  -    private Template lastTemplate;
  -    private Template evenTemplate;
  -    private Template defaultTemplate;
  -    private Template emptyTemplate;
  -    private Template columnTemplate;
  -    private Template headerColumnTemplate;
  -
  +    private Template columnTemplate, headerColumnTemplate;
  +     private Template resizableHeaderColumnTemplate, sortableHeaderColumnTemplate;
  +     private Template ascendingHeaderColumnTemplate, descendingHeaderColumnTemplate;
  +     
       private ParameterDescriptor []parameterDescriptors;
   
       public TableGenerator() {
           setRequiredFragments(new String[] { DEFAULT_FRAGMENT, COLUMN_FRAGMENT, 
HEADER_COLUMN_FRAGMENT });
  -        setOptionalFragments(new String[] { EMPTY_FRAGMENT, HEADER_FRAGMENT, 
FOOTER_FRAGMENT, FIRST_FRAGMENT, LAST_FRAGMENT, EVEN_FRAGMENT });
  +        setOptionalFragments(new String[] { RESIZABLE_HEADER_COLUMN_FRAGMENT, 
SORTABLE_HEADER_COLUMN_FRAGMENT, ASCENDING_HEADER_COLUMN_FRAGMENT, 
DESCENDING_HEADER_COLUMN_FRAGMENT, EMPTY_FRAGMENT, HEADER_FRAGMENT, FOOTER_FRAGMENT, 
FIRST_FRAGMENT, LAST_FRAGMENT, EVEN_FRAGMENT });
           setRepeatedFragments(new String[] { FIRST_FRAGMENT, LAST_FRAGMENT, 
DEFAULT_FRAGMENT, EVEN_FRAGMENT });
       }
   
       public void configure(StreamableValue config) throws ConfigurationException {
  -        super.configure(config);
  +        super.configure(config); 
           ParameterDescriptor []parentParameterDescriptors = 
super.getParameterDescriptors();
           // remove fragment parameter
  -        parameterDescriptors = new 
ParameterDescriptor[parentParameterDescriptors.length+1];
  -        int index = 0;
  +        List parameterDescriptorList = new ArrayList();
           for ( int i = 0; i < parentParameterDescriptors.length; i++ ) {
  -            ParameterDescriptor descriptor = parentParameterDescriptors[i];
  -            if ( descriptor.getName() != FRAGMENT ) {
  -                parameterDescriptors[index] = parentParameterDescriptors[i];
  -                index++;
  -            }
  +            parameterDescriptorList.add(parentParameterDescriptors[i]);
           }
  -        parameterDescriptors[parentParameterDescriptors.length-1] = new 
ParameterDescriptor(OFFSET, new ParameterMessage("tableRenderer/offset"), new 
NumberValueDescriptor(), new NumberValue(new Integer(0)));
  -        parameterDescriptors[parentParameterDescriptors.length] = new 
ParameterDescriptor(LENGTH, new ParameterMessage("tableRenderer/length"), new 
NumberValueDescriptor(), new NumberValue(new Integer(0)));
  -
  -        headerTemplate = getOptionalFragment(HEADER_FRAGMENT);
  -        footerTemplate = getOptionalFragment(FOOTER_FRAGMENT);
  -        firstTemplate = getOptionalFragment(FIRST_FRAGMENT);
  -        lastTemplate = getOptionalFragment(LAST_FRAGMENT);
  -        evenTemplate = getOptionalFragment(EVEN_FRAGMENT);
  -        emptyTemplate = getOptionalFragment(EMPTY_FRAGMENT);
  +        parameterDescriptorList.add(new ParameterDescriptor(COLUMNS_PARAMETER, new 
ParameterMessage("tableGenerator/parameter/columns"),
  +                     new ArrayValueDescriptor(new MapValueDescriptor(
  +                                     new ParameterDescriptor[] {
  +                                                     new 
ParameterDescriptor(HEADER, new 
ParameterMessage("tableGenerator/parameter/columns/header"), new 
StringValueDescriptor(), StringValue.EMPTY),
  +                                                     new ParameterDescriptor(KEY, 
new ParameterMessage("tableGenerator/parameter/columns/key"), new 
StringValueDescriptor()),
  +                                                     new 
ParameterDescriptor(RESIZABLE, new 
ParameterMessage("tableGenerator/parameter/columns/resizable"), new 
BooleanValueDescriptor(), BooleanValue.FALSE),
  +                                                     new 
ParameterDescriptor(SORTABLE, new 
ParameterMessage("tableGenerator/parameter/columns/sortable"), new 
BooleanValueDescriptor(), BooleanValue.FALSE)
  +                                     }
  +                     ))));
  +        parameterDescriptorList.add(new ParameterDescriptor(PARAMETER, new 
ParameterMessage("tableGenerator/parameter/parameter"), new MapValueDescriptor(), new 
MapValue(new HashMap())));
  +        parameterDescriptors = (ParameterDescriptor[] 
)parameterDescriptorList.toArray(new 
ParameterDescriptor[parameterDescriptorList.size()]);
  +        sortableHeaderColumnTemplate = 
getOptionalFragment(SORTABLE_HEADER_COLUMN_FRAGMENT);
  +        ascendingHeaderColumnTemplate = 
getOptionalFragment(ASCENDING_HEADER_COLUMN_FRAGMENT);
  +        descendingHeaderColumnTemplate = 
getOptionalFragment(DESCENDING_HEADER_COLUMN_FRAGMENT);
           try {
  -            defaultTemplate = getRequiredFragment(DEFAULT_FRAGMENT);
               columnTemplate = getRequiredFragment(COLUMN_FRAGMENT);
               headerColumnTemplate = getRequiredFragment(HEADER_COLUMN_FRAGMENT);
           } catch ( ProcessException exception ) {
  @@ -90,66 +96,91 @@
       }
   
       public Result process(Map parameter, Context context) throws Exception {
  -        StringBuffer buffer = new StringBuffer(1024);
  -        ArrayValue input = (ArrayValue)parameter.get(SimpleProcessor.INPUT);
  -        int offset = ((NumberValue)parameter.get(OFFSET)).getNumber().intValue();
  -        int length = ((NumberValue)parameter.get(LENGTH)).getNumber().intValue();
  -        parameter.remove(OFFSET);
  -        parameter.remove(LENGTH);
  -        int maxIndex = input.getArray().length;
  -        offset = Math.min(offset, maxIndex);
  -        if ( length > 0 ) {
  -            length = Math.min(length, maxIndex-offset);
  -        } else {
  -            length = maxIndex-offset;
  -        }
  -        if ( maxIndex == 0 ) {
  -            emptyTemplate.evaluate(buffer, parameter);
  +        Map parameters = ((MapValue)parameter.get(PARAMETER)).getMap();
  +        String handlerUrl = 
ProcessorManager.getInstance().process(ProcessorManager.URL, TableHandler.URL, 
context).toString();
  +        String id = parameter.get(TableHandler.ID).toString();
  +        String storeName = parameter.get(TableHandler.STORE).toString();
  +        Store store = context.getStore(StoreHelper.getStoreByName(storeName));
  +        Map tableMap;
  +        MapValue idResource = (MapValue)store.get(id);
  +        String sortedBy = null, order = null;
  +        if ( idResource == null) {
  +            tableMap = new HashMap();
  +            MapValue tableState = new MapValue(tableMap);
  +            store.put(id, tableState);
           } else {
  -            if ( headerTemplate != null ) {
  -                if ( maxIndex > 0 ) {
  -                    Map inputParameter = ((MapValue)input.getArray()[0]).getMap();
  -                    Map columnParameter = new HashMap();
  -                    StringBuffer headers = new StringBuffer();
  -                    for ( Iterator j = inputParameter.keySet().iterator(); 
j.hasNext(); ) {
  -                        columnParameter.putAll(parameter);
  -                        columnParameter.put(VALUE, new 
StringValue((String)j.next()));
  -                        headerColumnTemplate.evaluate(headers, columnParameter);
  -                    }
  -                    Map headerParameter = new HashMap();
  -                    headerParameter.putAll(parameter);
  -                    headerParameter.put(HEADERS, new 
StringValue(headers.toString()));
  -                    headerTemplate.evaluate(buffer, headerParameter);
  -                }
  -            }
  -            for ( int i = 0; i < length; i++ ) {
  -                Map inputParameter = ((MapValue)input.getArray()[i]).getMap();
  -                Map columnParameter = new HashMap();
  -                StringBuffer columns = new StringBuffer();
  -                for ( Iterator j = inputParameter.values().iterator(); j.hasNext(); 
) {
  -                    columnParameter.putAll(parameter);
  -                    columnParameter.put(VALUE, j.next());
  -                    columnTemplate.evaluate(columns, columnParameter);
  -                }
  -                Map rowParameter = new HashMap();
  -                rowParameter.put(COLUMNS, new StringValue(columns.toString()));
  -                rowParameter.putAll(parameter);
  -                if ( i == 0 && firstTemplate != null ) {
  -                    firstTemplate.evaluate(buffer, rowParameter);
  -                } else if ( i == length -1 && lastTemplate != null ) {
  -                    lastTemplate.evaluate(buffer, rowParameter);
  -                } else if ( evenTemplate != null && i%2 == 0 ) {
  -                    evenTemplate.evaluate(buffer, rowParameter);
  -                } else {
  -                    defaultTemplate.evaluate(buffer, rowParameter);
  -                }
  -            }
  -            if ( footerTemplate != null ) footerTemplate.evaluate(buffer, 
parameter);
  +            tableMap = idResource.getMap();
  +            Value sortedByValue = 
(Value)idResource.getMap().get(TableHandler.SORTED_BY);
  +            if ( sortedByValue != null && sortedByValue != NullValue.NULL ) 
sortedBy = sortedByValue.toString();
  +            Value orderValue = (Value)idResource.getMap().get(TableHandler.ORDER);
  +            if ( orderValue != null  && orderValue != NullValue.NULL ) order = 
orderValue.toString();
           }
  -        return new Result(OK, OUTPUT, new StringValue(buffer.toString(), 
defaultTemplate.getContentType(), false ));
  +        // create headers and columns and call super...
  +     StringBuffer headersBuffer = new StringBuffer(1024);
  +     Value []columns = ((ArrayValue)parameter.get(COLUMNS_PARAMETER)).getArray(); 
  +     for ( int i = 0; i < columns.length; i++ ) {
  +             Map columnMap = ((MapValue)columns[i]).getMap();
  +             boolean sortable = 
((BooleanValue)columnMap.get(SORTABLE)).booleanValue();
  +             if ( sortableHeaderColumnTemplate == null || 
ascendingHeaderColumnTemplate == null || descendingHeaderColumnTemplate == null ) 
sortable = false;
  +             boolean resizable = 
((BooleanValue)columnMap.get(RESIZABLE)).booleanValue();
  +             Value header = (Value)columnMap.get(HEADER);
  +             Map columnHeaderParameters = new HashMap();
  +             columnHeaderParameters.putAll(parameter);
  +             columnHeaderParameters.put(HEADER, header);
  +             Template template = headerColumnTemplate;
  +             if ( resizable ) {
  +                     template = resizableHeaderColumnTemplate;
  +             } else if ( sortable ) {
  +                             template = sortableHeaderColumnTemplate;
  +                     String key = columnMap.get(KEY).toString();
  +                     String requestedOrder = TableHandler.ASCENDING;
  +                     if ( sortedBy != null && sortedBy.equals(key) ) {
  +                             if ( order.equals(TableHandler.ASCENDING) ) {
  +                                     template = ascendingHeaderColumnTemplate;
  +                             requestedOrder = TableHandler.DESCENDING;
  +                             } else {
  +                                     template = descendingHeaderColumnTemplate;
  +                             requestedOrder = TableHandler.ASCENDING;
  +                             }
  +                     }
  +                     createHandler(key, requestedOrder, handlerUrl, storeName, id, 
columnHeaderParameters, parameters);
  +             }
  +             template.evaluate(headersBuffer, columnHeaderParameters);
  +     }
  +     parameter.put(HEADERS, new StringValue(headersBuffer.toString()));
  +     Value []input = ((ArrayValue)parameter.get(SimpleProcessor.INPUT)).getArray();
  +     for ( int i = 0; i < input.length; i++ ) {
  +             StringBuffer columnsBuffer = new StringBuffer(1024);
  +            Map inputParameter = ((MapValue)input[i]).getMap();
  +             for ( int j = 0; j < columns.length; j++ ) {
  +                     Map columnMap = ((MapValue)columns[j]).getMap();
  +                     String key = columnMap.get(KEY).toString();
  +                     Value value = (Value)inputParameter.get(key);
  +                     Map columnParameters = new HashMap();
  +                     columnParameters.putAll(parameter);
  +                     columnParameters.put(VALUE, value);
  +                     columnTemplate.evaluate(columnsBuffer, columnParameters);
  +             }       
  +             inputParameter.put(COLUMNS, new StringValue(columnsBuffer.toString()));
  +     }
  +        return super.process(parameter, context);
       }
   
       public ParameterDescriptor[] getParameterDescriptors() {
           return parameterDescriptors;
       }
  -}
  +    
  +    protected void createHandler(String sortedBy, String order, String handlerUrl, 
String storeName, String id, Map parameters, Map parameter) throws IOException {
  +        StringBuffer handlerBuffer = new StringBuffer(128);
  +        
handlerBuffer.append(handlerUrl).append('?').append(TableHandler.STORE).append('=').append(storeName).append('&').append(TableHandler.ID).append('=').append(id).
  +             
append('&').append(TableHandler.SORTED_BY).append('=').append(sortedBy).append('&').append(TableHandler.ORDER).append('=').append(order);
  +        for ( Iterator j = parameter.entrySet().iterator(); j.hasNext(); ) {
  +             Map.Entry entry = (Map.Entry)j.next();
  +             if ( entry.getValue() instanceof PrintableValue ) {
  +                     handlerBuffer.append('&').append(entry.getKey()).append('=');
  +                     ((PrintableValue)entry.getValue()).print(handlerBuffer);
  +             }
  +        }
  +        parameters.put(HANDLER, new StringValue(handlerBuffer.toString()));
  +    }
  +}
  \ No newline at end of file
  
  
  
  1.5       +26 -4     
jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/table/TableHandler.java
  
  Index: TableHandler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/table/TableHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TableHandler.java 1 Jun 2004 07:49:58 -0000       1.4
  +++ TableHandler.java 21 Jun 2004 16:00:25 -0000      1.5
  @@ -6,7 +6,10 @@
   import org.apache.slide.projector.util.StoreHelper;
   import org.apache.slide.projector.util.ProcessorHelper;
   import org.apache.slide.projector.value.MapValue;
  +import org.apache.slide.projector.value.NullValue;
   import org.apache.slide.projector.value.NumberValue;
  +import org.apache.slide.projector.value.StringValue;
  +import org.apache.slide.projector.value.Value;
   import org.apache.slide.projector.descriptor.*;
   
   import java.util.Map;
  @@ -18,24 +21,35 @@
    */
   
   public class TableHandler implements Processor {
  +    final static String URL = "tableHandler";
  +
       final static String OK = "id";
   
       final static String ID = "id";
       final static String STORE = "store";
       final static String TARGET_POSITION = "targetPosition";
       final static String CURRENT_POSITION = "currentPosition";
  +    final static String SORTED_BY= "sortedBy";
  +    final static String ORDER= "order";
  +
  +    final static String ASCENDING= "ascending";
  +    final static String DESCENDING= "descending";
   
       final static ParameterDescriptor[] parameterDescirptors = new 
ParameterDescriptor[] {
           new ParameterDescriptor(ID, new ParameterMessage("tableHandler/id"), new 
StringValueDescriptor()),
  -        new ParameterDescriptor(TARGET_POSITION, new 
ParameterMessage("tableHandler/targetPosition"), new NumberValueDescriptor()),
  +        new ParameterDescriptor(TARGET_POSITION, new 
ParameterMessage("tableHandler/targetPosition"), new NumberValueDescriptor(), 
NullValue.NULL),
  +        new ParameterDescriptor(SORTED_BY, new 
ParameterMessage("tableHandler/sortedBy"), new StringValueDescriptor(), 
NullValue.NULL),
  +        new ParameterDescriptor(ORDER, new ParameterMessage("tableHandler/order"), 
new StringValueDescriptor(new String[] {ASCENDING, DESCENDING}), NullValue.NULL),
           new ParameterDescriptor(STORE, new ParameterMessage("tableHandler/store"), 
new StringValueDescriptor(Store.stores))
       };
   
       public Result process(Map parameter, Context context) throws Exception {
  -        NumberValue targetPosition = (NumberValue)parameter.get(TARGET_POSITION);
           String id = parameter.get(ID).toString();
           Store store = 
context.getStore(StoreHelper.getStoreByName(parameter.get(STORE).toString()));
           MapValue idResource = (MapValue)store.get(id);
  +        Value targetPosition = (Value)parameter.get(TARGET_POSITION);
  +        Value sortedBy = (Value)parameter.get(SORTED_BY);
  +        Value order = (Value)parameter.get(ORDER);
           Map tableMap;
           if ( idResource == null) {
               tableMap = new HashMap();
  @@ -44,7 +58,15 @@
           } else {
               tableMap = idResource.getMap();
           }
  -        tableMap.put(CURRENT_POSITION, targetPosition);
  +        if ( targetPosition != NullValue.NULL ) {
  +             tableMap.put(CURRENT_POSITION, targetPosition);
  +        }
  +        if ( sortedBy != NullValue.NULL ) {
  +            tableMap.put(SORTED_BY, sortedBy);
  +        }
  +        if ( order != NullValue.NULL ) {
  +            tableMap.put(ORDER, order);
  +        }
           URI bookmark = (URI)context.getBookmark();
           if ( bookmark != null ) {
                Processor processor = 
ProcessorManager.getInstance().getProcessor(bookmark);
  
  
  
  1.5       +56 -14    
jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/table/TableMapRenderer.java
  
  Index: TableMapRenderer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/table/TableMapRenderer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TableMapRenderer.java     17 Jun 2004 14:54:56 -0000      1.4
  +++ TableMapRenderer.java     21 Jun 2004 16:00:25 -0000      1.5
  @@ -15,32 +15,34 @@
   import org.apache.slide.projector.i18n.ParameterMessage;
   
   import java.util.ArrayList;
  +import java.util.Arrays;
  +import java.util.Comparator;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
   import java.util.HashMap;
   
   public class TableMapRenderer extends TemplateMapRenderer {
  -    final private static String HEADER_FRAGMENT = "header";
  -    final private static String FOOTER_FRAGMENT = "footer";
  -    final private static String FIRST_FRAGMENT = "first";
  -    final private static String LAST_FRAGMENT = "last";
  -    final private static String EVEN_FRAGMENT = "even";
  -    final private static String DEFAULT_FRAGMENT = "default";
  -    final private static String EMPTY_FRAGMENT = "empty";
  +    final protected static String HEADER_FRAGMENT = "header";
  +    final protected static String FOOTER_FRAGMENT = "footer";
  +    final protected static String FIRST_FRAGMENT = "first";
  +    final protected static String LAST_FRAGMENT = "last";
  +    final protected static String EVEN_FRAGMENT = "even";
  +    final protected static String DEFAULT_FRAGMENT = "default";
  +    final protected static String EMPTY_FRAGMENT = "empty";
   
       final static String OFFSET = "offset";
       final static String ITEMS_PER_PAGE = "itemsPerPage";
   
       final static String LENGTH = "length";
   
  -    private Template headerTemplate;
  -    private Template footerTemplate;
  -    private Template firstTemplate;
  -    private Template lastTemplate;
  -    private Template evenTemplate;
  -    private Template defaultTemplate;
  -    private Template emptyTemplate;
  +    protected Template headerTemplate;
  +    protected Template footerTemplate;
  +    protected Template firstTemplate;
  +    protected Template lastTemplate;
  +    protected Template evenTemplate;
  +    protected Template defaultTemplate;
  +    protected Template emptyTemplate;
   
       private ParameterDescriptor []parameterDescriptors;
       private String[] repeatedFragments;
  @@ -79,6 +81,8 @@
           parameterDescriptorList.add(new ParameterDescriptor(ITEMS_PER_PAGE, new 
ParameterMessage("tableRenderer/length"), new NumberValueDescriptor(), new 
NumberValue(new Integer(-10))));
           parameterDescriptorList.add(new ParameterDescriptor(TableHandler.ID, new 
ParameterMessage("tableRenderer/id"), new StringValueDescriptor(), new 
StringValue("table")));
           parameterDescriptorList.add(new ParameterDescriptor(TableHandler.STORE, new 
ParameterMessage("tableRenderer/store"), new StringValueDescriptor(Store.stores), new 
StringValue(Store.stores[Store.SESSION])));
  +        parameterDescriptorList.add(new ParameterDescriptor(TableHandler.SORTED_BY, 
new ParameterMessage("tableHandler/sortedBy"), new StringValueDescriptor(), 
NullValue.NULL));
  +        parameterDescriptorList.add(new ParameterDescriptor(TableHandler.ORDER, new 
ParameterMessage("tableHandler/order"), new StringValueDescriptor(new String[] 
{TableHandler.ASCENDING, TableHandler.DESCENDING}), NullValue.NULL));
           parameterDescriptors = (ParameterDescriptor[] 
)parameterDescriptorList.toArray(new 
ParameterDescriptor[parameterDescriptorList.size()]);
           
           headerTemplate = getOptionalFragment(HEADER_FRAGMENT);
  @@ -99,6 +103,11 @@
           ArrayValue input = (ArrayValue)parameter.get(SimpleProcessor.INPUT);
           NumberValue offsetResource = (NumberValue)parameter.get(OFFSET);
           NumberValue itemsPerPageResource = 
(NumberValue)parameter.get(ITEMS_PER_PAGE);
  +        Value sortedByParameter = (Value)parameter.get(TableHandler.SORTED_BY);
  +        Value orderParameter = (Value)parameter.get(TableHandler.ORDER);
  +        String sortedBy = null, order = null;
  +        if ( sortedByParameter != NullValue.NULL ) sortedBy = 
sortedByParameter.toString();
  +        if ( orderParameter != NullValue.NULL ) order = orderParameter.toString();
           String id = parameter.get(TableHandler.ID).toString();
           Store store = 
context.getStore(StoreHelper.getStoreByName(parameter.get(TableHandler.STORE).toString()));
           MapValue idResource = (MapValue)store.get(id);
  @@ -113,6 +122,15 @@
               if ( offset != null ) offsetResource = offset;
               NumberValue itemsPerPage = 
(NumberValue)idResource.getMap().get(ITEMS_PER_PAGE);
               if ( itemsPerPage != null ) itemsPerPageResource = itemsPerPage;
  +            Value sortedByValue = 
(Value)idResource.getMap().get(TableHandler.SORTED_BY);
  +            if ( sortedByValue != null && sortedByValue != NullValue.NULL ) 
sortedBy = sortedByValue.toString();
  +            Value orderValue = (Value)idResource.getMap().get(TableHandler.ORDER);
  +            if ( orderValue != null  && orderValue != NullValue.NULL ) order = 
orderValue.toString();
  +        }
  +     // sort table
  +        if ( sortedBy != null && order != null ) {
  +             Comparator comparator = new RowComparator(sortedBy, order); 
  +             Arrays.sort(input.getArray(), comparator);
           }
           tableMap.put(TableHandler.CURRENT_POSITION, offsetResource);
           tableMap.put(ITEMS_PER_PAGE, itemsPerPageResource);
  @@ -172,5 +190,29 @@
               return true;
           }
           return false;
  +    }
  +
  +    protected class RowComparator implements Comparator {
  +     private String sortBy, order;
  +     
  +             public RowComparator(String sortBy, String order) {
  +                     this.sortBy = sortBy;
  +                     this.order = order;
  +             }
  +
  +             public int compare(Object o1, Object o2) {
  +                     Map map1 = ((MapValue)o1).getMap();
  +                     Map map2 = ((MapValue)o2).getMap();
  +                     Value v1 = (Value)map1.get(sortBy);
  +                     Value v2 = (Value)map2.get(sortBy);
  +                     int comparison = 0;
  +                     if ( v1 instanceof Comparable ) {
  +                             comparison = ((Comparable)v1).compareTo(v2);
  +                             if ( order.equals(TableHandler.ASCENDING) ) {
  +                                     comparison = -comparison;
  +                             }
  +                     }
  +                     return comparison;
  +             }
       }
   }
  
  
  
  1.2       +12 -1     
jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/value/ObjectValue.java
  
  Index: ObjectValue.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/value/ObjectValue.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ObjectValue.java  1 Jun 2004 07:49:55 -0000       1.1
  +++ ObjectValue.java  21 Jun 2004 16:00:25 -0000      1.2
  @@ -9,7 +9,7 @@
   import java.io.ObjectOutputStream;
   import java.io.Serializable;
   
  -public class ObjectValue implements Value {
  +public class ObjectValue implements Comparable, Value {
       private Object object;
   
       public ObjectValue(Object object) {
  @@ -40,4 +40,15 @@
               writer.writeElementWithPCData(XMLWriter.createStartTag("value"), 
XMLEncode.xmlEncodeText(object.toString()), XMLWriter.createEndTag("value"));
           }
       }
  +
  +     public int compareTo(Object o) {
  +             Object comparableObject = null;
  +             if ( o instanceof ObjectValue ) {
  +                     comparableObject = ((ObjectValue)o).getObject();
  +             }
  +             if ( comparableObject != null && 
object.getClass().equals(comparableObject.getClass()) ) {
  +                     return ((Comparable)object).compareTo(comparableObject);
  +             }
  +             return 0;
  +     }
   }
  
  
  
  1.2       +0 -63     
jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/value/LocaleValue.java
  
  Index: LocaleValue.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/value/LocaleValue.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocaleValue.java  1 Jun 2004 07:49:55 -0000       1.1
  +++ LocaleValue.java  21 Jun 2004 16:00:25 -0000      1.2
  @@ -6,69 +6,6 @@
   
   import java.util.Locale;
   
  -/*
  - * $Header$
  - * $Revision$
  - * $Date$
  - *
  - * ====================================================================
  - *
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:
  - *       "This product includes software developed by the
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowlegement may appear in the software itself,
  - *    if and wherever such third-party acknowlegements normally appear.
  - *
  - * 4. The names "The Jakarta Project", "Slide", and "Apache Software
  - *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written
  - *    permission, please contact [EMAIL PROTECTED]
  - *
  - * 5. Products derived from this software may not be called "Apache"
  - *    nor may "Apache" appear in their names without prior written
  - *    permission of the Apache Group.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - *
  - * [Additional notices, if required by prior licensing conditions]
  - *
  - */
  -
   public class LocaleValue implements Value {
       private Locale locale;
   
  
  
  
  1.3       +3 -1      
jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/value/StringValue.java
  
  Index: StringValue.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/value/StringValue.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StringValue.java  8 Jun 2004 09:04:06 -0000       1.2
  +++ StringValue.java  21 Jun 2004 16:00:25 -0000      1.3
  @@ -11,7 +11,9 @@
   import java.io.InputStream;
   
   public class StringValue extends ObjectValue implements StreamableValue, 
PrintableValue {
  -    private boolean isDocument;
  +     public static final StringValue EMPTY = new StringValue("");
  +
  +     private boolean isDocument;
       private String contentType = "text/plain";
   
       public StringValue(String content) {
  
  
  
  1.3       +4 -1      
jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/process/ParameterConfiguration.java
  
  Index: ParameterConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/process/ParameterConfiguration.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ParameterConfiguration.java       8 Jun 2004 14:43:16 -0000       1.2
  +++ ParameterConfiguration.java       21 Jun 2004 16:00:25 -0000      1.3
  @@ -2,7 +2,9 @@
   
   import org.apache.slide.projector.*;
   import org.apache.slide.projector.descriptor.ParameterDescriptor;
  +import org.apache.slide.projector.descriptor.ValidationException;
   import org.apache.slide.projector.engine.ProcessorManager;
  +import org.apache.slide.projector.i18n.ErrorMessage;
   import org.apache.slide.projector.util.StoreHelper;
   import org.apache.slide.projector.value.MapValue;
   import org.apache.slide.projector.value.URIValue;
  @@ -148,7 +150,8 @@
           }
   
           public Object getEvaluatedValue(Map parameter, Store stepStore, Context 
context) throws ProcessException, IOException {
  -            return configuration.getEvaluatedValue(parameter, stepStore, context);
  +             if ( configuration == null ) throw new ValidationException(new 
ErrorMessage("mapEntry/valueNotSet", new String[] { key }));
  +             return configuration.getEvaluatedValue(parameter, stepStore, context);
           }
   
           public String getKey() {
  
  
  
  1.3       +3 -1      
jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/query/ResultResolver.java
  
  Index: ResultResolver.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/proposals/projector/src/java/org/apache/slide/projector/processor/query/ResultResolver.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ResultResolver.java       2 Jun 2004 15:35:39 -0000       1.2
  +++ ResultResolver.java       21 Jun 2004 16:00:25 -0000      1.3
  @@ -26,6 +26,7 @@
   import java.util.Map;
   
   
  +import org.apache.slide.projector.Constants;
   import org.apache.slide.projector.Context;
   import org.apache.slide.projector.Processor;
   import org.apache.slide.projector.Result;
  @@ -51,6 +52,7 @@
   import org.apache.slide.projector.value.MultipleStreamableValue;
   import org.apache.slide.projector.value.NullValue;
   import org.apache.slide.projector.value.StreamableValue;
  +import org.apache.slide.projector.value.URIValue;
   import org.apache.slide.projector.value.Value;
   import org.jdom.xpath.XPath;
   
  @@ -101,7 +103,7 @@
                        Map resultMap = new HashMap();
                        resultMap.putAll(map);
                        URI uri = (URI)map.get(URI_ENTRY);
  -                     Value content = 
ConnectorFactory.getConnector().getResource(uri, context.getCredentials()); 
  +                     Value content = 
ConnectorFactory.getConnector().getResource(new 
URIValue(Constants.REPOSITORY_DOMAIN+uri), context.getCredentials()); 
                        if ( content != null ) {
                                if ( instructions instanceof MapValue ) {
                                        if ( includeContent ) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to