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.childpages.business.portlet;
35
36 import fr.paris.lutece.portal.business.page.Page;
37 import fr.paris.lutece.portal.business.page.PageHome;
38 import fr.paris.lutece.portal.business.portlet.Portlet;
39 import fr.paris.lutece.portal.web.admin.AdminPageJspBean;
40 import fr.paris.lutece.util.xml.XmlUtil;
41
42 import java.util.Collection;
43
44 import javax.servlet.http.HttpServletRequest;
45
46
47
48
49
50 public class ChildPagesPortlet extends Portlet
51 {
52
53
54 public static final String TAG_CHILD_PAGE = "child-page";
55 public static final String TAG_CHILD_PAGE_ID = "child-page-id";
56 public static final String TAG_CHILD_PAGE_NAME = "child-page-name";
57 public static final String TAG_CHILD_PAGE_DESCRIPTION = "child-page-description";
58 public static final String TAG_CHILD_PAGE_IMAGE = "child-page-image";
59 public static final String TAG_CHILD_PAGES_PORTLET_LIST = "child-pages-portlet";
60
61
62
63 private int _nParentPageId;
64
65
66
67
68 public ChildPagesPortlet( )
69 {
70 setPortletTypeId( ChildPagesPortletHome.getInstance( ).getPortletTypeId( ) );
71 }
72
73
74
75
76
77
78 public void setParentPageId( int nParentPageId )
79 {
80 _nParentPageId = nParentPageId;
81 }
82
83
84
85
86
87
88 public int getParentPageId( )
89 {
90 return _nParentPageId;
91 }
92
93
94
95
96
97
98
99 public String getXml( HttpServletRequest request )
100 {
101 StringBuffer strXml = new StringBuffer( );
102 XmlUtil.beginElement( strXml, TAG_CHILD_PAGES_PORTLET_LIST );
103
104 Collection<Page> pages;
105 if ( getParentPageId( ) == 0 )
106 {
107 pages = PageHome.getChildPages( getPageId( ) );
108 } else
109 {
110 pages = PageHome.getChildPages( getParentPageId( ) );
111 }
112
113 AdminPageJspBean adminPage = new AdminPageJspBean( );
114 for ( Page page : pages )
115 {
116 if ( request != null )
117 {
118 if ( page.isVisible( request ) )
119 {
120 XmlUtil.beginElement( strXml, TAG_CHILD_PAGE );
121 XmlUtil.addElement( strXml, TAG_CHILD_PAGE_ID, page.getId( ) );
122 XmlUtil.addElement( strXml, TAG_CHILD_PAGE_NAME, page.getName( ) );
123 XmlUtil.addElement( strXml, TAG_CHILD_PAGE_DESCRIPTION, page.getDescription( ) );
124
125 if ( page.getImageContent( ) != null )
126 {
127 int nImageLength = page.getImageContent( ).length;
128
129 if ( nImageLength >= 1 )
130 {
131 String strPageId = new Integer( page.getId( ) ).toString( );
132 XmlUtil.addElement( strXml, TAG_CHILD_PAGE_IMAGE,
133 adminPage.getResourceImagePage( page, strPageId ) );
134 }
135 }
136
137 XmlUtil.endElement( strXml, TAG_CHILD_PAGE );
138 }
139 }
140 }
141
142 XmlUtil.endElement( strXml, TAG_CHILD_PAGES_PORTLET_LIST );
143
144 return addPortletTags( strXml );
145 }
146
147
148
149
150
151
152
153 public String getXmlDocument( HttpServletRequest request )
154 {
155 return XmlUtil.getXmlHeader( ) + getXml( request );
156 }
157
158
159
160
161 public void update( )
162 {
163 ChildPagesPortletHome.getInstance( ).update( this );
164 }
165
166
167
168
169 public void remove( )
170 {
171 ChildPagesPortletHome.getInstance( ).remove( this );
172 }
173 }