View Javadoc
1   /*
2    * Copyright (c) 2002-2021, City of 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.mylutece.web.portlet;
35  
36  import fr.paris.lutece.plugins.mylutece.business.portlet.MyLutecePortlet;
37  import fr.paris.lutece.plugins.mylutece.business.portlet.MyLutecePortletHome;
38  import fr.paris.lutece.portal.business.portlet.PortletHome;
39  import fr.paris.lutece.portal.web.portlet.PortletJspBean;
40  import fr.paris.lutece.util.html.HtmlTemplate;
41  
42  import javax.servlet.http.HttpServletRequest;
43  
44  /**
45   * This class provides the user interface to manage MyLutece Portlet
46   */
47  public class MyLutecePortletJspBean extends PortletJspBean
48  {
49      ////////////////////////////////////////////////////////////////////////////
50      // Constants
51  
52      // Right
53      public static final String RIGHT_MANAGE_ADMIN_SITE = "CORE_ADMIN_SITE";
54      private static final String PARAMETER_PAGE_ID = "page_id";
55      private static final String PARAMETER_PORTLET_ID = "portlet_id";
56      private static final String PARAMETER_PORTLET_TYPE_ID = "portlet_type_id";
57  
58      /**
59       * Creates a new MyLutecePortletJspBean object.
60       */
61      public MyLutecePortletJspBean( )
62      {
63      }
64  
65      /**
66       * Returns the Download portlet creation form
67       *
68       * @param request
69       *            The http request
70       * @return The HTML form
71       */
72      public String getCreate( HttpServletRequest request )
73      {
74          String strIdPage = request.getParameter( PARAMETER_PAGE_ID );
75          String strIdPortletType = request.getParameter( PARAMETER_PORTLET_TYPE_ID );
76          HtmlTemplate template = getCreateTemplate( strIdPage, strIdPortletType );
77  
78          return template.getHtml( );
79      }
80  
81      /**
82       * Returns the Download portlet modification form
83       *
84       * @param request
85       *            The Http request
86       * @return The HTML form
87       */
88      public String getModify( HttpServletRequest request )
89      {
90          String strIdPortlet = request.getParameter( PARAMETER_PORTLET_ID );
91          int nIdPortlet = Integer.parseInt( strIdPortlet );
92          MyLutecePortlet./../../../fr/paris/lutece/plugins/mylutece/business/portlet/MyLutecePortlet.html#MyLutecePortlet">MyLutecePortlet portlet = (MyLutecePortlet) PortletHome.findByPrimaryKey( nIdPortlet );
93          HtmlTemplate template = getModifyTemplate( portlet );
94  
95          return template.getHtml( );
96      }
97  
98      /**
99       * Process portlet's creation
100      *
101      * @param request
102      *            The Http request
103      * @return The Jsp management URL of the process result
104      */
105     public String doCreate( HttpServletRequest request )
106     {
107         MyLutecePortletece/business/portlet/MyLutecePortlet.html#MyLutecePortlet">MyLutecePortlet portlet = new MyLutecePortlet( );
108 
109         // get portlet common attributes
110         String strErrorUrl = setPortletCommonData( request, portlet );
111 
112         if ( strErrorUrl != null )
113         {
114             return strErrorUrl;
115         }
116 
117         int nIdPage = Integer.parseInt( request.getParameter( PARAMETER_PAGE_ID ) );
118         portlet.setPageId( nIdPage );
119 
120         // Portlet creation
121         MyLutecePortletHome.getInstance( ).create( portlet );
122 
123         // Displays the page with the new Portlet
124         return getPageUrl( nIdPage );
125     }
126 
127     /**
128      * Process portlet's modification
129      *
130      * @param request
131      *            The http request
132      * @return Management's Url
133      */
134     public String doModify( HttpServletRequest request )
135     {
136         // recovery of the portlet
137         String strIdPortlet = request.getParameter( PARAMETER_PORTLET_ID );
138         int nIdPortlet = Integer.parseInt( strIdPortlet );
139         MyLutecePortlet./../../../fr/paris/lutece/plugins/mylutece/business/portlet/MyLutecePortlet.html#MyLutecePortlet">MyLutecePortlet portlet = (MyLutecePortlet) PortletHome.findByPrimaryKey( nIdPortlet );
140 
141         // get portlet common attributes
142         String strErrorUrl = setPortletCommonData( request, portlet );
143 
144         if ( strErrorUrl != null )
145         {
146             return strErrorUrl;
147         }
148 
149         // Update of the portlet
150         portlet.update( );
151 
152         // Displays the page with the updated portlet
153         return getPageUrl( portlet.getPageId( ) );
154     }
155 }