KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/loader/CmsTemplateLoaderFacade.java,v $
3  * Date : $Date: 2005/06/23 11:11:28 $
4  * Version: $Revision: 1.8 $
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.CmsResource;
35
36 /**
37  * Facade object that provides access to the template loader for a resource.<p>
38  *
39  * Some resource types are actually not loadable themself but require a template
40  * to be processed. This template is attached using the <code>template</code> property.
41  * Depending on the resource type of the template itself, a loader is then selected that
42  * processed the requested resource. The processing itself might start on the template,
43  * or on the requested resource (this will depend on the loader and the resource type implementation).<p>
44  *
45  * @author Alexander Kandzior
46  *
47  * @version $Revision: 1.8 $
48  *
49  * @since 6.0.0
50  */

51 public class CmsTemplateLoaderFacade {
52
53     /** The resource loader. */
54     private I_CmsResourceLoader m_loader;
55     
56     /** The resource requested by the user. */
57     private CmsResource m_resource;
58     
59     /** The template file attached to the resource. */
60     private CmsResource m_template;
61     
62     /**
63      * Creates a new template loader facade.<p>
64      *
65      * Some resource types are actually not loadable themself but require a template
66      * to be processed. This template is attached using the <code>template</code> property.
67      * Depending on the resource type of the template itself, a loader is then selected that
68      * processed the requested resource. The processing itself might start on the template,
69      * or on the requested resource (this will depend on the loader and the resource type implementation).<p>
70      *
71      * @param loader the loader to use
72      * @param resource the file to use
73      * @param template the template to use (ignored if null)
74      * @throws CmsLoaderException in case the template file does not use a loader that actually supports templates
75      */

76     public CmsTemplateLoaderFacade(I_CmsResourceLoader loader, CmsResource resource, CmsResource template) throws CmsLoaderException {
77         if (! loader.isUsableForTemplates()) {
78             throw new CmsLoaderException(Messages.get().container(Messages.ERR_LOADER_NOT_TEMPLATE_ENABLED_0));
79         }
80         m_loader = loader;
81         m_resource = resource;
82         m_template = template;
83     }
84
85     /**
86      * Returns the loader.<p>
87      *
88      * @return the loader
89      */

90     public I_CmsResourceLoader getLoader() {
91         return m_loader;
92     }
93         
94     /**
95      * Returns the loaders start resource.<p>
96      *
97      * @return the loaders start resource
98      */

99     public CmsResource getLoaderStartResource() {
100         if (m_loader.isUsingUriWhenLoadingTemplate()) {
101             return m_resource;
102         } else {
103             return m_template;
104         }
105     }
106     
107     /**
108      * Returns the resource.<p>
109      *
110      * @return the resource
111      */

112     public CmsResource getResource() {
113         return m_resource;
114     }
115     
116     /**
117      * Returns the template.<p>
118      *
119      * @return the template
120      */

121     public CmsResource getTemplate() {
122         return m_template;
123     }
124
125 }
Popular Tags