KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > editors > CmsEditorSelector


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/editors/CmsEditorSelector.java,v $
3  * Date : $Date: 2006/04/28 15:20:52 $
4  * Version: $Revision: 1.9 $
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.editors;
33
34 import org.opencms.i18n.CmsEncoder;
35 import org.opencms.jsp.CmsJspActionElement;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.CmsLog;
38 import org.opencms.main.OpenCms;
39 import org.opencms.workplace.CmsDialog;
40 import org.opencms.workplace.CmsWorkplace;
41 import org.opencms.workplace.CmsWorkplaceException;
42
43 import javax.servlet.jsp.JspException JavaDoc;
44
45 import org.apache.commons.logging.Log;
46
47 /**
48  * Selects the dialog which should be displayed by OpenCms depending on the configuration value.<p>
49  *
50  * You can define the class of your editor selector in the OpenCms XML configuration files.
51  * The following files use this class:
52  * <ul>
53  * <li>/jsp/editors/editor_main_html
54  * </ul>
55  * <p>
56  *
57  * @author Andreas Zahner
58  *
59  * @version $Revision: 1.9 $
60  *
61  * @since 6.0.0
62  *
63  * @see org.opencms.workplace.editors.I_CmsEditorHandler
64  */

65 public class CmsEditorSelector {
66
67     /** The log object for this class. */
68     private static final Log LOG = CmsLog.getLog(CmsEditorSelector.class);
69
70     /** The jsp context. */
71     private CmsJspActionElement m_jsp;
72
73     /** The name of the resource to get the editor for. */
74     private String JavaDoc m_paramResource;
75
76     /**
77      * Public constructor with JSP action element.<p>
78      *
79      * @param jsp an initialized JSP action element
80      */

81     public CmsEditorSelector(CmsJspActionElement jsp) {
82
83         setJsp(jsp);
84         setParamResource(jsp.getRequest().getParameter(CmsDialog.PARAM_RESOURCE));
85     }
86
87     /**
88      * Shows the error dialog when no valid editor is found and returns null for the editor URI.<p>
89      *
90      * @param jsp the instanciated CmsJspActionElement
91      * @param t a throwable object, can be null
92      */

93     private static void showErrorDialog(CmsJspActionElement jsp, Throwable JavaDoc t) {
94
95         CmsDialog wp = new CmsDialog(jsp);
96         wp.setParamMessage(Messages.get().getBundle(wp.getLocale()).key(Messages.ERR_NO_EDITOR_FOUND_0));
97         wp.fillParamValues(jsp.getRequest());
98         try {
99             wp.includeErrorpage(wp, t);
100         } catch (JspException JavaDoc e) {
101             LOG.debug(org.opencms.workplace.commons.Messages.get().getBundle().key(
102                 org.opencms.workplace.commons.Messages.LOG_ERROR_INCLUDE_FAILED_1,
103                 CmsWorkplace.FILE_DIALOG_SCREEN_ERRORPAGE), e);
104         }
105     }
106
107     /**
108      * Returns the uri of the dialog which will be displayed.<p>
109      *
110      * @return the uri of the property dialog
111      */

112     public String JavaDoc getSelectedEditorUri() {
113
114         // get the handler class from the OpenCms runtime property
115
I_CmsEditorHandler editorClass = OpenCms.getWorkplaceManager().getEditorHandler();
116
117         // the resourcenameparameter could be encoded, so decode it
118
String JavaDoc resource = getParamResource();
119         resource = CmsEncoder.unescape(resource, CmsEncoder.ENCODING_UTF_8);
120         if (editorClass == null) {
121             // error getting the dialog class, return to file list
122
return CmsWorkplace.FILE_EXPLORER_FILELIST;
123         }
124         // get the dialog URI from the class defined in the configuration
125
String JavaDoc editorUri = null;
126         try {
127             editorUri = editorClass.getEditorUri(resource, getJsp());
128             if (editorUri == null) {
129                 // no valid editor was found, show the error dialog
130
throw new CmsWorkplaceException(Messages.get().container(Messages.ERR_NO_EDITOR_FOUND_0));
131             }
132         } catch (CmsException e) {
133             showErrorDialog(getJsp(), e);
134         }
135         return editorUri;
136     }
137
138     /**
139      * Returns the CmsJspActionElement.<p>
140      *
141      * @return the CmsJspActionElement
142      */

143     private CmsJspActionElement getJsp() {
144
145         return m_jsp;
146     }
147
148     /**
149      * Returns the resource parameter String.<p>
150      *
151      * @return the resource parameter String
152      */

153     private String JavaDoc getParamResource() {
154
155         return m_paramResource;
156     }
157
158     /**
159      * Sets the CmsJspActionElement.<p>
160      *
161      * @param jsp the CmsJspActionElement
162      */

163     private void setJsp(CmsJspActionElement jsp) {
164
165         m_jsp = jsp;
166     }
167
168     /**
169      * Sets the resource parameter String.<p>
170      *
171      * @param resource the resource parameter String
172      */

173     private void setParamResource(String JavaDoc resource) {
174
175         m_paramResource = resource;
176     }
177
178 }
179
Popular Tags