KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > site > CmsSite


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/site/CmsSite.java,v $
3  * Date : $Date: 2006/04/28 15:20:52 $
4  * Version: $Revision: 1.24 $
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.site;
33
34 import org.opencms.util.CmsUUID;
35
36 import java.util.ArrayList JavaDoc;
37 import java.util.List JavaDoc;
38
39 /**
40  * Describes a configured site in OpenCms.<p>
41  *
42  * @author Alexander Kandzior
43  * @author Jan Baudisch
44  *
45  * @version $Revision: 1.24 $
46  *
47  * @since 6.0.0
48  */

49 public final class CmsSite implements Cloneable JavaDoc {
50
51     /** The aliases for this site, a vector of CmsSiteMatcher Objects. */
52     private List JavaDoc m_aliases;
53
54     /** If exclusive, and set to true will generate a 404 error, if set to false will redirect to secure url. */
55     private boolean m_exclusiveError;
56
57     /** If set to true, secure resources will only be available using the configured secure url. */
58     private boolean m_exclusiveUrl;
59
60     /** The Url of the secure server. */
61     private CmsSiteMatcher m_secureServer;
62
63     /** The site matcher that describes the site. */
64     private CmsSiteMatcher m_siteMatcher;
65
66     /** Root directory of this site in the OpenCms VFS. */
67     private String JavaDoc m_siteRoot;
68
69     /** UUID of this site's root directory in the OpenCms VFS. */
70     private CmsUUID m_siteRootUUID;
71
72     /** Display title of this site. */
73     private String JavaDoc m_title;
74
75     /**
76      * Constructs a new site object without title and id information,
77      * this is to be used for lookup purposes only.<p>
78      *
79      * @param siteRoot root directory of this site in the OpenCms VFS
80      * @param siteMatcher the site matcher for this site
81      */

82     public CmsSite(String JavaDoc siteRoot, CmsSiteMatcher siteMatcher) {
83
84         this(siteRoot, CmsUUID.getNullUUID(), siteRoot, siteMatcher);
85     }
86
87     /**
88      * Constructs a new site object with a default (wildcard) a site matcher,
89      * this is to be used for display purposes only.<p>
90      *
91      * @param siteRoot root directory of this site in the OpenCms VFS
92      * @param siteRootUUID UUID of this site's root directory in the OpenCms VFS
93      * @param title display name of this site
94      */

95     public CmsSite(String JavaDoc siteRoot, CmsUUID siteRootUUID, String JavaDoc title) {
96
97         this(siteRoot, siteRootUUID, title, CmsSiteMatcher.DEFAULT_MATCHER);
98     }
99
100     /**
101      * Constructs a new site object.<p>
102      *
103      * @param siteRoot root directory of this site in the OpenCms VFS
104      * @param siteRootUUID UUID of this site's root directory in the OpenCms VFS
105      * @param title display name of this site
106      * @param siteMatcher the site matcher for this site
107      */

108     public CmsSite(String JavaDoc siteRoot, CmsUUID siteRootUUID, String JavaDoc title, CmsSiteMatcher siteMatcher) {
109
110         setSiteRoot(siteRoot);
111         setSiteRootUUID(siteRootUUID);
112         setTitle(title);
113         setSiteMatcher(siteMatcher);
114         m_aliases = new ArrayList JavaDoc();
115     }
116
117     /**
118      * Hides the public default constructor.<p>
119      */

120     private CmsSite() {
121
122         // NOOP
123
}
124
125     /**
126      * Returns a clone of this Objects instance.<p>
127      *
128      * @return a clone of this instance
129      */

130     public Object JavaDoc clone() {
131
132         return new CmsSite(
133             getSiteRoot(),
134             (CmsUUID)getSiteRootUUID().clone(),
135             getTitle(),
136             (CmsSiteMatcher)getSiteMatcher().clone());
137     }
138
139     /**
140      * @see java.lang.Object#equals(java.lang.Object)
141      */

142     public boolean equals(Object JavaDoc obj) {
143
144         if (obj == this) {
145             return true;
146         }
147         if (obj instanceof CmsSite) {
148             ((CmsSite)obj).m_siteMatcher.equals(m_siteMatcher);
149         }
150         return false;
151     }
152
153     /**
154      * Returns the aliases for this site.<p>
155      *
156      * @return a ArrayList with the aliases
157      */

158     public List JavaDoc getAliases() {
159
160         return m_aliases;
161     }
162
163     /**
164      * Returns the secure server url of this site root.<p>
165      *
166      * @return the secure server url
167      */

168     public String JavaDoc getSecureUrl() {
169
170         return m_secureServer.getUrl();
171     }
172
173     /**
174      * Returns the site matcher that describes the URL of this site.<p>
175      *
176      * @return the site matcher that describes the URL of this site
177      */

178     public CmsSiteMatcher getSiteMatcher() {
179
180         return m_siteMatcher;
181     }
182
183     /**
184      * Returns the server URL prefix to which this site is mapped.<p>
185      *
186      * @return the server URL prefix to which this site is mapped
187      */

188     public String JavaDoc getSiteRoot() {
189
190         return m_siteRoot;
191     }
192
193     /**
194      * Returns the UUID of this site's root directory in the OpenCms VFS.<p>
195      *
196      * @return the UUID of this site's root directory in the OpenCms VFS
197      */

198     public CmsUUID getSiteRootUUID() {
199
200         return m_siteRootUUID;
201     }
202
203     /**
204      * Returns the root directory of this site in the OpenCms VFS.<p>
205      *
206      * @return the root directory of this site in the OpenCms VFS
207      */

208     public String JavaDoc getTitle() {
209
210         return m_title;
211     }
212
213     /**
214      * Returns the server url of this site root.<p>
215      *
216      * @return the server url
217      */

218     public String JavaDoc getUrl() {
219
220         return m_siteMatcher.getUrl();
221     }
222
223     /**
224      * @see java.lang.Object#hashCode()
225      */

226     public int hashCode() {
227
228         return m_siteRootUUID.hashCode();
229     }
230
231     /**
232      * Returns true, if the site has a secure server.<p>
233      *
234      * @return true, if the site has a secure server
235      */

236     public boolean hasSecureServer() {
237
238         return m_secureServer != null;
239     }
240
241     /**
242      * Returns the exclusive error flag.<p>
243      *
244      * @return <code>true</code> will generate a 404 error,
245      * or <code>false</code> will redirect to secure url.
246      */

247     public boolean isExclusiveError() {
248
249         return m_exclusiveError;
250     }
251
252     /**
253      * Returns the exclusive protocol flag.<p>
254      *
255      * @return <code>true</code> secure resources will only be available using the configured secure url,
256      * or <code>false</code> if the uri (protocol + servername) does not really matter.
257      */

258     public boolean isExclusiveUrl() {
259
260         return m_exclusiveUrl;
261     }
262
263     /**
264      * Sets the exclusive error flag.<p>
265      *
266      * @param error the exclusive error flag
267      */

268     public void setExclusiveError(boolean error) {
269
270         m_exclusiveError = error;
271     }
272
273     /**
274      * Sets the exclusive protocol flag.<p>
275      *
276      * @param exclusive the exclusive protocol flag
277      */

278     public void setExclusiveUrl(boolean exclusive) {
279
280         m_exclusiveUrl = exclusive;
281     }
282
283     /**
284      * @see java.lang.Object#toString()
285      */

286     public String JavaDoc toString() {
287
288         StringBuffer JavaDoc result = new StringBuffer JavaDoc(128);
289         result.append("server: ");
290         result.append(m_siteMatcher != null ? m_siteMatcher.toString() : "null");
291         result.append(" uri: ");
292         result.append(m_siteRoot);
293         result.append(" title: ");
294         result.append(m_title);
295         return result.toString();
296     }
297
298     /**
299      * Adds an alias for the site.<p>
300      *
301      * @param aliasServer the sitematcher for the alias
302      */

303     protected void addAlias(CmsSiteMatcher aliasServer) {
304
305         m_aliases.add(aliasServer);
306     }
307
308     /**
309      * Sets the aliases for the site.<p>
310      *
311      * @param aliases the aliases for the site
312      */

313     protected void setAliases(List JavaDoc aliases) {
314
315         m_aliases = aliases;
316     }
317
318     /**
319      * Sets the secure server.<p>
320      *
321      * @param secureServer the sitematcher of the secure server
322      */

323     protected void setSecureServer(CmsSiteMatcher secureServer) {
324
325         m_secureServer = secureServer;
326     }
327
328     /**
329      * Sets the site matcher that describes the URL of this site.<p>
330      *
331      * @param siteMatcher the site matcher that describes the URL of this site
332      */

333     protected void setSiteMatcher(CmsSiteMatcher siteMatcher) {
334
335         m_siteMatcher = siteMatcher;
336     }
337
338     /**
339      * Sets the server URL prefix to which this site is mapped.<p>
340      *
341      * @param siteRoot the server URL prefix to which this site is mapped
342      */

343     protected void setSiteRoot(String JavaDoc siteRoot) {
344
345         // site roots must never end with a "/"
346
if (siteRoot.endsWith("/")) {
347             m_siteRoot = siteRoot.substring(0, siteRoot.length() - 1);
348         } else {
349             m_siteRoot = siteRoot;
350         }
351     }
352
353     /**
354      * Sets the UUID of this site's root directory in the OpenCms VFS.<p>
355      *
356      * @param siteRootUUID the UUID of this site's root directory in the OpenCms VFS
357      */

358     protected void setSiteRootUUID(CmsUUID siteRootUUID) {
359
360         m_siteRootUUID = siteRootUUID;
361     }
362
363     /**
364      * Sets the display title of this site in the OpenCms VFS.<p>
365      *
366      * @param name the display title of this site in the OpenCms VFS
367      */

368     protected void setTitle(String JavaDoc name) {
369
370         m_title = name;
371     }
372 }
Popular Tags