View Javadoc

1   /*
2    * Copyright 2004 Jeff Johnston
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.extremecomponents.table.model;
17  
18  import java.util.ArrayList;
19  import java.util.Iterator;
20  import java.util.List;
21  
22  import org.apache.commons.lang.StringUtils;
23  
24  import org.apache.commons.logging.Log;
25  import org.apache.commons.logging.LogFactory;
26  import org.extremecomponents.table.bean.Export;
27  
28  
29  
30  /***
31   * @author Jeff Johnston
32   */
33  public class ExportHandler
34  {
35  	private static Log logger = LogFactory.getLog(ExportHandler.class);
36  	public final static String PDF = "pdf";
37  	public final static String XLS = "xls";
38  	public final static String EXPORT_NAME = "export_name_";
39  	public final static String EXPORT_DATA = "exportData";
40  	private TableModel model;
41  	private List exports = new ArrayList();
42  
43  	public ExportHandler(TableModel model)
44  	{
45  		this.model = model;
46  	}
47  
48  	public void addExport(Export export)
49  	{
50  		exports.add(export);
51  	}
52  
53  	public Export getExport(String view)
54  	{
55  		for (Iterator iter = exports.iterator(); iter.hasNext();)
56  		{
57  			Export export = (Export) iter.next();
58  
59  			if (export.getView().equals(view))
60  			{
61  				return export;
62  			}
63  		}
64  
65  		return null;
66  	}
67  
68  	public boolean invokeExport()
69  	{
70  		String value = model.getRegistry().getParameter(ParameterRegistry.EXPORT);
71  
72  		if (StringUtils.isNotBlank(value))
73  		{
74  			return true;
75  		}
76  
77  		return false;
78  	}
79  
80  	public Export getCurrentExport()
81  	{
82  		return getExport(model.getRegistry().getParameter(ParameterRegistry.EXPORT));
83  	}
84  
85  	public List getExports()
86  	{
87  		return exports;
88  	}
89  	
90  	public boolean hasExports()
91  	{
92  		return getExports().size() > 0;
93  	}
94  	
95  	public void destroy()
96  	{
97  		exports.clear();
98  		exports = null;
99  	}	
100 }