1 20 21 package com.methodhead.shim; 22 23 import javax.servlet.http.*; 24 import javax.servlet.*; 25 import java.io.IOException ; 26 import com.methodhead.sitecontext.SiteContext; 27 import com.methodhead.aikp.IntKey; 28 import com.methodhead.persistable.PersistableException; 29 import org.apache.log4j.Logger; 30 31 public class ViewPageServlet 32 extends 33 HttpServlet { 34 35 37 39 41 43 46 public void doPost( 47 HttpServletRequest request, 48 HttpServletResponse response ) 49 throws 50 IOException , 51 ServletException { 52 53 doGet( request, response ); 54 } 55 56 65 public void doGet( 66 HttpServletRequest request, 67 HttpServletResponse response ) 68 throws 69 IOException , 70 ServletException { 71 72 SiteContext siteContext = SiteContext.getContext( request ); 76 77 if ( logger_.isDebugEnabled() ) { 78 logger_.debug( "Using site context \"" + siteContext + "\"" ); 79 } 80 81 Page page = new Page(); 82 page.setSiteContext( siteContext ); 83 84 String alias = ( String )request.getAttribute( ShimGlobals.PAGEALIAS_KEY ); 85 86 if ( alias == null ) { 90 91 if ( logger_.isDebugEnabled() ) { 92 logger_.debug( "No alias specified; looking for root link" ); 93 } 94 95 SiteMap siteMap = ShimUtils.getSiteMap( request ); 99 Link root = ( Link )siteMap.getRoot(); 100 101 if ( root == null ) { 105 106 if ( logger_.isDebugEnabled() ) { 107 logger_.debug( "No links in the site map; forwarding to /emptySite.do" ); 108 } 109 110 request.getRequestDispatcher( "/emptySite.do" ).forward( request, response ); 111 112 return; 113 } 114 else { 115 116 if ( logger_.isDebugEnabled() ) { 117 logger_.debug( "Found root link; loading page for id \"" + root.getPageId() + "\"" ); 118 } 119 120 page.loadFull( new IntKey( root.getPageId() ) ); 124 } 125 } 126 else { 127 128 try { 129 if ( logger_.isDebugEnabled() ) { 130 logger_.debug( "Loading page for alias \"" + alias + "\"" ); 131 } 132 133 page.loadFullForAlias( alias ); 134 } 135 catch ( PersistableException e ) { 136 137 response.setStatus( HttpServletResponse.SC_GONE ); 141 142 try { 146 page.loadFullForAlias( "pagenotfound" ); 147 148 if ( logger_.isDebugEnabled() ) { 149 logger_.debug( "Loaded page for alias \"pagenotfound\"" ); 150 } 151 } 152 catch ( PersistableException ee ) { 153 154 if ( logger_.isDebugEnabled() ) { 155 logger_.debug( "Couldn't load page for alias \"" + alias + "\" or \"pagenotfound\"; forwarding to /pageNotFound.do" ); 156 } 157 158 request.getRequestDispatcher( "/pageNotFound.do" ).forward( request, response ); 159 160 return; 161 } 162 } 163 } 164 165 if ( logger_.isDebugEnabled() ) { 166 logger_.debug( "Displaying page" ); 167 } 168 169 response.setContentType( "text/html; charset=iso-8859-1" ); 173 174 request.setAttribute( ShimGlobals.PAGE_KEY, page ); 178 179 Template template = new Template(); 183 template.setSiteContext( siteContext ); 184 template.include( request, response, page.getString( "template" ) ); 185 } 186 187 189 191 public static Logger logger_ = Logger.getLogger( ViewPageServlet.class ); 192 } 193 | Popular Tags |