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.portalrest.rs;
35
36 import fr.paris.lutece.plugins.rest.service.RestConstants;
37 import fr.paris.lutece.portal.service.portal.ThemesService;
38 import fr.paris.lutece.util.ReferenceItem;
39 import fr.paris.lutece.util.ReferenceList;
40 import fr.paris.lutece.util.xml.XmlUtil;
41
42 import javax.servlet.http.HttpServletRequest;
43
44 import javax.ws.rs.GET;
45 import javax.ws.rs.Path;
46 import javax.ws.rs.Produces;
47 import javax.ws.rs.core.Context;
48 import javax.ws.rs.core.MediaType;
49
50
51
52
53
54 @Path( RestConstants.BASE_PATH + Constants.PLUGIN_NAME + "/theme" )
55 public class ThemeRest
56 {
57 private static final String KEY_NAME = "name";
58 private static final String KEY_DESCRIPTION = "description";
59 private static final String KEY_THEME = "theme";
60 private static final String KEY_THEMES = "themes";
61
62 @GET
63 @Path( "/" )
64 @Produces( MediaType.APPLICATION_XML )
65 public String getThemeXml( @Context
66 HttpServletRequest request )
67 {
68 ReferenceList list = ThemesService.getPageThemes( request.getLocale( ) );
69 StringBuffer sbXML = new StringBuffer( );
70 sbXML.append( "<?xml version=\"1.0\"?>\n" );
71 XmlUtil.beginElement( sbXML, KEY_THEMES );
72
73 for ( ReferenceItem item : list )
74 {
75 XmlUtil.beginElement( sbXML, KEY_THEME );
76 XmlUtil.addElement( sbXML, KEY_NAME, item.getCode( ) );
77 XmlUtil.addElement( sbXML, KEY_DESCRIPTION, item.getName( ) );
78 XmlUtil.endElement( sbXML, KEY_THEME );
79 }
80
81 XmlUtil.endElement( sbXML, KEY_THEMES );
82
83 return sbXML.toString( );
84 }
85 }