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.business.style.PageTemplate;
38 import fr.paris.lutece.portal.business.style.PageTemplateHome;
39 import fr.paris.lutece.util.xml.XmlUtil;
40
41 import java.util.List;
42
43 import javax.ws.rs.GET;
44 import javax.ws.rs.Path;
45 import javax.ws.rs.Produces;
46 import javax.ws.rs.core.MediaType;
47
48
49
50
51
52 @Path( RestConstants.BASE_PATH + Constants.PLUGIN_NAME + "/pagetemplate" )
53 public class PageTemplateRest
54 {
55 private static final String KEY_ID = "id";
56 private static final String KEY_NAME = "name";
57 private static final String KEY_PAGE_TEMPLATE = "page-template";
58 private static final String KEY_PAGE_TEMPLATES = "page-templates";
59
60 @GET
61 @Path( "/" )
62 @Produces( MediaType.APPLICATION_XML )
63 public String getPageTemplateXml( )
64 {
65 List<PageTemplate> list = PageTemplateHome.getPageTemplatesList( );
66 StringBuffer sbXML = new StringBuffer( );
67 sbXML.append( "<?xml version=\"1.0\"?>\n" );
68 XmlUtil.beginElement( sbXML, KEY_PAGE_TEMPLATES );
69
70 for ( PageTemplate page : list )
71 {
72 XmlUtil.beginElement( sbXML, KEY_PAGE_TEMPLATE );
73 XmlUtil.addElement( sbXML, KEY_ID, page.getId( ) );
74 XmlUtil.addElement( sbXML, KEY_NAME, page.getDescription( ) );
75 XmlUtil.endElement( sbXML, KEY_PAGE_TEMPLATE );
76 }
77
78 XmlUtil.endElement( sbXML, KEY_PAGE_TEMPLATES );
79
80 return sbXML.toString( );
81 }
82 }