1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.myapps.business.portlet;
35
36 import fr.paris.lutece.plugins.myapps.business.MyApps;
37 import fr.paris.lutece.plugins.myapps.service.MyAppsManager;
38 import fr.paris.lutece.plugins.myapps.service.MyAppsPlugin;
39 import fr.paris.lutece.plugins.myapps.service.MyAppsProvider;
40 import fr.paris.lutece.plugins.myapps.service.parameter.MyAppsParameterService;
41 import fr.paris.lutece.plugins.myapps.service.portlet.MyAppsPortletService;
42 import fr.paris.lutece.portal.business.portlet.Portlet;
43 import fr.paris.lutece.portal.service.i18n.I18nService;
44 import fr.paris.lutece.portal.service.plugin.Plugin;
45 import fr.paris.lutece.portal.service.plugin.PluginService;
46 import fr.paris.lutece.portal.service.security.LuteceUser;
47 import fr.paris.lutece.portal.service.security.SecurityService;
48 import fr.paris.lutece.portal.service.security.UserNotSignedException;
49 import fr.paris.lutece.util.ReferenceItem;
50 import fr.paris.lutece.util.url.UrlItem;
51 import fr.paris.lutece.util.xml.XmlUtil;
52
53 import org.apache.commons.lang.StringUtils;
54
55 import java.util.List;
56
57 import javax.servlet.http.HttpServletRequest;
58
59
60
61
62
63
64
65 public class MyAppsPortlet extends Portlet
66 {
67
68 private static final String TRUE = "1";
69 private static final String FALSE = "0";
70
71
72 private static final String TAG_MYAPPS_PROVIDERS_LIST = "myapps-providers-list";
73 private static final String TAG_MYAPPS_PROVIDER = "myapps-provider";
74 private static final String TAG_MYAPPS_PROVIDERS_NAME = "myapps-provider-name";
75 private static final String TAG_MYAPPS_LIST = "myapps-list";
76 private static final String TAG_MYAPP = "myapp";
77 private static final String TAG_MYAPP_NAME = "myapp-name";
78 private static final String TAG_MYAPP_ICON = "myapp-icon";
79 private static final String TAG_MYAPP_DESCRIPTION = "myapp-description";
80 private static final String TAG_MYAPP_LINK = "myapp-link";
81 private static final String TAG_MYAPP_BUTTON = "myapp-button";
82 private static final String TAG_MYAPP_HAS_ICON = "myapp-has-icon";
83
84
85 private static final String PARAMETER_MYAPP_ID = "myapp_id";
86 private static final String PARAMETER_PLUGIN_NAME = "plugin_name";
87 private static final String PARAMETER_IS_ASC_SORT = "is_asc_sort";
88
89
90 private static final String PROPERTY_MANAGE_MYAPPS_BUTTON_LABEL = "myapps.portlet.buttonManageMyApps";
91
92
93 private static final String JSP_OPEN_MYAPP = "jsp/site/plugins/myapps/DoOpenMyApp.jsp";
94
95
96
97
98 public MyAppsPortlet( )
99 {
100 }
101
102
103
104
105
106
107
108 public String getXml( HttpServletRequest request )
109 {
110 String strUserName;
111
112 try
113 {
114 LuteceUser user = SecurityService.getInstance( ).getRemoteUser( request );
115
116 if ( user != null )
117 {
118 strUserName = user.getName( );
119 }
120 else
121 {
122 strUserName = StringUtils.EMPTY;
123 }
124 }
125 catch ( UserNotSignedException e )
126 {
127 strUserName = StringUtils.EMPTY;
128 }
129
130 StringBuffer sbXml = new StringBuffer( );
131
132 if ( StringUtils.isNotBlank( strUserName ) )
133 {
134 List<MyAppsProvider> listProviders = MyAppsManager.getInstance( ).getProvidersList( );
135
136 XmlUtil.beginElement( sbXml, TAG_MYAPPS_PROVIDERS_LIST );
137
138 String strButtonLabel = I18nService.getLocalizedString( PROPERTY_MANAGE_MYAPPS_BUTTON_LABEL,
139 request.getLocale( ) );
140 Plugin plugin = PluginService.getPlugin( MyAppsPlugin.PLUGIN_NAME );
141 ReferenceItem isAscSort = MyAppsParameterService.getInstance( )
142 .getParamDefaultValue( PARAMETER_IS_ASC_SORT, plugin );
143
144 for ( MyAppsProvider provider : listProviders )
145 {
146 XmlUtil.beginElement( sbXml, TAG_MYAPPS_PROVIDER );
147 XmlUtil.addElement( sbXml, TAG_MYAPPS_PROVIDERS_NAME, provider.getProviderName( request.getLocale( ) ) );
148 XmlUtil.beginElement( sbXml, TAG_MYAPPS_LIST );
149
150 for ( MyApps myApp : provider.getMyAppsListByUserName( strUserName, isAscSort.isChecked( ) ) )
151 {
152 XmlUtil.beginElement( sbXml, TAG_MYAPP );
153
154 UrlItem urlLink = new UrlItem( JSP_OPEN_MYAPP );
155 urlLink.addParameter( PARAMETER_MYAPP_ID, myApp.getIdApplication( ) );
156 urlLink.addParameter( PARAMETER_PLUGIN_NAME, provider.getPluginName( ) );
157 XmlUtil.addElement( sbXml, TAG_MYAPP_ICON,
158 provider.getResourceImage( String.valueOf( myApp.getIdApplication( ) ) ) );
159 XmlUtil.addElement( sbXml, TAG_MYAPP_NAME, myApp.getName( ) );
160 XmlUtil.addElement( sbXml, TAG_MYAPP_DESCRIPTION, myApp.getDescription( ) );
161 XmlUtil.addElement( sbXml, TAG_MYAPP_LINK, urlLink.getUrlWithEntity( ) );
162 XmlUtil.addElement( sbXml, TAG_MYAPP_HAS_ICON, myApp.hasIcon( ) ? TRUE : FALSE );
163 XmlUtil.endElement( sbXml, TAG_MYAPP );
164 }
165
166 XmlUtil.endElement( sbXml, TAG_MYAPPS_LIST );
167
168 XmlUtil.endElement( sbXml, TAG_MYAPPS_PROVIDER );
169 }
170
171 XmlUtil.addElement( sbXml, TAG_MYAPP_BUTTON, strButtonLabel );
172 XmlUtil.endElement( sbXml, TAG_MYAPPS_PROVIDERS_LIST );
173 }
174
175 return addPortletTags( sbXml );
176 }
177
178
179
180
181
182
183
184 public String getXmlDocument( HttpServletRequest request )
185 {
186 return XmlUtil.getXmlHeader( ) + getXml( request );
187 }
188
189
190
191
192 public void update( )
193 {
194 MyAppsPortletService.getInstance( ).update( this );
195 }
196
197
198
199
200 public void remove( )
201 {
202 MyAppsPortletService.getInstance( ).remove( this );
203 }
204 }