View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.htmldocs.web;
35  
36  
37  import fr.paris.lutece.plugins.htmldocs.business.HtmlDoc;
38  import fr.paris.lutece.plugins.htmldocs.business.portlet.HtmlDocPublication;
39  import fr.paris.lutece.plugins.htmldocs.business.portlet.HtmlDocPublicationHome;
40  import fr.paris.lutece.plugins.htmldocs.service.HtmlDocService;
41  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
42  import fr.paris.lutece.portal.util.mvc.xpage.MVCApplication;
43  import fr.paris.lutece.portal.util.mvc.xpage.annotations.Controller;
44  import fr.paris.lutece.portal.web.xpages.XPage;
45  
46  import java.util.ArrayList;
47  import java.util.List;
48  import java.util.Map;
49  
50  import javax.servlet.http.HttpServletRequest;
51  
52  /**
53   * This class manages HtmlDocs page.
54   *
55   */
56  @Controller( xpageName = HtmlDocApp.XPAGE_NAME, pageTitleI18nKey = HtmlDocApp.MESSAGE_PAGE_TITLE, pagePathI18nKey = HtmlDocApp.MESSAGE_PATH )
57  public class HtmlDocApp  extends MVCApplication
58  {
59  	
60  	/**
61  	 * 
62  	 */
63  	private static final long serialVersionUID = 1L;
64  
65  	protected static final String XPAGE_NAME = "htmldoc";
66  
67      // Messages
68      protected static final String MESSAGE_PAGE_TITLE = "htmldocs.xpage.htmldoc.view.pageTitle";
69      protected static final String MESSAGE_PATH = "htmldocs.xpage.htmldoc.view.pagePathLabel";
70  	  // Templates
71  
72      private static final String TEMPLATE_VIEW_HTMLDOC = "skin/plugins/htmldocs/view_htmldoc.html";
73  
74      // Parameters
75      protected static final String PARAMETER_ID_HTMLDOC = "id";
76      protected static final String PARAMETER_ID_Portlet = "portlet_id";
77  
78     
79      protected static final String PARAMETER_VIEW = "view";
80     
81      // Properties for page titles
82  
83      // Filter Marks
84      protected static final String MARK_HTML_DOC = "htmldoc";
85      protected static final String MARK_LIST_DOC = "htmldoc_list";
86  
87  
88  
89  
90      // Views
91      private static final String VIEW_DETAILS = "documentDetails";
92      
93  
94  
95      /**
96       * Gets the HTMLDOC details view
97       * 
98       * @param request
99       *            The HTTP request
100      * @return The view
101      */
102     @View( value = VIEW_DETAILS, defaultView = true )
103     public XPage getTicketDetails( HttpServletRequest request )
104     {
105     	
106     	List<HtmlDocPublication> listHtmlDocPub= new ArrayList<HtmlDocPublication>();
107 
108     	int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_HTMLDOC ) );
109     	String idPortlet =  request.getParameter( PARAMETER_ID_Portlet ) ;
110     	if(idPortlet != null && !idPortlet.isEmpty()){
111     		
112     		listHtmlDocPub= HtmlDocPublicationHome.getDocPublicationByPortlet(Integer.parseInt(idPortlet));
113     	}
114   	    List<HtmlDoc> listHtmlDocs = new ArrayList<HtmlDoc>();
115 
116   	    for(HtmlDoc doc:HtmlDocService.getInstance().getListDocWithoutBinaries()){
117   	    	for(HtmlDocPublication pub:listHtmlDocPub){
118   	    		if(doc.getId() == pub.getIdDocument( )){
119   	    			doc.setAttachedPortletId(Integer.parseInt(idPortlet));
120   	    			listHtmlDocs.add(doc);
121   	    			
122   	    		}
123   	    	}
124   	    	
125   	    }
126   	    
127         HtmlDoc htmldoc = HtmlDocService.getInstance().loadDocument(nId);
128         Map<String, Object> model = getModel( );
129         model.put( MARK_HTML_DOC, htmldoc );
130         model.put( MARK_LIST_DOC, listHtmlDocs );
131 
132 
133         return getXPage( TEMPLATE_VIEW_HTMLDOC, request.getLocale( ), model );
134     }
135 
136 }