KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/editors/CmsEditorHandler.java,v $
3  * Date : $Date: 2006/04/28 15:20:52 $
4  * Version: $Revision: 1.13 $
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.file.CmsResource;
35 import org.opencms.file.CmsResourceFilter;
36 import org.opencms.file.types.CmsResourceTypePlain;
37 import org.opencms.jsp.CmsJspActionElement;
38 import org.opencms.main.CmsException;
39 import org.opencms.main.CmsLog;
40 import org.opencms.main.OpenCms;
41 import org.opencms.util.CmsRequestUtil;
42
43 import org.apache.commons.logging.Log;
44
45 /**
46  * This editor handler class returns the editor URI depending on various factors.<p>
47  *
48  * Editor selection criteria:
49  * <ul>
50  * <li>the user preferences</li>
51  * <li>the users current browser</li>
52  * <li>the resource type</li>
53  * </ul>
54  * <p>
55  *
56  * @author Andreas Zahner
57  *
58  * @version $Revision: 1.13 $
59  *
60  * @since 6.0.0
61  *
62  * @see org.opencms.workplace.editors.I_CmsEditorHandler
63  * @see org.opencms.workplace.editors.CmsWorkplaceEditorManager
64  */

65 public class CmsEditorHandler implements I_CmsEditorHandler {
66
67     /** The log object for this class. */
68     private static final Log LOG = CmsLog.getLog(CmsEditorHandler.class);
69
70     /**
71      * @see org.opencms.workplace.editors.I_CmsEditorHandler#getEditorUri(java.lang.String, CmsJspActionElement)
72      */

73     public String JavaDoc getEditorUri(String JavaDoc resource, CmsJspActionElement jsp) throws CmsException {
74
75         // first try to get the "edit as text" and "load default" parameters from the request
76
boolean editAsText = Boolean.valueOf(jsp.getRequest().getParameter(CmsEditor.PARAM_EDITASTEXT)).booleanValue();
77         boolean loadDefault = Boolean.valueOf(jsp.getRequest().getParameter(CmsEditor.PARAM_LOADDEFAULT)).booleanValue();
78         // initialize resource type with -1 (unknown resource type)
79
int resTypeId = -1;
80         String JavaDoc resourceType = "";
81         if (editAsText) {
82             // the resource should be treated as text, set the plain resource id
83
resTypeId = CmsResourceTypePlain.getStaticTypeId();
84         } else {
85             // get the resource type id of the edited resource
86
CmsResource res = jsp.getCmsObject().readResource(resource, CmsResourceFilter.ALL);
87             resTypeId = res.getTypeId();
88         }
89
90         // get the resource type name
91
resourceType = OpenCms.getResourceManager().getResourceType(resTypeId).getTypeName();
92
93         // get the editor URI from the editor manager
94
String JavaDoc editorUri = null;
95
96         // get the browser identification from the request
97
String JavaDoc userAgent = jsp.getRequest().getHeader(CmsRequestUtil.HEADER_USER_AGENT);
98
99         if (loadDefault) {
100             // get default editor because loaddefault parameter was found
101
editorUri = OpenCms.getWorkplaceManager().getWorkplaceEditorManager().getDefaultEditorUri(
102                 jsp.getRequestContext(),
103                 resourceType,
104                 userAgent);
105         } else {
106             // get preferred editor
107
editorUri = OpenCms.getWorkplaceManager().getWorkplaceEditorManager().getEditorUri(
108                 jsp.getRequestContext(),
109                 resourceType,
110                 userAgent);
111         }
112
113         try {
114             // check the presence of the editor
115
jsp.getCmsObject().readResource(editorUri);
116         } catch (Throwable JavaDoc t) {
117             // preferred or selected editor not found, try default editor
118
if (LOG.isInfoEnabled()) {
119                 LOG.info(t);
120             }
121             editorUri = OpenCms.getWorkplaceManager().getWorkplaceEditorManager().getDefaultEditorUri(
122                 jsp.getRequestContext(),
123                 resourceType,
124                 userAgent);
125         }
126
127         return editorUri;
128     }
129
130 }
131
Popular Tags