KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > meshcms > core > VirtualWebSite


1 /*
2  * MeshCMS - A simple CMS based on SiteMesh
3  * Copyright (C) 2004-2007 Luciano Vernaschi
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * You can contact the author at http://www.cromoteca.com
20  * and at info@cromoteca.com
21  */

22
23 package org.meshcms.core;
24
25 import java.io.File JavaDoc;
26 import javax.servlet.*;
27 import javax.servlet.http.*;
28 import org.meshcms.util.*;
29
30 public class VirtualWebSite extends WebSite {
31   private MainWebSite mainWebSite;
32
33   protected static WebSite create(ServletContext sc,
34       String JavaDoc[] welcomeFiles, File JavaDoc rootFile, Path rootPath, Path cmsPath) {
35     throw new UnsupportedOperationException JavaDoc
36         ("You should use create(MainWebSite, Path, Path) instead");
37   }
38
39   protected static VirtualWebSite create(MainWebSite mainWebSite, Path rootPath,
40       Path cmsPath) {
41     VirtualWebSite virtualWebSite = new VirtualWebSite();
42     virtualWebSite.init(mainWebSite, rootPath, cmsPath);
43     return virtualWebSite;
44   }
45
46   protected void init(MainWebSite mainWebSite, Path rootPath, Path cmsPath) {
47     this.mainWebSite = mainWebSite;
48     init(mainWebSite.getServletContext(), mainWebSite.getWelcomeFileNames(),
49         mainWebSite.getFile(rootPath), rootPath, cmsPath);
50   }
51
52   public WebSite getWebSite(ServletRequest request) {
53     throw new UnsupportedOperationException JavaDoc("This is a virtual website");
54   }
55
56   public boolean isVirtual() {
57     return true;
58   }
59
60   public HttpServletRequest wrapRequest(ServletRequest request) {
61     return new MultiSiteRequestWrapper((HttpServletRequest) request, this);
62   }
63
64   public String JavaDoc getTypeDescription() {
65     return "virtual web site (" + rootPath.getLastElement() + ')';
66   }
67
68   public Path getRequestedPath(HttpServletRequest request) {
69     return ((MultiSiteRequestWrapper) request).getRequestedPath();
70   }
71
72   public Path getServedPath(HttpServletRequest request) {
73     return ((MultiSiteRequestWrapper) request).getServedPath();
74   }
75
76   public Path getServedPath(Path requestedPath) {
77     // a null adminPath is handled correctly
78
return requestedPath.isContainedIn(adminPath) ?
79         mainWebSite.getAdminPath().add(requestedPath.getRelativeTo(adminPath)) :
80         rootPath.add(requestedPath);
81   }
82
83   public File JavaDoc getFile(Path path) {
84     return mainWebSite.getFile(getServedPath(path));
85   }
86
87   public MainWebSite getMainWebSite() {
88     return mainWebSite;
89   }
90
91   /* public String getLink(Path path) {
92     return siteMap.getServedPath(path).getAsLink();
93   } */

94
95   public void updateSiteMap(boolean force) {
96     if (cmsPath != null) {
97       super.updateSiteMap(force);
98     }
99   }
100 }
101
Popular Tags