KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > projects > CmsProjectFilesCollector


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/projects/CmsProjectFilesCollector.java,v $
3  * Date : $Date: 2006/03/27 14:52:43 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.tools.projects;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsResource;
36 import org.opencms.file.collectors.I_CmsResourceCollector;
37 import org.opencms.main.CmsException;
38 import org.opencms.main.CmsLog;
39 import org.opencms.util.CmsStringUtil;
40
41 import java.util.ArrayList JavaDoc;
42 import java.util.Collections JavaDoc;
43 import java.util.List JavaDoc;
44
45 import org.apache.commons.logging.Log;
46
47 /**
48  * Collector for receiving CmsResources from a project.<p>
49  *
50  * @author Michael Emmerich
51  *
52  * @version $Revision: 1.2 $
53  *
54  * @since 6.1.0
55  */

56 public class CmsProjectFilesCollector implements I_CmsResourceCollector {
57
58     /** Parameter of the default collector name. */
59     public static final String JavaDoc COLLECTOR_NAME = "projectresources";
60
61     /** Parameter to get all changed resources. */
62     public static final String JavaDoc PARAM_CHANGED = "changed";
63
64     /** Parameter to get all deleted resources. */
65     public static final String JavaDoc PARAM_DELETED = "deleted";
66
67     /** Parameter to get all modified resources. */
68     public static final String JavaDoc PARAM_MODIFIED = "modified";
69
70     /** Parameter to get all new resources. */
71     public static final String JavaDoc PARAM_NEW = "new";
72
73     /** The log object for this class. */
74     private static final Log LOG = CmsLog.getLog(CmsProjectFilesCollector.class);
75
76     /** The collector name. */
77     private String JavaDoc m_collectorName;
78
79     /** The colelctor parameter. */
80     private String JavaDoc m_collectorParameter;
81
82     /** Sort order. Not used yet. */
83     private int m_order;
84
85     /**
86      * Constructor, creates a new CmsProjectFilesCollector.<p>
87      */

88     public CmsProjectFilesCollector() {
89
90         m_collectorName = COLLECTOR_NAME;
91         m_collectorParameter = PARAM_MODIFIED + "|0";
92         m_order = 0;
93     }
94
95     /**
96      * @see java.lang.Comparable#compareTo(java.lang.Object)
97      */

98     public int compareTo(Object JavaDoc arg0) {
99
100         return 0;
101     }
102
103     /**
104      * @see org.opencms.file.collectors.I_CmsResourceCollector#getCollectorNames()
105      */

106     public List JavaDoc getCollectorNames() {
107
108         List JavaDoc names = new ArrayList JavaDoc();
109         names.add(COLLECTOR_NAME);
110         return names;
111     }
112
113     /**
114      * @see org.opencms.file.collectors.I_CmsResourceCollector#getCreateLink(org.opencms.file.CmsObject)
115      */

116     public String JavaDoc getCreateLink(CmsObject cms) {
117
118         return null;
119     }
120
121     /**
122      * @see org.opencms.file.collectors.I_CmsResourceCollector#getCreateLink(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
123      */

124     public String JavaDoc getCreateLink(CmsObject cms, String JavaDoc collectorName, String JavaDoc param) {
125
126         return null;
127     }
128
129     /**
130      * @see org.opencms.file.collectors.I_CmsResourceCollector#getCreateParam(org.opencms.file.CmsObject)
131      */

132     public String JavaDoc getCreateParam(CmsObject cms) {
133
134         return null;
135     }
136
137     /**
138      * @see org.opencms.file.collectors.I_CmsResourceCollector#getCreateParam(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
139      */

140     public String JavaDoc getCreateParam(CmsObject cms, String JavaDoc collectorName, String JavaDoc param) {
141
142         return null;
143     }
144
145     /**
146      * @see org.opencms.file.collectors.I_CmsResourceCollector#getDefaultCollectorName()
147      */

148     public String JavaDoc getDefaultCollectorName() {
149
150         return m_collectorName;
151     }
152
153     /**
154      * @see org.opencms.file.collectors.I_CmsResourceCollector#getDefaultCollectorParam()
155      */

156     public String JavaDoc getDefaultCollectorParam() {
157
158         return m_collectorParameter;
159     }
160
161     /**
162      * @see org.opencms.file.collectors.I_CmsResourceCollector#getOrder()
163      */

164     public int getOrder() {
165
166         return m_order;
167     }
168
169     /**
170      * @see org.opencms.file.collectors.I_CmsResourceCollector#getResults(org.opencms.file.CmsObject)
171      */

172     public List JavaDoc getResults(CmsObject cms) {
173
174         return getResults(cms, COLLECTOR_NAME, m_collectorParameter);
175     }
176
177     /**
178      * @see org.opencms.file.collectors.I_CmsResourceCollector#getResults(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
179      * The parameter must follow the syntax "mode|projectId" where mode is either "new", "changed", "deleted"
180      * or "modified" and projectId is the id of the project to be displayed.
181      */

182     public List JavaDoc getResults(CmsObject cms, String JavaDoc collectorName, String JavaDoc parameter) {
183
184         if (parameter == null) {
185             parameter = m_collectorParameter;
186         }
187
188         List JavaDoc params = CmsStringUtil.splitAsList(parameter, "|");
189         String JavaDoc param = (String JavaDoc)params.get(0);
190         String JavaDoc projectId = (String JavaDoc)params.get(1);
191
192         int state;
193         if (param.equals(PARAM_NEW)) {
194             state = CmsResource.STATE_NEW;
195         } else if (param.equals(PARAM_CHANGED)) {
196             state = CmsResource.STATE_CHANGED;
197         } else if (param.equals(PARAM_DELETED)) {
198             state = CmsResource.STATE_DELETED;
199         } else {
200             state = CmsResource.STATE_KEEP;
201         }
202
203         // show files in the selected project with the selected status
204
try {
205             return cms.readProjectView(new Integer JavaDoc(projectId).intValue(), state);
206         } catch (CmsException e) {
207             // should usually never happen
208
if (LOG.isInfoEnabled()) {
209                 LOG.info(e);
210             }
211             return Collections.EMPTY_LIST;
212         }
213     }
214
215     /**
216      * @see org.opencms.file.collectors.I_CmsResourceCollector#setDefaultCollectorName(java.lang.String)
217      */

218     public void setDefaultCollectorName(String JavaDoc collectorName) {
219
220         m_collectorName = collectorName;
221     }
222
223     /**
224      * @see org.opencms.file.collectors.I_CmsResourceCollector#setDefaultCollectorParam(java.lang.String)
225      * The parameter must follow the syntax "mode|projectId" where mode is either "new", "changed", "deleted"
226      * or "modified" and projectId is the id of the project to be displayed.
227      */

228     public void setDefaultCollectorParam(String JavaDoc param) {
229
230         m_collectorParameter = param;
231     }
232
233     /**
234      * @see org.opencms.file.collectors.I_CmsResourceCollector#setOrder(int)
235      */

236     public void setOrder(int order) {
237
238         m_order = order;
239     }
240
241 }
242
Popular Tags