KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > loader > CmsPointerLoader


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/loader/CmsPointerLoader.java,v $
3  * Date : $Date: 2006/03/27 14:52:37 $
4  * Version: $Revision: 1.50 $
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.loader;
33
34 import org.opencms.file.CmsFile;
35 import org.opencms.file.CmsObject;
36 import org.opencms.file.CmsResource;
37 import org.opencms.main.CmsException;
38 import org.opencms.main.CmsLog;
39 import org.opencms.main.CmsRuntimeException;
40 import org.opencms.main.OpenCms;
41 import org.opencms.util.CmsStringUtil;
42
43 import java.io.IOException JavaDoc;
44 import java.util.Locale JavaDoc;
45 import java.util.Map JavaDoc;
46
47 import javax.servlet.ServletRequest JavaDoc;
48 import javax.servlet.ServletResponse JavaDoc;
49 import javax.servlet.http.HttpServletRequest JavaDoc;
50 import javax.servlet.http.HttpServletResponse JavaDoc;
51
52 /**
53  * Loader for "pointers" to resources in the VFS or to external resources.<p>
54  *
55  * @author Alexander Kandzior
56  *
57  * @version $Revision: 1.50 $
58  *
59  * @since 6.0.0
60  */

61 public class CmsPointerLoader implements I_CmsResourceLoader {
62
63     /** The id of this loader. */
64     public static final int RESOURCE_LOADER_ID = 4;
65
66     /** The html-code prefix for generating the export file for external links. */
67     private static String JavaDoc EXPORT_PREFIX = "<html>\n<head>\n<meta http-equiv="
68         + '"'
69         + "refresh"
70         + '"'
71         + " content="
72         + '"'
73         + "0; url=";
74
75     /** The html-code suffix for generating the export file for external links. */
76     private static String JavaDoc EXPORT_SUFFIX = '"' + ">\n</head>\n<body></body>\n</html>";
77
78     /**
79      * The constructor of the class is empty and does nothing.<p>
80      */

81     public CmsPointerLoader() {
82
83         // NOOP
84
}
85
86     /**
87      * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#addConfigurationParameter(java.lang.String, java.lang.String)
88      */

89     public void addConfigurationParameter(String JavaDoc paramName, String JavaDoc paramValue) {
90
91         // this resource loader requires no parameters
92
}
93
94     /**
95      * Destroy this ResourceLoder, this is a NOOP so far.<p>
96      */

97     public void destroy() {
98
99         // NOOP
100
}
101
102     /**
103      * @see org.opencms.loader.I_CmsResourceLoader#dump(org.opencms.file.CmsObject, org.opencms.file.CmsResource, java.lang.String, java.util.Locale, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
104      */

105     public byte[] dump(
106         CmsObject cms,
107         CmsResource resource,
108         String JavaDoc element,
109         Locale JavaDoc locale,
110         HttpServletRequest JavaDoc req,
111         HttpServletResponse JavaDoc res) throws CmsException {
112
113         return CmsFile.upgrade(resource, cms).getContents();
114     }
115
116     /**
117      * @see org.opencms.loader.I_CmsResourceLoader#export(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
118      */

119     public byte[] export(CmsObject cms, CmsResource resource, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
120     throws IOException JavaDoc, CmsException {
121
122         String JavaDoc pointer = new String JavaDoc(CmsFile.upgrade(resource, cms).getContents());
123         StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
124         result.append(EXPORT_PREFIX);
125         if (pointer.indexOf(':') < 0) {
126             result.append(OpenCms.getLinkManager().substituteLink(cms, pointer));
127         } else {
128             result.append(pointer);
129         }
130         result.append(EXPORT_SUFFIX);
131         load(cms, resource, req, res);
132         return result.toString().getBytes(OpenCms.getSystemInfo().getDefaultEncoding());
133     }
134
135     /**
136      * Will always return <code>null</code> since this loader does not
137      * need to be cnofigured.<p>
138      *
139      * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#getConfiguration()
140      */

141     public Map JavaDoc getConfiguration() {
142
143         return null;
144     }
145
146     /**
147      * @see org.opencms.loader.I_CmsResourceLoader#getLoaderId()
148      */

149     public int getLoaderId() {
150
151         return RESOURCE_LOADER_ID;
152     }
153
154     /**
155      * Return a String describing the ResourceLoader,
156      * which is (localized to the system default locale)
157      * <code>"The OpenCms default resource loader for pointers"</code>.<p>
158      *
159      * @return a describing String for the ResourceLoader
160      */

161     public String JavaDoc getResourceLoaderInfo() {
162
163         return Messages.get().getBundle().key(Messages.GUI_LOADER_POINTER_DEFAULT_DESC_0);
164     }
165
166     /**
167      * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#initConfiguration()
168      */

169     public void initConfiguration() {
170
171         if (CmsLog.INIT.isInfoEnabled()) {
172             CmsLog.INIT.info(Messages.get().getBundle().key(
173                 Messages.INIT_LOADER_INITIALIZED_1,
174                 this.getClass().getName()));
175         }
176     }
177
178     /**
179      * @see org.opencms.loader.I_CmsResourceLoader#isStaticExportEnabled()
180      */

181     public boolean isStaticExportEnabled() {
182
183         return true;
184     }
185
186     /**
187      * @see org.opencms.loader.I_CmsResourceLoader#isStaticExportProcessable()
188      */

189     public boolean isStaticExportProcessable() {
190
191         return false;
192     }
193
194     /**
195      * @see org.opencms.loader.I_CmsResourceLoader#isUsableForTemplates()
196      */

197     public boolean isUsableForTemplates() {
198
199         return false;
200     }
201
202     /**
203      * @see org.opencms.loader.I_CmsResourceLoader#isUsingUriWhenLoadingTemplate()
204      */

205     public boolean isUsingUriWhenLoadingTemplate() {
206
207         return false;
208     }
209
210     /**
211      * @see org.opencms.loader.I_CmsResourceLoader#load(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
212      */

213     public void load(CmsObject cms, CmsResource resource, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
214     throws IOException JavaDoc, CmsException {
215
216         if (res == null || res.isCommitted()) {
217             // nothing we can do
218
return;
219         }
220
221         String JavaDoc pointer = new String JavaDoc(CmsFile.upgrade(resource, cms).getContents());
222         if (CmsStringUtil.isEmptyOrWhitespaceOnly(pointer)) {
223             throw new CmsLoaderException(Messages.get().container(
224                 Messages.ERR_INVALID_POINTER_FILE_1,
225                 resource.getName()));
226         }
227         if (pointer.indexOf(':') < 0) {
228             pointer = OpenCms.getLinkManager().substituteLink(cms, pointer);
229         }
230
231         res.sendRedirect(pointer);
232     }
233
234     /**
235      * @see org.opencms.loader.I_CmsResourceLoader#service(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.ServletRequest, javax.servlet.ServletResponse)
236      */

237     public void service(CmsObject cms, CmsResource file, ServletRequest JavaDoc req, ServletResponse JavaDoc res) {
238
239         throw new CmsRuntimeException(
240             Messages.get().container(Messages.ERR_SERVICE_UNSUPPORTED_1, getClass().getName()));
241     }
242 }
Popular Tags