KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > modules > CmsModulesListExportReport


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/modules/CmsModulesListExportReport.java,v $
3  * Date : $Date: 2006/03/27 14:52:53 $
4  * Version: $Revision: 1.10 $
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.modules;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.CmsException;
36 import org.opencms.main.CmsSystemInfo;
37 import org.opencms.main.OpenCms;
38 import org.opencms.module.CmsModuleImportExportHandler;
39 import org.opencms.report.I_CmsReportThread;
40 import org.opencms.workplace.list.A_CmsListReport;
41 import org.opencms.workplace.threads.CmsExportThread;
42
43 import java.util.ArrayList JavaDoc;
44 import java.util.Iterator JavaDoc;
45 import java.util.List JavaDoc;
46
47 import javax.servlet.http.HttpServletRequest JavaDoc;
48 import javax.servlet.http.HttpServletResponse JavaDoc;
49 import javax.servlet.jsp.PageContext JavaDoc;
50
51 /**
52  * Provides a report for exporting modules.<p>
53  *
54  * @author Michael Emmerich
55  *
56  * @version $Revision: 1.10 $
57  *
58  * @since 6.0.0
59  */

60 public class CmsModulesListExportReport extends A_CmsListReport {
61
62     /** Modulename. */
63     private String JavaDoc m_paramModule;
64
65     /**
66      * Public constructor with JSP action element.<p>
67      *
68      * @param jsp an initialized JSP action element
69      */

70     public CmsModulesListExportReport(CmsJspActionElement jsp) {
71
72         super(jsp);
73     }
74
75     /**
76      * Public constructor with JSP variables.<p>
77      *
78      * @param context the JSP page context
79      * @param req the JSP request
80      * @param res the JSP response
81      */

82     public CmsModulesListExportReport(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
83
84         this(new CmsJspActionElement(context, req, res));
85     }
86
87     /**
88      * Gets the module parameter.<p>
89      *
90      * @return the module parameter
91      */

92     public String JavaDoc getParamModule() {
93
94         return m_paramModule;
95     }
96
97     /**
98      *
99      * @see org.opencms.workplace.list.A_CmsListReport#initializeThread()
100      */

101     public I_CmsReportThread initializeThread() {
102
103         I_CmsReportThread exportThread = new CmsExportThread(getCms(), getExportHandler(), false);
104
105         return exportThread;
106     }
107
108     /**
109      * Sets the module parameter.<p>
110      * @param paramModule the module parameter
111      */

112     public void setParamModule(String JavaDoc paramModule) {
113
114         m_paramModule = paramModule;
115     }
116
117     /**
118      * Gets the module export handler containing all resources used in the module export.<p>
119      * @return CmsModuleImportExportHandler with all module resources
120      */

121     private CmsModuleImportExportHandler getExportHandler() {
122
123         String JavaDoc moduleName = getParamModule();
124
125         // get all module resources
126
List JavaDoc resList = OpenCms.getModuleManager().getModule(moduleName).getResources();
127         // check if all resources are valid
128
ArrayList JavaDoc resListCopy = new ArrayList JavaDoc();
129         for (Iterator JavaDoc it = resList.iterator(); it.hasNext();) {
130             String JavaDoc res = (String JavaDoc)it.next();
131             try {
132                 if (res != null) {
133                     getCms().readResource(res);
134                     resListCopy.add(res);
135                 }
136             } catch (CmsException e) {
137                 // resource did not exist / could not be read
138
}
139         }
140
141         String JavaDoc[] resources = new String JavaDoc[resListCopy.size()];
142
143         for (int i = 0; i < resListCopy.size(); i++) {
144             resources[i] = (String JavaDoc)resListCopy.get(i);
145         }
146
147         String JavaDoc filename = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(
148             OpenCms.getSystemInfo().getPackagesRfsPath()
149                 + CmsSystemInfo.FOLDER_MODULES
150                 + moduleName
151                 + "_"
152                 + OpenCms.getModuleManager().getModule(moduleName).getVersion().toString());
153
154         CmsModuleImportExportHandler moduleExportHandler = new CmsModuleImportExportHandler();
155         moduleExportHandler.setFileName(filename);
156         moduleExportHandler.setModuleName(moduleName.replace('\\', '/'));
157         moduleExportHandler.setAdditionalResources(resources);
158         moduleExportHandler.setDescription(Messages.get().getBundle(getLocale()).key(
159             Messages.GUI_MODULES_LIST_EXPORT_REPORT_HANDLER_NAME_1,
160             moduleExportHandler.getModuleName()));
161
162         return moduleExportHandler;
163     }
164 }
Popular Tags