My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 143 attachment: fixed-for-143-new3.patch (19.7 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
Index: src/org/jmesa/view/renderer/ExportHtmlCellRenderer.java
===================================================================
--- src/org/jmesa/view/renderer/ExportHtmlCellRenderer.java (revision 0)
+++ src/org/jmesa/view/renderer/ExportHtmlCellRenderer.java (revision 0)
@@ -0,0 +1,71 @@
+// FrontEnd Plus GUI for JAD
+// DeCompiled : ExportHtmlCellRenderer.class
+
+package org.jmesa.view.renderer;
+
+import org.jmesa.view.component.Column;
+import org.jmesa.view.editor.CellEditor;
+import org.jmesa.view.html.component.HtmlColumn;
+import org.jmesa.view.html.renderer.HtmlCellRenderer;
+import org.jmesa.worksheet.editor.WorksheetEditor;
+
+public class ExportHtmlCellRenderer implements HtmlCellRenderer {
+
+ private HtmlColumn column;
+ private HtmlCellRenderer cellRenderer;
+
+ private CellEditor cellEditor;
+
+ public ExportHtmlCellRenderer(HtmlColumn column) {
+ this.column = column;
+ cellRenderer = column.getCellRenderer();
+ cellEditor = cellRenderer.getCellEditor();
+ }
+
+ public String getStyle() {
+ return cellRenderer.getStyle();
+ }
+
+ public String getStyleClass() {
+ return cellRenderer.getStyleClass();
+ }
+
+ public WorksheetEditor getWorksheetEditor() {
+ return cellRenderer.getWorksheetEditor();
+ }
+
+ public void setStyle(String s) {
+ cellRenderer.setStyle(s);
+ }
+
+ public void setStyleClass(String s) {
+ cellRenderer.setStyleClass(s);
+ }
+
+ public void setWorksheetEditor(WorksheetEditor worksheeteditor) {
+ cellRenderer.setWorksheetEditor(worksheeteditor);
+ }
+
+ public CellEditor getCellEditor() {
+ return cellEditor != null ? cellEditor : cellRenderer.getCellEditor();
+ }
+
+ public Object render(Object item, int rowcount) {
+ final CellEditor cellEditor = getCellEditor();
+ final Object value = cellEditor.getValue(item, getColumn().getProperty(),
+ rowcount);
+ return value;
+ }
+
+ public void setCellEditor(CellEditor celleditor) {
+ this.cellEditor = celleditor;
+ }
+
+ public void setColumn(Column column) {
+ cellRenderer.setColumn(column);
+ }
+
+ public HtmlColumn getColumn() {
+ return column;
+ }
+}
Index: src/org/jmesa/facade/filter/TableFacadeFilter.java
===================================================================
--- src/org/jmesa/facade/filter/TableFacadeFilter.java (revision 2276)
+++ src/org/jmesa/facade/filter/TableFacadeFilter.java (working copy)
@@ -25,42 +25,61 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

+
/**
* <p>
* A filter to put the request and response on the ThreadLocal to pass to the
* TableFacade implementation. Very useful for controllers in frameworks that
* try to keep the request and response inaccessable.
* </p>
- *
+ *
* <p>
* <filter>
* <filter-name>TableFacadeFilter</filter-name>
* <filter-class>org.jmesa.facade.filter.TableFacadeFilter</filter-class>
* </filter>
- *
+ *
* <filter-mapping>
* <filter-name>TableFacadeFilter</filter-name>
* <url-pattern>/*</url-pattern>
* </filter-mapping>
* <p>
- *
+ *
* @since 2.2
* @author Jeff Johnston
*/
public class TableFacadeFilter implements Filter {

+ private String exportParam = "jemsaExport";
+
public void init(FilterConfig config) throws ServletException {
+ String tmp = config.getInitParameter("exportParam");
+ if( tmp != null){
+ exportParam = tmp;
+ }
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {

- FilterThreadLocal.set((HttpServletRequest) request, (HttpServletResponse) response);
+ if("true".equals(request.getParameter(exportParam))){

- // run the other filters
- chain.doFilter(request, response);
+ // tell sitemesh do not decorated this request
+ request.setAttribute("__sitemesh__filterapplied", Boolean.TRUE);

- FilterThreadLocal.set(null, null);
+ FilterThreadLocal.set((HttpServletRequest) request, (HttpServletResponse) response);
+
+ request.setAttribute("response", response);
+
+ ExportResponseWrapper responseWrapper = new ExportResponseWrapper( (HttpServletResponse)response);
+
+ // run the other filters
+ chain.doFilter(request, responseWrapper);
+
+ FilterThreadLocal.set(null, null);
+ }else{
+ chain.doFilter(request, response);
+ }
}

public void destroy() {
@@ -81,12 +100,12 @@

public static HttpServletRequest getHttpServletRequest() {
FilterValue filterValue = (FilterValue) tLocal.get();
- return filterValue.getRequest();
+ return filterValue != null ? filterValue.getRequest() : null;
}
-
+
public static HttpServletResponse getHttpServletResponse() {
FilterValue filterValue = (FilterValue) tLocal.get();
- return filterValue.getResponse();
+ return filterValue != null ? filterValue.getResponse() : null;
}

private static class FilterValue {
Index: src/org/jmesa/facade/filter/ExportResponseWrapper.java
===================================================================
--- src/org/jmesa/facade/filter/ExportResponseWrapper.java (revision 0)
+++ src/org/jmesa/facade/filter/ExportResponseWrapper.java (revision 0)
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2004 original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jmesa.facade.filter;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+/**
+ * @author Jeff Johnston
+ */
+public final class ExportResponseWrapper extends HttpServletResponseWrapper {
+ private ByteArrayOutputStream output;
+ private int contentLength;
+ private String contentType;
+
+ public ExportResponseWrapper(HttpServletResponse response) {
+ super(response);
+ output = new ByteArrayOutputStream();
+ }
+
+ public byte[] getData() {
+ return output.toByteArray();
+ }
+
+ public ServletOutputStream getOutputStream() {
+ return new FilterServletOutputStream(output);
+ }
+
+ public PrintWriter getWriter() {
+ return new PrintWriter(getOutputStream(), true);
+ }
+
+ public void setContentLength(int length) {
+ this.contentLength = length;
+ super.setContentLength(length);
+ }
+
+ public int getContentLength() {
+ return contentLength;
+ }
+
+ public void setContentType(String type) {
+ this.contentType = type;
+ super.setContentType(type);
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ private static class FilterServletOutputStream extends ServletOutputStream {
+ private DataOutputStream stream;
+
+ public FilterServletOutputStream(OutputStream output) {
+ stream = new DataOutputStream(output);
+ }
+
+ public void write(int b) throws IOException {
+ stream.write(b);
+ }
+
+ public void write(byte[] b) throws IOException {
+ stream.write(b);
+ }
+
+ public void write(byte[] b, int off, int len) throws IOException {
+ stream.write(b, off, len);
+ }
+ }
+}
Index: src/org/jmesa/facade/tag/TableFacadeTag.java
===================================================================
--- src/org/jmesa/facade/tag/TableFacadeTag.java (revision 2276)
+++ src/org/jmesa/facade/tag/TableFacadeTag.java (working copy)
@@ -15,22 +15,25 @@
*/
package org.jmesa.facade.tag;

+import static org.jmesa.facade.tag.TagUtils.getTableFacadeColumnSort;
+import static org.jmesa.facade.tag.TagUtils.getTableFacadeExportTypes;
import static org.jmesa.facade.tag.TagUtils.getTableFacadeFilterMatcherMap;
+import static org.jmesa.facade.tag.TagUtils.getTableFacadeMaxRowIncrements;
import static org.jmesa.facade.tag.TagUtils.getTableFacadeMessages;
import static org.jmesa.facade.tag.TagUtils.getTableFacadePreferences;
import static org.jmesa.facade.tag.TagUtils.getTableFacadeRowFilter;
-import static org.jmesa.facade.tag.TagUtils.getTableFacadeColumnSort;
import static org.jmesa.facade.tag.TagUtils.getTableFacadeToolbar;
-import static org.jmesa.facade.tag.TagUtils.getTableFacadeMaxRowIncrements;
import static org.jmesa.facade.tag.TagUtils.getTableFacadeView;
-import static org.jmesa.facade.tag.TagUtils.getTableFacadeExportTypes;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;

+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.JspFragment;
@@ -38,17 +41,24 @@

import org.jmesa.facade.TableFacade;
import org.jmesa.facade.TableFacadeFactory;
+import org.jmesa.facade.filter.TableFacadeFilter;
import org.jmesa.limit.Limit;
-import org.jmesa.view.View;
+import org.jmesa.view.editor.BasicCellEditor;
+import org.jmesa.view.editor.CellEditor;
import org.jmesa.view.html.HtmlComponentFactory;
import org.jmesa.view.html.HtmlUtils;
+import org.jmesa.view.html.component.HtmlColumn;
import org.jmesa.view.html.component.HtmlTable;
+import org.jmesa.view.html.editor.HtmlCellEditor;
+import org.jmesa.view.renderer.ExportHtmlCellRenderer;
import org.jmesa.web.JspPageWebContext;
import org.jmesa.web.WebContext;
+import org.jmesa.worksheet.editor.WorksheetEditor;

+
/**
* A tag abstraction similar to the TableFacade. See the TableFacade document for more information.
- *
+ *
* @since 2.1
* @author Jeff Johnston
*/
@@ -103,7 +113,7 @@
* Useful if performing the sorting and filtering manually and need to set the items on the
* facade. If you are performing the sorting and filtering manually you should also set the
* autoFilterAndSort() to false.
- *
+ *
* @param items The Collecton of Beans (or Maps) to use.
*/
public void setItems(Collection items) {
@@ -119,7 +129,7 @@

/**
* The max rows to display on a page.
- *
+ *
* @param maxRows The maxRows to use.
*/
public void setMaxRows(int maxRows) {
@@ -136,7 +146,7 @@
/**
* Set the comma separated list of values to use for the max rows droplist. Be sure that one of
* the values is the same as the maxRows set on the facade.
- *
+ *
* @param maxRowsIncrements The max rows increments to use.
*/
public void setMaxRowsIncrements(String maxRowsIncrements) {
@@ -153,7 +163,7 @@
/**
* Utilize the State interface to persist the Limit in the users HttpSession. Will persist the
* Limit by the id.
- *
+ *
* @param stateAttr The parameter that will be searched to see if the state should be used.
*/
public void setStateAttr(String stateAttr) {
@@ -189,7 +199,7 @@
/**
* Set the comma separated list of export types. The currently supported types are
* TableFacadeImpl.CVS and TableFacadeImpl.EXCEL.
- *
+ *
* @param exportTypes The exportTypes to use.
*/
public void setExportTypes(String exportTypes) {
@@ -205,7 +215,7 @@

/**
* Turn the table into an editable worksheet.
- *
+ *
* @param editable Is true if the table should be editable.
*/
public void setEditable(boolean editable) {
@@ -221,7 +231,7 @@

/**
* The value to hold the current bean or map.
- *
+ *
* @param var The var to use.
*/
public void setVar(String var) {
@@ -232,7 +242,7 @@
* <p>
* Get the Limit.
* </p>
- *
+ *
* @return The Limit to use.
*/
public Limit getLimit() {
@@ -241,7 +251,7 @@

/**
* Set the Limit on the facade. This will override the Limit if it was previously set.
- *
+ *
* @param limit The Limit to use.
*/
public void setLimit(Limit limit) {
@@ -250,7 +260,7 @@

/**
* Get the Messages. If the Messages does not exist then one will be created.
- *
+ *
* @return The Messages to use.
*/
public String getMessages() {
@@ -259,7 +269,7 @@

/**
* Set the Messages on the facade.
- *
+ *
* @param messages The Messages to use.
*/
public void setMessages(String messages) {
@@ -268,7 +278,7 @@

/**
* Get the Preferences. If the Preferences does not exist then one will be created.
- *
+ *
* @return The Preferences to use.
*/
public String getPreferences() {
@@ -277,7 +287,7 @@

/**
* Set the Preferences on the facade.
- *
+ *
* @param preferences The Preferences to use.
*/
public void setPreferences(String preferences) {
@@ -286,7 +296,7 @@

/**
* Get the RowFilter. If the RowFilter does not exist then one will be created.
- *
+ *
* @return The RowFilter to use.
*/
public String getRowFilter() {
@@ -295,7 +305,7 @@

/**
* Set the RowFilter on the facade.
- *
+ *
* @param rowFilter The RowFilter to use.
*/
public void setRowFilter(String rowFilter) {
@@ -304,7 +314,7 @@

/**
* Get the ColumnSort. If the ColumnSort does not exist then one will be created.
- *
+ *
* @return The ColumnSort to use.
*/
public String getColumnSort() {
@@ -313,7 +323,7 @@

/**
* Set the ColumnSort on the facade.
- *
+ *
* @param columnSort The ColumnSort to use.
*/
public void setColumnSort(String columnSort) {
@@ -329,7 +339,7 @@

/**
* Set the View on the facade. This will override the View if it was previously set.
- *
+ *
* @param view The View to use.
*/
public void setView(String view) {
@@ -338,7 +348,7 @@

/**
* Get the Toolbar. If the Toolbar does not exist then one will be created.
- *
+ *
* @return The Toolbar to use.
*/
public String getToolbar() {
@@ -347,7 +357,7 @@

/**
* Set the Toolbar on the facade. This will override the Toolbar if it was previously set.
- *
+ *
* @param toolbar The Toolbar to use.
*/
public void setToolbar(String toolbar) {
@@ -363,7 +373,7 @@

/**
* Set the current Map of FilterMatchers.
- *
+ *
* @param filterMatcherMap The Map of current FilterMatchers.
*/
public void setFilterMatcherMap(String filterMatcherMap) {
@@ -386,7 +396,7 @@

/**
* Set the Table on the facade.
- *
+ *
* @param table The HtmlTable to use.
*/
void setTable(HtmlTable table) {
@@ -412,7 +422,7 @@
* for each row Bean (or Map) and then used in place of the regular items. So in effect this is
* a Collection of Maps that represents the original Collection of Beans (or Maps) after being
* processed by the columns.
- *
+ *
* @return The converted items.
*/
Collection<Map<String, Object>> getPageItems() {
@@ -438,14 +448,29 @@
tableFacade.setLimit(getLimit());

tableFacade.setMaxRowsIncrements(getTableFacadeMaxRowIncrements(getMaxRowsIncrements()));
- tableFacade.setExportTypes(null, getTableFacadeExportTypes(getExportTypes()));

+ HttpServletResponse response = (HttpServletResponse) TableFacadeFilter.FilterThreadLocal.getHttpServletResponse();
+ if( null == response){
+ response = (HttpServletResponse) getJspContext().getAttribute("response", PageContext.REQUEST_SCOPE);
+ }
+ tableFacade.setExportTypes(response, getTableFacadeExportTypes(getExportTypes()));
+
tableFacade.autoFilterAndSort(isAutoFilterAndSort());
tableFacade.setPreferences(getTableFacadePreferences(getPreferences()));
tableFacade.setColumnSort(getTableFacadeColumnSort(getColumnSort()));
tableFacade.setRowFilter(getTableFacadeRowFilter(getRowFilter()));
tableFacade.addFilterMatcherMap(getTableFacadeFilterMatcherMap(getFilterMatcherMap()));

+ boolean isExported = true;
+ final Limit limitObj = tableFacade.getLimit();
+ if (limitObj == null || !limitObj.isExported()) {
+ isExported = false;
+ }else{
+ tableFacade.setEditable(false);
+ getJspContext().setAttribute("limit", limitObj);
+ getJspContext().setAttribute("exportType", limitObj.getExportType().toParam());
+ }
+
Collection<?> pi = tableFacade.getCoreContext().getPageItems();

if (pi.size() == 0) {
@@ -465,13 +490,35 @@
getJspContext().removeAttribute("rowcount");

tableFacade.setTable(getTable());
+
+
+ if (isExported) {
+ List<?> columns = tableFacade.getTable().getRow().getColumns();
+ for (Iterator<?> iterator = columns.iterator(); iterator.hasNext();) {
+ HtmlColumn col = (HtmlColumn)iterator.next();
+ final ExportHtmlCellRenderer exportHtmlCellRenderer = new ExportHtmlCellRenderer(col);
+ CellEditor cellEditor = col.getCellRenderer().getCellEditor();
+ if ( cellEditor instanceof WorksheetEditor){
+ cellEditor = ((WorksheetEditor)cellEditor).getCellEditor();
+ }
+ if( cellEditor instanceof HtmlCellEditor){
+ cellEditor = new BasicCellEditor();
+ }
+ exportHtmlCellRenderer.setCellEditor(cellEditor);
+ col.setCellRenderer(exportHtmlCellRenderer);
+ }
+ }
+
tableFacade.setToolbar(getTableFacadeToolbar(getToolbar()));
- tableFacade.setView(getTableFacadeView(getView()));
+
+ if (!isExported) {//using default export view
+ tableFacade.setView(getTableFacadeView(getView()));
+ }
tableFacade.getCoreContext().setPageItems(getPageItems());
-
- View v = tableFacade.getView();
- String html = v.render().toString();
- getJspContext().getOut().print(html);
+ String renderStr = tableFacade.render();
+ if (renderStr != null) {
+ getJspContext().getOut().print(renderStr);
+ }
}

protected WebContext getWebContext() {
@@ -480,7 +527,9 @@

protected TableFacade createTableFacade() {

- TableFacade facade = TableFacadeFactory.createTableFacade(getId(), getWebContext());
+ final HttpServletRequest request = TableFacadeFilter.FilterThreadLocal.getHttpServletRequest();
+ TableFacade facade = request != null ? TableFacadeFactory.createTableFacade(getId(),request): TableFacadeFactory.createTableFacade(getId(), getWebContext());
+
facade.setMessages(getTableFacadeMessages(getMessages()));
return facade;
}
Powered by Google Project Hosting