KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc {
46     
47     public static String JavaDoc relativePath;
48     public static SmartCacheManager cache;
49
50     public void service(
51         HttpServletRequest JavaDoc request,
52         HttpServletResponse JavaDoc response)
53         throws ServletException JavaDoc, IOException JavaDoc {
54             
55         if( cache == null ) {
56             cache = new SmartCacheManager();
57         }
58
59         try {
60             
61             CommonThings.common(request,response);
62
63             // cherche l'identifiant de la section demandée dans
64
// la query string
65
String JavaDoc 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             // rollback dirty transaction ??
77
if( Mapping.getInstance().isTransactionActive() ) {
78                 try {
79                     Mapping.rollback();
80                 } catch(Exception JavaDoc e) {}
81             }
82              
83             // demarre une transaction pour accéder aux
84
// données du framework wcm
85
Mapping.begin();
86             
87             // choisis une section par default si aucune n'est
88
// spécifiée
89
if (requestedId == null) {
90                 requestedId = getDefaultSectionId();
91             }
92
93             // recupére une instance sur la Section
94
Section section;
95             try {
96                 section = Section.getInstance(requestedId);
97             } catch( MappingException e ) {
98                 throw new IdNotFoundException();
99             }
100
101             // créé le bean de status
102
IonStatus status = new IonStatus();
103             status.setCurrentSection(section);
104             if( request.getParameter("static")!=null ) status.setIsStatic(true);
105             request.setAttribute("ionStatus", status);
106
107             // utilise la metaData "template" de la section
108
// pour decider vers quelle vue rediriger le flux
109
String JavaDoc template = (String JavaDoc) section.getMetaData("template");
110             if (template == null)
111                 template = "default";
112                 
113             String JavaDoc 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 JavaDoc e) {
129             Mapping.rollback();
130             //transmet l'exception a tomcat
131
throw new ServletException JavaDoc(e);
132         }
133     }
134
135     protected String JavaDoc getDefaultSectionId() throws MappingException {
136         // selectionne la premiére des sections racines
137
Vector JavaDoc rootSections = Section.listRootSections();
138         return ((Section) rootSections.get(0)).getId();
139     }
140     
141
142     public void init() throws ServletException JavaDoc {
143         relativePath = getInitParameter("relativePath");
144     }
145
146 }
Popular Tags