KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminStaticExport.java,v $
3 * Date : $Date: 2005/07/08 17:42:47 $
4 * Version: $Revision: 1.5 $
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.i18n.CmsEncoder;
33 import org.opencms.main.CmsException;
34 import org.opencms.main.CmsLog;
35 import org.opencms.main.OpenCms;
36 import org.opencms.report.A_CmsReportThread;
37 import org.opencms.workplace.tools.database.CmsStaticExportThread;
38
39 import com.opencms.core.I_CmsSession;
40 import com.opencms.legacy.CmsXmlTemplateLoader;
41
42 import java.util.Hashtable JavaDoc;
43 import java.util.Vector JavaDoc;
44
45 import org.apache.oro.text.perl.Perl5Util;
46
47 /**
48  * Template class for displaying OpenCms workplace admin static export.
49  * <P>
50  *
51  * @author Hanjo Riege
52  * @version $Revision: 1.5 $
53  * @see com.opencms.workplace.CmsXmlWpTemplateFile
54  *
55  * @deprecated Will not be supported past the OpenCms 6 release.
56  */

57
58 public class CmsAdminStaticExport extends CmsWorkplaceDefault {
59
60     private static String JavaDoc C_STATICEXPORT_THREAD = "static_export_thread";
61
62     /**
63      * Gets the content of a defined section in a given template file and its subtemplates
64      * with the given parameters.
65      *
66      * @see #getContent(CmsObject, String, String, Hashtable, String)
67      * @param cms CmsObject Object for accessing system resources.
68      * @param templateFile Filename of the template file.
69      * @param elementName Element name of this template in our parent template.
70      * @param parameters Hashtable with all template class parameters.
71      * @param templateSelector template section that should be processed.
72      */

73
74     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
75             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
76         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
77             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
78             CmsLog.getLog(this).debug("Template file is: " + templateFile);
79             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
80         }
81
82         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
83         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
84         CmsXmlLanguageFile lang = xmlTemplateDocument.getLanguageFile();
85
86         // get the parameters
87
String JavaDoc action = (String JavaDoc)parameters.get("action");
88
89         // here we show the report updates when the threads are allready running.
90
if("showResult".equals(action)){
91             // ok. Thread is started and we shoud show the report information.
92
A_CmsReportThread doTheWork = (A_CmsReportThread)session.getValue(C_STATICEXPORT_THREAD);
93             //still working?
94
if(doTheWork.isAlive()){
95                 xmlTemplateDocument.setData("endMethod", "");
96                 xmlTemplateDocument.setData("text", "");
97             }else{
98                 xmlTemplateDocument.setData("endMethod", xmlTemplateDocument.getDataValue("endMethod"));
99                 xmlTemplateDocument.setData("autoUpdate","");
100                 xmlTemplateDocument.setData("text", lang.getLanguageValue("staticexport.label.exportend"));
101             }
102             xmlTemplateDocument.setData("data", doTheWork.getReportUpdate());
103             return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "updateReport");
104         }
105         if(action == null || "dynPrint".equals(action)) {
106             // This is an initial request of the static export page
107
Vector JavaDoc exportStartPoints = null;
108             String JavaDoc allStartPoints = "";
109             if(exportStartPoints != null){
110                 for(int i=0; i<exportStartPoints.size(); i++){
111                     xmlTemplateDocument.setData("entry", (String JavaDoc)exportStartPoints.elementAt(i));
112                     allStartPoints += xmlTemplateDocument.getProcessedDataValue("exportpoint");
113                 }
114             }
115             xmlTemplateDocument.setData("exportpoints", allStartPoints);
116             xmlTemplateDocument.setData("path", OpenCms.getStaticExportManager().getExportPath(null));
117         }
118
119         // special feature to test the regular expressions
120
if((action != null) && ("regTest".equals(action))) {
121             String JavaDoc sub = (String JavaDoc)parameters.get("sub");
122             String JavaDoc link = "";
123             String JavaDoc regExpr = "";
124             String JavaDoc result = "";
125             if(sub != null && "true".equals(sub)){
126                 link = (String JavaDoc)parameters.get("link");
127                 regExpr = (String JavaDoc)parameters.get("regExpr");
128                 try{
129                     Perl5Util subClass = new Perl5Util();
130                     result = subClass.substitute(regExpr, link);
131                 }catch(Exception JavaDoc e){
132                     result = "error: "+ e.getMessage();
133                 }
134             }
135             xmlTemplateDocument.setData("link", CmsEncoder.escape(link,
136                 cms.getRequestContext().getEncoding()));
137             xmlTemplateDocument.setData("regExpr", CmsEncoder.escape(regExpr,
138                 cms.getRequestContext().getEncoding()));
139             xmlTemplateDocument.setData("result", CmsEncoder.escape(result,
140                 cms.getRequestContext().getEncoding()));
141             return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "regTest");
142         }
143
144         // first we look if the thread is allready running
145
if((action != null) && ("working".equals(action))) {
146             // still working?
147
A_CmsReportThread doTheWork = (A_CmsReportThread)session.getValue(C_STATICEXPORT_THREAD);
148             if(doTheWork.isAlive()) {
149                 String JavaDoc time = (String JavaDoc)parameters.get("time");
150                 int wert = Integer.parseInt(time);
151                 wert += 20;
152                 xmlTemplateDocument.setData("time", "" + wert);
153                 return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "wait");
154             }else {
155                 // thread has come to an end, was there an error?
156
String JavaDoc errordetails = (String JavaDoc)session.getValue(com.opencms.core.I_CmsConstants.C_SESSION_THREAD_ERROR);
157                 session.removeValue(com.opencms.core.I_CmsConstants.C_SESSION_THREAD_ERROR);
158                 if(errordetails == null) {
159                     // export ready
160
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "done");
161                 }else {
162                     // get errorpage:
163
xmlTemplateDocument.setData("details", errordetails);
164                     return startProcessing(cms, xmlTemplateDocument, elementName, parameters, "error");
165                 }
166             }
167         }
168         if("export".equals(action)) {
169
170             // start the thread for export
171
// first clear the session entry if necessary
172
if(session.getValue(com.opencms.core.I_CmsConstants.C_SESSION_THREAD_ERROR) != null) {
173                 session.removeValue(com.opencms.core.I_CmsConstants.C_SESSION_THREAD_ERROR);
174             }
175             A_CmsReportThread doExport = new CmsStaticExportThread(cms);
176             doExport.start();
177             session.putValue(C_STATICEXPORT_THREAD , doExport);
178             xmlTemplateDocument.setData("time", "10");
179             templateSelector = "showresult";
180         }
181
182         // Now load the template file and start the processing
183
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
184     }
185
186
187     /**
188      * Indicates if the results of this class are cacheable.
189      *
190      * @param cms CmsObject Object for accessing system resources
191      * @param templateFile Filename of the template file
192      * @param elementName Element name of this template in our parent template.
193      * @param parameters Hashtable with all template class parameters.
194      * @param templateSelector template section that should be processed.
195      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
196      */

197     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
198             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
199         return false;
200     }
201
202     /**
203      * Returns <code>true</code> if the staticExport is enabled,
204      * the current project is the online project
205      * and the current user is in the project manager group.<p>
206      *
207      * This method is used by workplace icons to decide whether the icon should
208      * be activated or not. Icons will use this method if the attribute <code>method="isExportActive"</code>
209      * is defined in the <code>&lt;ICON&gt;</code> tag.
210      *
211      * @param cms for accessing system resources <em>(not used here)</em>
212      * @param lang reference to the currently valid language file <em>(not used here)</em>
213      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>
214      * @return (see method description)
215      * @throws CmsException if there were errors while accessing project data
216      */

217     public Boolean JavaDoc isExportActive(CmsObject cms, CmsXmlLanguageFile lang, Hashtable JavaDoc parameters) throws CmsException {
218         boolean isProMan = isProjectManager(cms, lang, parameters).booleanValue();
219         return new Boolean JavaDoc(OpenCms.getStaticExportManager().isStaticExportEnabled() && isProMan);
220     }
221
222     /**
223      * Returns <code>true</code> if the staticExport is enabled,
224      * the current project is the online project
225      * and the current user is in the administrator group.<p>
226      *
227      * This method is used by workplace icons to decide whether the icon should
228      * be activated or not. Icons will use this method if the attribute <code>method="isExportActiveAdmin"</code>
229      * is defined in the <code>&lt;ICON&gt;</code> tag.
230      *
231      * @param cms for accessing system resources <em>(not used here)</em>
232      * @param lang reference to the currently valid language file <em>(not used here)</em>
233      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>
234      * @return (see method description)
235      * @throws CmsException if there were errors while accessing project data
236      */

237     public Boolean JavaDoc isExportActiveAdmin(CmsObject cms, CmsXmlLanguageFile lang, Hashtable JavaDoc parameters) throws CmsException {
238         boolean isAdmin = isAdmin(cms, lang, parameters).booleanValue();
239         return new Boolean JavaDoc(OpenCms.getStaticExportManager().isStaticExportEnabled() && isAdmin);
240     }
241 }
Popular Tags