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.appstore.web;
35
36 import fr.paris.lutece.plugins.appstore.business.Application;
37 import fr.paris.lutece.plugins.appstore.business.ApplicationHome;
38 import fr.paris.lutece.plugins.appstore.business.ComponentHome;
39 import fr.paris.lutece.portal.service.message.SiteMessageException;
40 import fr.paris.lutece.portal.service.plugin.Plugin;
41 import fr.paris.lutece.portal.service.template.AppTemplateService;
42 import fr.paris.lutece.portal.service.util.AppPropertiesService;
43 import fr.paris.lutece.portal.web.xpages.XPage;
44 import fr.paris.lutece.portal.web.xpages.XPageApplication;
45 import fr.paris.lutece.util.ReferenceList;
46 import fr.paris.lutece.util.html.HtmlTemplate;
47
48 import java.io.Serializable;
49
50 import java.util.ArrayList;
51 import java.util.HashMap;
52 import java.util.List;
53 import java.util.Map;
54
55 import javax.servlet.http.HttpServletRequest;
56
57
58
59
60 public class AppStoreApp implements XPageApplication, Serializable
61 {
62 private static final String TEMPLATE_HOMEPAGE = "/skin/plugins/appstore/appstore.html";
63 private static final String TEMPLATE_APPLICATION = "/skin/plugins/appstore/application.html";
64 private static final String TEMPLATE_POM = "/admin/plugins/appstore/pom.xml";
65 private static final String MARK_APPLICATIONS_LIST = "applications_list";
66 private static final String MARK_APPLICATION = "application";
67 private static final String MARK_COMPONENTS_LIST = "components_list";
68 private static final String PARAMETER_ID_APPLICATION = "id_application";
69 private static final String PROPERTY_PAGE_PATH = "appstore.pagePathLabel";
70 private static final String PROPERTY_PAGE_TITLE = "appstore.pageTitle";
71 private static final String URL_HOME_APPSTORE = "page=appstore";
72
73
74
75
76
77
78
79
80
81
82
83
84
85 @Override
86 public XPage getPage( HttpServletRequest request, int nMode, Plugin plugin ) throws SiteMessageException
87 {
88 XPage page = new XPage( );
89
90 String strApplicationId = request.getParameter( PARAMETER_ID_APPLICATION );
91
92 if ( strApplicationId != null )
93 {
94 int nApplicationId = Integer.parseInt( strApplicationId );
95 getApplicationContent( request, page, nApplicationId );
96 }
97 else
98 {
99 getHomePageContent( request, page );
100 }
101
102 return page;
103 }
104
105 private void getHomePageContent( HttpServletRequest request, XPage page )
106 {
107 Map<String, Object> model = new HashMap<String, Object>( );
108
109 model.put( MARK_APPLICATIONS_LIST, getActiveApplications( ) );
110
111 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_HOMEPAGE, request.getLocale( ), model );
112
113 page.setContent( template.getHtml( ) );
114 page.setTitle( AppPropertiesService.getProperty( PROPERTY_PAGE_TITLE ) );
115 page.setPathLabel( AppPropertiesService.getProperty( PROPERTY_PAGE_PATH ) );
116 }
117
118 private List<Application> getActiveApplications( )
119 {
120 List<Application> list = new ArrayList<Application>( );
121
122 for ( Application application : ApplicationHome.getApplicationsList( ) )
123 {
124 if ( application.getPublishStatus( ) > 0 )
125 {
126 list.add( application );
127 }
128 }
129
130 return list;
131 }
132
133 private void getApplicationContent( HttpServletRequest request, XPage page, int nApplicationId )
134 {
135 Application application = ApplicationHome.findByPrimaryKey( nApplicationId );
136 Map<String, Object> model = new HashMap<String, Object>( );
137
138 model.put( MARK_APPLICATION, application );
139 model.put( MARK_COMPONENTS_LIST, ComponentHome.findByApplication( application.getId( ) ) );
140
141 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_APPLICATION, request.getLocale( ), model );
142
143 page.setContent( template.getHtml( ) );
144 page.setTitle( AppPropertiesService.getProperty( PROPERTY_PAGE_TITLE ) + " - " + application.getTitle( ) );
145 page.setExtendedPathLabel( getXmlExtendedPath( application.getTitle( ) ) );
146 }
147
148 public String generatePOM( HttpServletRequest request )
149 {
150 int nApplicationId = Integer.parseInt( request.getParameter( PARAMETER_ID_APPLICATION ) );
151 Application application = ApplicationHome.findByPrimaryKey( nApplicationId );
152 Map<String, Object> model = new HashMap<String, Object>( );
153
154 model.put( MARK_APPLICATION, application );
155 model.put( MARK_COMPONENTS_LIST, ComponentHome.findByApplication( application.getId( ) ) );
156
157 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_POM, request.getLocale( ), model );
158
159 return template.getHtml( );
160 }
161
162
163
164
165
166
167
168
169 private ReferenceList getXmlExtendedPath( String strPageName )
170 {
171 ReferenceList list = new ReferenceList( );
172 list.addItem( AppPropertiesService.getProperty( PROPERTY_PAGE_PATH ), URL_HOME_APPSTORE );
173 list.addItem( strPageName, "" );
174
175 return list;
176 }
177 }