KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > frontoffice > servlet > PublicationServlet


1 /*
2  * ÏON content management system.
3  * Copyright (C) 2002 Guillaume Bort(gbort@msn.com). All rights reserved.
4  *
5  * Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
6  * Copyright 2000-2002 (C) Intalio Inc. All Rights Reserved.
7  *
8  * ÏON is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * ÏON core framework, ÏON content server, ÏON backoffice, ÏON frontoffice
14  * and ÏON admin application are parts of ÏON and are distributed under
15  * same terms of licence.
16  *
17  *
18  * ÏON includes software developed by the Apache Software Foundation (http://www.apache.org/)
19  * and software developed by the Exolab Project (http://www.exolab.org).
20  *
21  * ÏON is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  */

26
27 package org.nextime.ion.frontoffice.servlet;
28
29 import java.io.IOException JavaDoc;
30 import java.util.Vector JavaDoc;
31
32 import javax.servlet.ServletException JavaDoc;
33 import javax.servlet.http.HttpServlet JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc {
48
49     public void service(
50         HttpServletRequest JavaDoc request,
51         HttpServletResponse JavaDoc response)
52         throws ServletException JavaDoc, IOException JavaDoc {
53
54         try {
55
56             CommonThings.common(request,response);
57             
58             // cherche l'identifiant de la publication demandée dans
59
// la query string
60
String JavaDoc 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             // rollback dirty transaction ??
72
if( Mapping.getInstance().isTransactionActive() ) {
73                 try {
74                     Mapping.rollback();
75                 } catch(Exception JavaDoc e) {}
76             }
77             
78             // demarre une transaction pour accéder aux
79
// données du framework
80
Mapping.begin();
81             
82             // recupére une instance sur la Publication
83
Publication publication;
84             try {
85                 publication = Publication.getInstance(requestedId);
86             } catch( MappingException e ) {
87                 throw new IdNotFoundException();
88             }
89             
90             // recupére la section de cette publication
91
Section section = (Section)publication.listSections().firstElement();
92             
93             // créé le bean de status
94
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             // utilise la metaData "template" de la section
102
// pour decider vers quelle vue rediriger le flux
103
String JavaDoc template = (String JavaDoc) section.getMetaData("template");
104             if (template == null)
105                 template = "default";
106                 
107             String JavaDoc 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 JavaDoc e) {
121             Mapping.rollback();
122             //transmet l'exception a tomcat
123
throw new ServletException JavaDoc(e);
124         }
125     }
126
127     protected String JavaDoc getDefaultSectionId() throws MappingException {
128         // selectionne la premiére des sections racines
129
Vector JavaDoc rootSections = Section.listRootSections();
130         return ((Section) rootSections.get(0)).getId();
131     }
132
133 }
Popular Tags