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 private static final String PROPERTY_LINKS_PATHLABEL = "links.xPageLinks.pagePathLabel";
63 private static final String PROPERTY_LINKS_TITLE = "links.xPageLinks.pageTitle";
64 private static final String TEMPLATE_PORTLET_BLOCK = "skin/plugins/links/block_portlet.html";
65 private static final String TEMPLATE_XPAGE_LINKS = "skin/plugins/links/page_links_summary.html";
66 private static final String MARK_PORTLET_NAME = "portlet_name";
67 private static final String MARK_LINKS_LIST = "links_list";
68 private static final String MARK_PORTLETS_LIST = "list_portlets";
69
70
71
72
73 public LinksApp( )
74 {
75 }
76
77
78
79
80
81
82
83
84
85 public XPage getPage( HttpServletRequest request, int nMode, Plugin plugin )
86 {
87 String strServerKey = AppPathService.getVirtualHostKey( request );
88 XPage page = new XPage( );
89
90 page.setContent( getPortletBlock( request, strServerKey ) );
91 page.setTitle( I18nService.getLocalizedString( PROPERTY_LINKS_TITLE, request.getLocale( ) ) );
92 page.setPathLabel( I18nService.getLocalizedString( PROPERTY_LINKS_PATHLABEL, request.getLocale( ) ) );
93
94 return page;
95 }
96
97
98
99
100
101
102
103 public String getPortletBlock( HttpServletRequest request, String strServerKey )
104 {
105 StringBuffer strBlocPortlet = new StringBuffer( );
106 Collection<Portlet> listePortlet = LinksPortletHome.getPortletsInLinksPage( );
107 Collection<Link> listLinksForVhost = new ArrayList<Link>( );
108 HashMap<String, Object> modelTemplateXpageLinks = new HashMap<String, Object>( );
109
110 for ( Portlet portlet : listePortlet )
111 {
112 int nPortletId = portlet.getId( );
113 HashMap model = new HashMap( );
114 Collection<Link> listLinks = LinkHome.findByPortlet( nPortletId );
115
116 for ( Link link : listLinks )
117 {
118 String urlVhost = link.getUrl( strServerKey );
119
120 if ( urlVhost != null )
121 {
122 link.setUrl( urlVhost );
123 listLinksForVhost.add( link );
124 }
125 }
126
127 if ( listLinksForVhost.size( ) > 0 )
128 {
129 model.put( MARK_LINKS_LIST, listLinksForVhost );
130 model.put( MARK_PORTLET_NAME, portlet.getName( ) );
131
132 HtmlTemplate tListLinks = AppTemplateService.getTemplate( TEMPLATE_PORTLET_BLOCK,
133 request.getLocale( ), model );
134 strBlocPortlet.append( tListLinks.getHtml( ) );
135 listLinksForVhost.clear( );
136 }
137 }
138
139 modelTemplateXpageLinks.put( MARK_PORTLETS_LIST, strBlocPortlet.toString( ) );
140
141 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_XPAGE_LINKS, request.getLocale( ),
142 modelTemplateXpageLinks );
143
144 return template.getHtml( );
145 }
146 }