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.directory.modules.gismap.business.portlet;
35  
36  import java.util.List;
37  
38  import javax.servlet.http.HttpServletRequest;
39  
40  import org.apache.commons.lang.BooleanUtils;
41  
42  import fr.paris.lutece.plugins.directory.modules.gismap.business.DirectoryGismapSourceQuery;
43  import fr.paris.lutece.plugins.directory.modules.gismap.service.GismapDirectoryService;
44  import fr.paris.lutece.portal.business.portlet.Portlet;
45  import fr.paris.lutece.portal.business.portlet.PortletHome;
46  import fr.paris.lutece.portal.service.util.AppPropertiesService;
47  import fr.paris.lutece.util.xml.XmlUtil;
48  
49  /**
50   * This class represents business objects ArticlesList Portlet
51   */
52  public class GismapDirectoryPortlet extends Portlet
53  {
54      // ///////////////////////////////////////////////////////////////////////////////
55      // Xml Tags
56      private static final String TAG_GISMAP_PORTLET         = "gismap-portlet";
57      private static final String TAG_GISMAP_PORTLET_CONTENT = "gismap-portlet-content";
58  
59      // ///////////////////////////////////////////////////////////////////////////////
60      
61  	public static final String   GISMAP_DEFAULT_VIEW_PROPERTIES = "gismap.mainmap.defaultview";
62  	public static final String 	MAX_LAYER_GEOJSON_PROPERTY = "directory-gismap.portlet.maxLayerGeojson";
63  
64      // Constants
65      private int                 _nPortletId;
66      private int                 _nStatus;
67      private	int					_nview;
68  	private List<DirectoryGismapSourceQuery> _listMapSource;
69  
70      /**
71       * Sets the identifier of the portlet type to the value specified in the
72       * ArticlesListPortletHome class
73       */
74      public GismapDirectoryPortlet( )
75      {
76      }
77  
78      /**
79       * Returns the Xml code of the form portlet without XML heading
80       *
81       * @param request The HTTP Servlet request
82       * @return the Xml code of the form portlet content
83       */
84      @Override
85      public String getXml( HttpServletRequest request )
86      {
87      	GismapDirectoryPortlet portlet = ( GismapDirectoryPortlet ) PortletHome.findByPrimaryKey( getId( ) );
88      	List<DirectoryGismapSourceQuery> listGeojsonSources = portlet.getListMapSource( );
89  
90      	String viewId = String.valueOf( portlet.getView( ) );
91  
92      	StringBuffer strXml = new StringBuffer( );
93      	XmlUtil.beginElement( strXml, TAG_GISMAP_PORTLET );
94      	if ( !BooleanUtils.toBoolean( portlet.getDisplayPortletTitle( ) ) )
95      	{
96      		XmlUtil.addElementHtml( strXml, TAG_GISMAP_PORTLET_CONTENT, "<h3>" + portlet.getName( ) + "</h3>" );
97      	}
98      	XmlUtil.addElementHtml( strXml, TAG_GISMAP_PORTLET_CONTENT, GismapDirectoryService.getInstance( ).getMapTemplateWithDirectoryGismapSources(request, viewId, listGeojsonSources) );
99  
100     	XmlUtil.endElement( strXml, TAG_GISMAP_PORTLET );
101 
102     	return addPortletTags( strXml );
103     }
104 
105     /**
106      * Returns the Xml code of the form portlet with XML heading
107      *
108      * @param request The HTTP Servlet Request
109      * @return the Xml code of the Articles List portlet
110      */
111     @Override
112     public String getXmlDocument( HttpServletRequest request )
113     {
114         return XmlUtil.getXmlHeader( ) + getXml( request );
115     }
116 
117     /**
118      * Updates the current instance of the form portlet object
119      */
120     public void update( )
121     {
122         GismapDirectoryPortletHome.getInstance( ).update( this );
123     }
124 
125     /**
126      * Removes the current instance of the the form portlet object
127      */
128     @Override
129     public void remove( )
130     {
131         GismapDirectoryPortletHome.getInstance( ).remove( this );
132     }
133 
134     /**
135      * Returns the nPortletId
136      *
137      * @return The nPortletId
138      */
139     public int getPortletId( )
140     {
141         return _nPortletId;
142     }
143 
144     /**
145      * Sets the IdPortlet
146      *
147      * @param nPortletId The nPortletId
148      */
149     public void setPortletId( int nPortletId )
150     {
151         _nPortletId = nPortletId;
152     }
153 
154 
155     /**
156      * Returns the Status
157      *
158      * @return The Status
159      */
160     @Override
161     public int getStatus( )
162     {
163         return _nStatus;
164     }
165 
166     /**
167      * Sets the Status
168      *
169      * @param nStatus The Status
170      */
171     @Override
172     public void setStatus( int nStatus )
173     {
174         _nStatus = nStatus;
175     }
176 
177     /**
178      * Returns the map View
179      * @param _nview 
180      *
181      * @return The View
182      */
183 	public int getView( )
184 	{
185 		// TODO Auto-generated method stub
186 		return _nview;
187 	}
188 	
189     /**
190      * Sets the map View
191      * @param _nview 
192      *
193      */
194 	public void setView( int nView )
195 	{
196 		_nview = nView;
197 	}
198 
199     /**
200      * getter for the List of MapSource
201      * @param listDirectoryGismapSource 
202      *
203      */
204 	public List<DirectoryGismapSourceQuery> getListMapSource( )
205 	{
206 		return this._listMapSource;
207 		
208 	}
209 	
210     /**
211      * Setter for the List of MapSource
212      * @param listDirectoryGismapSource 
213      *
214      */
215 	public void setListMapSource(List<DirectoryGismapSourceQuery> listDirectoryGismapSource)
216 	{
217 		this._listMapSource = listDirectoryGismapSource;		
218 	}
219 }