KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > workplace > CmsAdminModuleExport


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminModuleExport.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
4 * Version: $Revision: 1.4 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
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 OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */

28
29 package com.opencms.workplace;
30
31 import org.opencms.file.CmsObject;
32 import org.opencms.main.CmsException;
33 import org.opencms.main.CmsLog;
34 import org.opencms.main.CmsSystemInfo;
35 import org.opencms.main.OpenCms;
36 import org.opencms.module.CmsModuleImportExportHandler;
37 import org.opencms.report.A_CmsReportThread;
38 import org.opencms.workplace.threads.CmsExportThread;
39
40 import com.opencms.core.I_CmsSession;
41 import com.opencms.legacy.CmsXmlTemplateLoader;
42
43 import java.util.ArrayList JavaDoc;
44 import java.util.Hashtable JavaDoc;
45 import java.util.Iterator JavaDoc;
46 import java.util.List JavaDoc;
47
48 /**
49  * Template class for displaying OpenCms workplace administration module create.
50  *
51  * Creation date: (27.10.00 10:28:08)
52  * @author Hanjo Riege
53  * @author Thomas Weckert
54  *
55  * @deprecated Will not be supported past the OpenCms 6 release.
56  */

57 public class CmsAdminModuleExport extends CmsWorkplaceDefault {
58
59     private final String JavaDoc C_MODULE = "module";
60     private final String JavaDoc C_MODULENAME = "modulename";
61     private final String JavaDoc C_ACTION = "action";
62     private final String JavaDoc C_MODULE_THREAD = "modulethread";
63
64     private static final int C_MINIMUM_MODULE_RESOURCE_COUNT = 1;
65
66     private static final int DEBUG = 0;
67
68     /**
69      * Collects all resources of a module to be exported in a string array. By setting the module property
70      * "additional_folders" as a folder list separated by ";", you can specify folders outside the
71      * "system/modules" directory to be exported with the module!
72      *
73      * @see #getContent(CmsObject, String, String, Hashtable, String)
74      * @param cms CmsObject Object for accessing system resources.
75      * @param templateFile Filename of the template file.
76      * @param elementName Element name of this template in our parent template.
77      * @param parameters Hashtable with all template class parameters.
78      * @param templateSelector template section that should be processed.
79      */

80     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
81         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
82             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
83             CmsLog.getLog(this).debug("Template file is: " + templateFile);
84             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
85         }
86         
87         CmsXmlWpTemplateFile xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
88         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
89
90         String JavaDoc step = (String JavaDoc) parameters.get(C_ACTION);
91         String JavaDoc moduleName = (String JavaDoc) parameters.get(C_MODULENAME);
92                
93         if (step == null) {
94             // first call
95
xmlTemplateDocument.setData("modulename", (String JavaDoc)parameters.get(C_MODULE));
96             
97         } else if("showResult".equals(step)){
98             if (DEBUG > 1) System.out.println("showResult for export");
99                      
100             // first look if there is already a thread running.
101
A_CmsReportThread doTheWork = (A_CmsReportThread)session.getValue(C_MODULE_THREAD);
102             if(doTheWork.isAlive()){
103                 if (DEBUG > 1) System.out.println("showResult: thread is still running");
104                 // thread is still running
105
xmlTemplateDocument.setData("endMethod", "");
106                 xmlTemplateDocument.setData("text", "");
107             }else{
108                 if (DEBUG > 1) System.out.println("showResult: thread is finished");
109                 // thread is finished, activate the buttons
110
xmlTemplateDocument.setData("endMethod", xmlTemplateDocument.getDataValue("endMethod"));
111                 xmlTemplateDocument.setData("autoUpdate","");
112                 xmlTemplateDocument.setData("text", xmlTemplateDocument.getLanguageFile().getLanguageValue("module.lable.exportend"));
113                 session.removeValue(C_MODULE_THREAD);
114             }
115             xmlTemplateDocument.setData("data", doTheWork.getReportUpdate());
116             return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "updateReport");
117                   
118         } else if ("ok".equals(step)) {
119             // export is confirmed
120
String JavaDoc[] resourcen = null;
121
122             // check if all resources exists and can be read
123
List JavaDoc resList = OpenCms.getModuleManager().getModule(moduleName).getResources();
124             ArrayList JavaDoc resListCopy = new ArrayList JavaDoc();
125             for (Iterator JavaDoc it = resList.iterator(); it.hasNext(); ) {
126                 String JavaDoc res = (String JavaDoc)it.next();
127                 try {
128                     if (res != null) {
129                         if (DEBUG > 0) {
130                             System.err.println("reading file header of: " + res);
131                         }
132                         cms.readResource(res);
133                         resListCopy.add(res);
134                     }
135                 }
136                 catch (CmsException e) {
137                     // resource did not exist / could not be read
138
if (CmsLog.getLog(this).isErrorEnabled()) {
139                         CmsLog.getLog(this).error("Error exporting module: couldn't add " + res + " to Module", e);
140                     }
141                     if (DEBUG > 0) {
142                         System.err.println("couldn't add " + res);
143                     }
144                 }
145             }
146             resourcen = new String JavaDoc[resListCopy.size()];
147             for (int count=0; count < resListCopy.size(); count++ ) {
148                 resourcen[count] = (String JavaDoc)resListCopy.get(count);
149                 if (DEBUG > 0) {
150                     System.err.println("exporting " + resourcen[count]);
151                 }
152             }
153             
154             String JavaDoc filename =
155                 OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(
156                     OpenCms.getSystemInfo().getPackagesRfsPath() + CmsSystemInfo.FOLDER_MODULES + moduleName + "_"
157                     + OpenCms.getModuleManager().getModule(moduleName).getVersion().toString());
158             
159             CmsModuleImportExportHandler moduleExportHandler = new CmsModuleImportExportHandler();
160             moduleExportHandler.setFileName(filename);
161             moduleExportHandler.setModuleName(moduleName.replace('\\', '/'));
162             moduleExportHandler.setAdditionalResources(resourcen);
163             moduleExportHandler.setDescription("Module export of " + moduleExportHandler.getModuleName());
164             
165             A_CmsReportThread doExport = new CmsExportThread(cms, moduleExportHandler, true);
166             doExport.start();
167             session.putValue(C_MODULE_THREAD, doExport);
168             xmlTemplateDocument.setData("time", "5");
169             templateSelector = "showresult";
170         }
171
172         // now load the template file and start the processing
173
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
174     }
175
176     /**
177      * Indicates if the results of this class are cacheable.
178      *
179      * @param cms CmsObject Object for accessing system resources
180      * @param templateFile Filename of the template file
181      * @param elementName Element name of this template in our parent template.
182      * @param parameters Hashtable with all template class parameters.
183      * @param templateSelector template section that should be processed.
184      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
185      */

186     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
187         return false;
188     }
189 }
190
Free Books   Free Magazines  
Popular Tags