KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > action > content > PreviewPublicationAction


1 package org.nextime.ion.backoffice.action.content;
2
3
4 import java.io.IOException JavaDoc;
5 import java.util.Vector JavaDoc;
6
7 import javax.servlet.ServletException JavaDoc;
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
10 import org.apache.struts.action.ActionForm;
11 import org.apache.struts.action.ActionForward;
12 import org.apache.struts.action.ActionMapping;
13 import org.nextime.ion.backoffice.action.BaseAction;
14
15 import org.nextime.ion.framework.business.Publication;
16 import org.nextime.ion.framework.business.TypePublication;
17 import org.nextime.ion.framework.business.impl.Style;
18 import org.nextime.ion.framework.business.impl.TypePublicationImpl;
19 import org.nextime.ion.framework.helper.Viewer;
20 import org.nextime.ion.framework.locale.Locale;
21 import org.nextime.ion.framework.locale.LocaleList;
22 import org.nextime.ion.framework.mapping.Mapping;
23
24
25
26 public class PreviewPublicationAction extends BaseAction {
27
28     public ActionForward perform(ActionMapping mapping,
29                                  ActionForm form,
30                                  HttpServletRequest JavaDoc request,
31                                  HttpServletResponse JavaDoc response)
32         throws IOException JavaDoc, ServletException JavaDoc {
33             
34         // check if user is correctly logged
35
checkUser(request);
36         
37         // set the locales list
38
request.setAttribute("locales", LocaleList.getInstance().getLocales() );
39         
40         String JavaDoc id = request.getParameter("id");
41         int version = Integer.parseInt(request.getParameter("version"));
42         String JavaDoc style = request.getParameter("style");
43         String JavaDoc locale = request.getParameter("locale");
44         
45         try {
46             Mapping.begin();
47             
48             Publication publication = Publication.getInstance(id);
49             TypePublication type = publication.getType();
50             // list only XSL styles (not XSL-FO)
51
Vector JavaDoc styleNames = type.listStyles();
52             Vector JavaDoc styles = new Vector JavaDoc();
53             for( int i=0; i<styleNames.size(); i++ ) {
54                 String JavaDoc n = styleNames.get(i).toString();
55                 if(((TypePublicationImpl)type).getStyleSheet(n).getType() == Style.XSL && !n.startsWith("indexation") && !n.startsWith("special")) {
56                     styles.add(n);
57                 }
58             }
59             request.setAttribute("styles",styles);
60             
61             if( style == null ) style=styles.get(0)+"";
62             if( locale == null ) locale=((Locale)LocaleList.getInstance().getLocales().iterator().next()).getLocale();
63             
64             String JavaDoc view = new String JavaDoc(Viewer.getView(publication, version, style, locale));
65             request.setAttribute("view",view);
66             
67             Mapping.rollback();
68         } catch( Exception JavaDoc e ) {
69             Mapping.rollback();
70             throw new ServletException JavaDoc(e);
71         }
72         
73         // Forward to the next page
74
return (mapping.findForward("view"));
75
76     }
77
78 }
79
Popular Tags