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.links.web;
35
36 import fr.paris.lutece.plugins.links.business.Link;
37 import fr.paris.lutece.plugins.links.business.LinkHome;
38 import fr.paris.lutece.plugins.links.business.portlet.LinksPortletHome;
39 import fr.paris.lutece.portal.business.portlet.Portlet;
40 import fr.paris.lutece.portal.service.i18n.I18nService;
41 import fr.paris.lutece.portal.service.plugin.Plugin;
42 import fr.paris.lutece.portal.service.template.AppTemplateService;
43 import fr.paris.lutece.portal.service.util.AppPathService;
44 import fr.paris.lutece.portal.web.xpages.XPage;
45 import fr.paris.lutece.portal.web.xpages.XPageApplication;
46 import fr.paris.lutece.util.html.HtmlTemplate;
47
48 import java.util.ArrayList;
49 import java.util.Collection;
50 import java.util.HashMap;
51
52 import javax.servlet.http.HttpServletRequest;
53
54
55
56
57
58 public class LinksApp implements XPageApplication
59 {
60
61
62
63 private static final long serialVersionUID = -4031785213438754274L;
64
65
66 private static final String PROPERTY_LINKS_PATHLABEL = "links.xPageLinks.pagePathLabel";
67 private static final String PROPERTY_LINKS_TITLE = "links.xPageLinks.pageTitle";
68 private static final String TEMPLATE_PORTLET_BLOCK = "skin/plugins/links/block_portlet.html";
69 private static final String TEMPLATE_XPAGE_LINKS = "skin/plugins/links/page_links_summary.html";
70 private static final String MARK_PORTLET_NAME = "portlet_name";
71 private static final String MARK_LINKS_LIST = "links_list";
72 private static final String MARK_PORTLETS_LIST = "list_portlets";
73
74
75
76
77 public LinksApp( )
78 {
79 }
80
81
82
83
84
85
86
87
88
89 public XPage getPage( HttpServletRequest request, int nMode, Plugin plugin )
90 {
91 String strServerKey = AppPathService.getVirtualHostKey( request );
92 XPage page = new XPage( );
93
94 page.setContent( getPortletBlock( request, strServerKey ) );
95 page.setTitle( I18nService.getLocalizedString( PROPERTY_LINKS_TITLE, request.getLocale( ) ) );
96 page.setPathLabel( I18nService.getLocalizedString( PROPERTY_LINKS_PATHLABEL, request.getLocale( ) ) );
97
98 return page;
99 }
100
101
102
103
104
105
106
107 public String getPortletBlock( HttpServletRequest request, String strServerKey )
108 {
109 StringBuffer strBlocPortlet = new StringBuffer( );
110 Collection<Portlet> listePortlet = LinksPortletHome.getPortletsInLinksPage( );
111 Collection<Link> listLinksForVhost = new ArrayList<>( );
112 HashMap<String, Object> modelTemplateXpageLinks = new HashMap<>( );
113
114 for ( Portlet portlet : listePortlet )
115 {
116 int nPortletId = portlet.getId( );
117 HashMap<String, Object> model = new HashMap<>( );
118 Collection<Link> listLinks = LinkHome.findByPortlet( nPortletId );
119
120 for ( Link link : listLinks )
121 {
122 String urlVhost = link.getUrl( strServerKey );
123
124 if ( urlVhost != null )
125 {
126 link.setUrl( urlVhost );
127 listLinksForVhost.add( link );
128 }
129 }
130
131 if ( !listLinksForVhost.isEmpty( ) )
132 {
133 model.put( MARK_LINKS_LIST, listLinksForVhost );
134 model.put( MARK_PORTLET_NAME, portlet.getName( ) );
135
136 HtmlTemplate tListLinks = AppTemplateService.getTemplate( TEMPLATE_PORTLET_BLOCK,
137 request.getLocale( ), model );
138 strBlocPortlet.append( tListLinks.getHtml( ) );
139 listLinksForVhost.clear( );
140 }
141 }
142
143 modelTemplateXpageLinks.put( MARK_PORTLETS_LIST, strBlocPortlet.toString( ) );
144
145 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_LINKS, request.getLocale( ),
146 modelTemplateXpageLinks );
147
148 return template.getHtml( );
149 }
150 }