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.xmlpage.business.portlet;
35
36 import fr.paris.lutece.plugins.xmlpage.service.XmlPageElement;
37 import fr.paris.lutece.plugins.xmlpage.service.XmlPageService;
38 import fr.paris.lutece.plugins.xmlpage.util.XmlPageContentUtils;
39 import fr.paris.lutece.portal.business.portlet.Portlet;
40 import fr.paris.lutece.portal.service.util.AppPropertiesService;
41 import fr.paris.lutece.util.xml.XmlUtil;
42
43 import java.util.HashMap;
44 import java.util.Map;
45
46 import javax.servlet.http.HttpServletRequest;
47
48
49
50
51
52 public class XmlPagePortlet extends Portlet
53 {
54
55 private static final String PROPERTY_TRANSFORM_CACHE = "xmlpage.transform.cache";
56 private static final String PROPERTY_PARAMETERS_LIST = "xmlpage.parameters.list";
57 private static final String PROPERTY_PARAMETERS_LIST_SEPARATOR = "xmlpage.parameters.list.separator";
58
59
60 private static final String TAG_PORTLET_XMLPAGE = "xmlpage-portlet";
61 private static final String TAG_PORTLET_XMLPAGE_CONTENT = "xmlpage-portlet-content";
62 private static final String EMPTY_STRING = "";
63 private String _strPageName;
64 private String _strStyle;
65
66
67
68
69 public XmlPagePortlet( )
70 {
71 setPortletTypeId( XmlPagePortletHome.getInstance( ).getPortletTypeId( ) );
72 }
73
74
75
76
77
78
79 public void setPageName( String strPageName )
80 {
81 _strPageName = strPageName;
82 }
83
84
85
86
87
88
89 public String getPageName( )
90 {
91 return _strPageName;
92 }
93
94
95
96
97
98
99 public void setStyle( String strStyle )
100 {
101 _strStyle = strStyle;
102 }
103
104
105
106
107
108
109 public String getStyle( )
110 {
111 return _strStyle;
112 }
113
114
115
116
117
118
119
120 public String getXmlDocument( HttpServletRequest request )
121 {
122 return XmlUtil.getXmlHeader( ) + getXml( request );
123 }
124
125
126
127
128
129
130
131 public String getXml( HttpServletRequest request )
132 {
133 StringBuffer strXml = new StringBuffer( );
134
135 String strTransformCache = AppPropertiesService.getProperty( PROPERTY_TRANSFORM_CACHE );
136 boolean bTransformCacheActive = Boolean.parseBoolean( strTransformCache );
137 Map<String, String> mapParameters = null;
138
139 if ( !bTransformCacheActive )
140 {
141 String strParametersList = AppPropertiesService.getProperty( PROPERTY_PARAMETERS_LIST );
142 String strParametersListSeparator = AppPropertiesService.getProperty( PROPERTY_PARAMETERS_LIST_SEPARATOR );
143 String[] listParameters = strParametersList.split( strParametersListSeparator );
144
145 mapParameters = new HashMap<String, String>( );
146
147 if ( request != null )
148 {
149 for ( String currentParameter : listParameters )
150 {
151 if ( request.getParameter( currentParameter ) != null )
152 {
153 mapParameters.put( currentParameter, request.getParameter( currentParameter ) );
154 }
155 }
156 }
157 }
158
159 XmlUtil.beginElement( strXml, TAG_PORTLET_XMLPAGE );
160
161 XmlPageElement xmlPageElement = XmlPageService.getInstance( ).getXmlPageResource( getPageName( ) );
162
163 String strContent = EMPTY_STRING;
164
165 if ( xmlPageElement != null )
166 {
167
168 strContent = XmlPageContentUtils.getContent( xmlPageElement, getStyle( ), bTransformCacheActive,
169 mapParameters );
170 }
171
172 XmlUtil.addElementHtml( strXml, TAG_PORTLET_XMLPAGE_CONTENT, strContent );
173 XmlUtil.endElement( strXml, TAG_PORTLET_XMLPAGE );
174
175 return addPortletTags( strXml );
176 }
177
178
179
180
181 public void update( )
182 {
183 XmlPagePortletHome.getInstance( ).update( this );
184 }
185
186
187
188
189 public void remove( )
190 {
191 XmlPagePortletHome.getInstance( ).remove( this );
192 }
193 }