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.googleapi.web;
35
36 import fr.paris.lutece.plugins.googleapi.business.FeedProvider;
37 import fr.paris.lutece.plugins.googleapi.business.Item;
38 import fr.paris.lutece.plugins.googleapi.service.FeedsService;
39 import fr.paris.lutece.portal.service.i18n.I18nService;
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.AppLogService;
43 import fr.paris.lutece.portal.web.xpages.XPage;
44 import fr.paris.lutece.portal.web.xpages.XPageApplication;
45 import fr.paris.lutece.util.html.HtmlTemplate;
46
47 import org.xml.sax.SAXException;
48
49 import java.io.IOException;
50
51 import java.util.ArrayList;
52 import java.util.HashMap;
53 import java.util.List;
54 import java.util.Locale;
55
56 import javax.servlet.http.HttpServletRequest;
57
58 import javax.xml.parsers.ParserConfigurationException;
59
60
61
62
63
64
65 public class GoogleApiApp implements XPageApplication
66 {
67 private static final String TEMPLATE_PROJECT = "skin/plugins/googleapi/home.html";
68 private static final String KEY_PAGE_TITLE = "googleapi.pageTitle";
69 private static final String KEY_PAGE_PATH = "googleapi.pagePath";
70 private static final String MARK_QUERY = "query";
71 private static final String MARK_PROVIDER = "provider";
72 private static final String MARK_ITEMS_LIST = "items_list";
73 private static final String MARK_FEEDS_LIST = "feeds_list";
74 private static final String PARAMETER_SEARCH = "search";
75 private static final String PARAMETER_PROVIDER = "provider";
76
77
78
79
80
81
82
83
84 public XPage getPage( HttpServletRequest request, int nMode, Plugin plugin )
85 {
86 XPage page = new XPage( );
87
88 Locale locale = request.getLocale( );
89 HashMap model = new HashMap( );
90
91 String strQuery = request.getParameter( PARAMETER_SEARCH );
92 String strProvider = request.getParameter( PARAMETER_PROVIDER );
93
94 FeedProvider fp = FeedsService.getInstance( ).getProvider( strProvider );
95
96 List<Item> listItems = new ArrayList<Item>( );
97
98 if ( strQuery != null )
99 {
100 try
101 {
102 FeedsService.getInstance( ).getItems( strQuery, listItems, fp );
103 }
104 catch ( ParserConfigurationException e )
105 {
106 AppLogService.error( "Error retrieving items : " + e.getMessage( ), e );
107 }
108 catch ( SAXException e )
109 {
110 AppLogService.error( "Error retrieving items : " + e.getMessage( ), e );
111 }
112 catch ( IOException e )
113 {
114 AppLogService.error( "Error retrieving items : " + e.getMessage( ), e );
115 }
116 }
117
118 model.put( MARK_QUERY, ( strQuery != null ) ? strQuery : "" );
119 model.put( MARK_PROVIDER, ( strProvider != null ) ? strProvider : "" );
120 model.put( MARK_ITEMS_LIST, listItems );
121 model.put( MARK_FEEDS_LIST, FeedsService.getInstance( ).getProviders( ) );
122
123 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PROJECT, locale, model );
124 page.setContent( template.getHtml( ) );
125
126
127 Object[] args = { model.get( "name" ) };
128 String strTitle = I18nService.getLocalizedString( KEY_PAGE_TITLE, args, locale );
129 String strPath = I18nService.getLocalizedString( KEY_PAGE_PATH, args, locale );
130 page.setTitle( strTitle );
131 page.setPathLabel( strPath );
132
133 return page;
134 }
135 }