1 26 27 package org.nextime.ion.frontoffice.servlet; 28 29 import java.io.IOException ; 30 import java.util.Vector ; 31 32 import javax.servlet.ServletException ; 33 import javax.servlet.http.HttpServlet ; 34 import javax.servlet.http.HttpServletRequest ; 35 import javax.servlet.http.HttpServletResponse ; 36 37 import org.nextime.ion.framework.business.Section; 38 import org.nextime.ion.framework.mapping.Mapping; 39 import org.nextime.ion.framework.mapping.MappingException; 40 import org.nextime.ion.frontoffice.bean.IonStatus; 41 import org.nextime.ion.frontoffice.bean.SectionTypes; 42 import org.nextime.ion.frontoffice.exception.IdNotFoundException; 43 import org.nextime.ion.frontoffice.smartCache.SmartCacheManager; 44 45 public class SectionServlet extends HttpServlet { 46 47 public static String relativePath; 48 public static SmartCacheManager cache; 49 50 public void service( 51 HttpServletRequest request, 52 HttpServletResponse response) 53 throws ServletException , IOException { 54 55 if( cache == null ) { 56 cache = new SmartCacheManager(); 57 } 58 59 try { 60 61 CommonThings.common(request,response); 62 63 String requestedId = 66 (request.getPathInfo() != null) 67 ? request.getPathInfo().substring(1) 68 : null; 69 if (requestedId != null) { 70 if (requestedId.indexOf(".") != -1) { 71 requestedId = 72 requestedId.substring(0, requestedId.indexOf(".")); 73 } 74 } 75 76 if( Mapping.getInstance().isTransactionActive() ) { 78 try { 79 Mapping.rollback(); 80 } catch(Exception e) {} 81 } 82 83 Mapping.begin(); 86 87 if (requestedId == null) { 90 requestedId = getDefaultSectionId(); 91 } 92 93 Section section; 95 try { 96 section = Section.getInstance(requestedId); 97 } catch( MappingException e ) { 98 throw new IdNotFoundException(); 99 } 100 101 IonStatus status = new IonStatus(); 103 status.setCurrentSection(section); 104 if( request.getParameter("static")!=null ) status.setIsStatic(true); 105 request.setAttribute("ionStatus", status); 106 107 String template = (String ) section.getMetaData("template"); 110 if (template == null) 111 template = "default"; 112 113 String jsp = SectionTypes.getSectionBean(this,template).getJsp(); 114 115 if( request.getParameter("templateType")!=null ) { 116 jsp = jsp.substring(0,jsp.lastIndexOf(".jsp"))+"-"+request.getParameter("templateType")+".jsp"; 117 } 118 119 getServletContext() 120 .getRequestDispatcher( 121 "/templates/" + jsp) 122 .forward(request, response); 123 124 if( Mapping.getInstance().isTransactionActive() ) { 125 Mapping.rollback(); 126 } 127 128 } catch (Exception e) { 129 Mapping.rollback(); 130 throw new ServletException (e); 132 } 133 } 134 135 protected String getDefaultSectionId() throws MappingException { 136 Vector rootSections = Section.listRootSections(); 138 return ((Section) rootSections.get(0)).getId(); 139 } 140 141 142 public void init() throws ServletException { 143 relativePath = getInitParameter("relativePath"); 144 } 145 146 } | Popular Tags |