1 package org.nextime.ion.backoffice.action.content; 2 3 import java.io.IOException ; 4 import java.util.Hashtable ; 5 import java.util.Vector ; 6 7 import javax.servlet.ServletException ; 8 import javax.servlet.http.HttpServletRequest ; 9 import javax.servlet.http.HttpServletResponse ; 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 import org.nextime.ion.backoffice.bean.SectionTypes; 15 import org.nextime.ion.commons.PublicationSorter; 16 17 import org.nextime.ion.framework.business.Section; 18 import org.nextime.ion.framework.mapping.Mapping; 19 20 public class ViewSectionAction extends BaseAction { 21 22 static public final int pageSize = 5; 23 24 public ActionForward perform( 25 ActionMapping mapping, 26 ActionForm form, 27 HttpServletRequest request, 28 HttpServletResponse response) 29 throws IOException , ServletException { 30 31 checkUser(request); 33 34 String highlightId = request.getSession().getAttribute("highlightId")+""; 35 request.getSession().removeAttribute("highlightId"); 36 request.setAttribute("highlightId", highlightId); 37 38 if (request.getSession().getAttribute("pageInfos") == null) { 39 request.getSession().setAttribute("pageInfos", new Hashtable ()); 40 } 41 if (request.getSession().getAttribute("versionDisplayInfos") == null) { 42 request.getSession().setAttribute( 43 "versionDisplayInfos", 44 new Hashtable ()); 45 } 46 47 if (request.getParameter("expand") != null) { 48 Hashtable ht = 49 (Hashtable ) request.getSession().getAttribute( 50 "versionDisplayInfos"); 51 ht.put(request.getParameter("expand"), "true"); 52 } 53 if (request.getParameter("collapse") != null) { 54 Hashtable ht = 55 (Hashtable ) request.getSession().getAttribute( 56 "versionDisplayInfos"); 57 ht.remove(request.getParameter("collapse")); 58 } 59 60 try { 62 Mapping.begin(); 63 64 Vector sections; 65 Vector publications; 66 67 Section section = Section.getInstance(request.getParameter("id")); 68 69 int startPublications; 70 try { 71 startPublications = 72 Integer.parseInt(request.getParameter("start")); 73 ( 74 (Hashtable ) 75 (request.getSession().getAttribute("pageInfos"))).put( 76 section.getId(), 77 new Integer (startPublications)); 78 } catch (NumberFormatException e) { 79 try { 80 startPublications = 81 ( 82 (Integer ) (((Hashtable ) (request 83 .getSession() 84 .getAttribute("pageInfos"))) 85 .get(section.getId()))) 86 .intValue(); 87 } catch (Exception ex) { 88 startPublications = 0; 89 ( 90 (Hashtable ) 91 ( 92 request.getSession().getAttribute( 93 "pageInfos"))).put( 94 section.getId(), 95 new Integer (startPublications)); 96 97 } 98 } 99 100 sections = section.listSubSections(); 101 publications = PublicationSorter.sortPublications(section); 102 103 105 request.setAttribute("section", section); 106 request.setAttribute("sectionName", section.getMetaData("name")); 107 try { 108 String description = 109 SectionTypes 110 .getSectionBean( 111 servlet, 112 section.getMetaData("template") + "", 113 request) 114 .getDescription(); 115 request.setAttribute("sectionDescription", description); 116 } catch (Exception e) { 117 } 119 120 request.setAttribute("sections", sections); 122 request.setAttribute("sectionsSize", new Integer (sections.size())); 123 124 Vector publicationPage = new Vector (); 125 126 int stopPublications = -1; 127 128 for (int i = startPublications; 129 i < startPublications + pageSize; 130 i++) { 131 if (i < publications.size()) { 132 publicationPage.add(publications.get(i)); 133 stopPublications = i; 134 } 135 } 136 137 request.setAttribute("pageSize", new Integer (pageSize)); 139 request.setAttribute("start", new Integer (startPublications)); 140 request.setAttribute("stop", new Integer (stopPublications)); 141 request.setAttribute("publications", publicationPage); 142 request.setAttribute( 143 "publicationsSize", 144 new Integer (publications.size())); 145 146 } catch (Exception e) { 147 throw new ServletException (e); 148 } finally { 149 Mapping.rollback(); 150 } 151 152 return (mapping.findForward("view")); 154 155 } 156 157 } 158 | Popular Tags |