1 22 23 package org.meshcms.core; 24 25 import java.io.File ; 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 [] welcomeFiles, File rootFile, Path rootPath, Path cmsPath) { 35 throw new UnsupportedOperationException 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 ("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 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 return requestedPath.isContainedIn(adminPath) ? 79 mainWebSite.getAdminPath().add(requestedPath.getRelativeTo(adminPath)) : 80 rootPath.add(requestedPath); 81 } 82 83 public File getFile(Path path) { 84 return mainWebSite.getFile(getServedPath(path)); 85 } 86 87 public MainWebSite getMainWebSite() { 88 return mainWebSite; 89 } 90 91 94 95 public void updateSiteMap(boolean force) { 96 if (cmsPath != null) { 97 super.updateSiteMap(force); 98 } 99 } 100 } 101 | Popular Tags |