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.common.IsOnline; 38 import org.nextime.ion.framework.business.Publication; 39 import org.nextime.ion.framework.business.Section; 40 import org.nextime.ion.framework.mapping.Mapping; 41 import org.nextime.ion.framework.mapping.MappingException; 42 import org.nextime.ion.frontoffice.bean.IonStatus; 43 import org.nextime.ion.frontoffice.bean.SectionTypes; 44 import org.nextime.ion.frontoffice.exception.IdNotFoundException; 45 import org.nextime.ion.frontoffice.smartCache.SmartCacheManager; 46 47 public class PublicationServlet extends HttpServlet { 48 49 public void service( 50 HttpServletRequest request, 51 HttpServletResponse response) 52 throws ServletException , IOException { 53 54 try { 55 56 CommonThings.common(request,response); 57 58 String requestedId = 61 (request.getPathInfo() != null) 62 ? request.getPathInfo().substring(1) 63 : null; 64 if (requestedId != null) { 65 if (requestedId.indexOf(".") != -1) { 66 requestedId = 67 requestedId.substring(0, requestedId.indexOf(".")); 68 } 69 } 70 71 if( Mapping.getInstance().isTransactionActive() ) { 73 try { 74 Mapping.rollback(); 75 } catch(Exception e) {} 76 } 77 78 Mapping.begin(); 81 82 Publication publication; 84 try { 85 publication = Publication.getInstance(requestedId); 86 } catch( MappingException e ) { 87 throw new IdNotFoundException(); 88 } 89 90 Section section = (Section)publication.listSections().firstElement(); 92 93 IonStatus status = new IonStatus(); 95 status.setCurrentSection(section); 96 status.setCurrentPublication(publication); 97 status.setCurrentVersion( IsOnline.getMostRecentVersion(publication) ); 98 if( request.getParameter("static")!=null ) status.setIsStatic(true); 99 request.setAttribute("ionStatus", status); 100 101 String template = (String ) section.getMetaData("template"); 104 if (template == null) 105 template = "default"; 106 107 String jsp = SectionTypes.getSectionBean(this,template).getJsp(); 108 109 if( request.getParameter("template")!=null ) { 110 jsp = request.getParameter("template")+".jsp"; 111 } 112 113 getServletContext() 114 .getRequestDispatcher( 115 "/templates/" + jsp) 116 .forward(request, response); 117 118 Mapping.rollback(); 119 120 } catch (Exception e) { 121 Mapping.rollback(); 122 throw new ServletException (e); 124 } 125 } 126 127 protected String getDefaultSectionId() throws MappingException { 128 Vector rootSections = Section.listRootSections(); 130 return ((Section) rootSections.get(0)).getId(); 131 } 132 133 } | Popular Tags |