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.tagcloud.business.portlet;
35
36 import fr.paris.lutece.plugins.tagcloud.business.Tag;
37 import fr.paris.lutece.plugins.tagcloud.business.TagHome;
38 import fr.paris.lutece.plugins.tagcloud.service.RandomTagService;
39 import fr.paris.lutece.portal.business.portlet.Portlet;
40 import fr.paris.lutece.portal.service.plugin.Plugin;
41 import fr.paris.lutece.portal.service.plugin.PluginService;
42 import fr.paris.lutece.util.xml.XmlUtil;
43
44 import java.util.ArrayList;
45 import java.util.Collection;
46
47 import javax.servlet.http.HttpServletRequest;
48
49
50
51
52
53 public class TagCloudPortlet extends Portlet
54 {
55
56
57 private static final String TAG_WEIGHT = "tag-weight";
58 private static final String TAG_NAME = "tag-name";
59 private static final String TAG_URL = "tag-url";
60 private static final String TAG_PORTLET_TAGCLOUD = "cloud";
61 private static final String TAG = "tag";
62
63
64 private int _nIdPortlet;
65 private int _nIdCloud;
66
67
68
69
70 public TagCloudPortlet( )
71 {
72 setPortletTypeId( TagCloudPortletHome.getInstance( ).getPortletTypeId( ) );
73 }
74
75
76
77
78
79
80
81 public String getXmlDocument( HttpServletRequest request )
82 {
83 return XmlUtil.getXmlHeader( ) + getXml( request );
84 }
85
86
87
88
89
90
91
92 public String getXml( HttpServletRequest request )
93 {
94 StringBuffer strXml = new StringBuffer( );
95 Plugin plugin = PluginService.getPlugin( "tagcloud" );
96
97
98 Collection<Integer> listClouds = TagCloudPortletHome.findTagCloudsInPortlet( this.getId( ) );
99 XmlUtil.beginElement( strXml, TAG_PORTLET_TAGCLOUD );
100
101 for ( Integer tagCloudId : listClouds )
102 {
103 ArrayList<Tag> listTags = TagHome.findTagsByCloud( tagCloudId.intValue( ), plugin );
104 RandomTagServiceud/service/RandomTagService.html#RandomTagService">RandomTagService service = new RandomTagService( );
105
106
107 if ( ( listTags != null ) && !listTags.isEmpty( ) )
108 {
109 listTags = service.transform( listTags );
110
111 for ( Tag tag : listTags )
112 {
113 XmlUtil.beginElement( strXml, TAG );
114 XmlUtil.addElement( strXml, TAG_NAME, tag.getTagName( ) );
115 XmlUtil.addElement( strXml, TAG_URL, tag.getTagUrl( ) );
116 XmlUtil.addElement( strXml, TAG_WEIGHT, tag.getTagWeight( ) );
117 XmlUtil.endElement( strXml, TAG );
118 }
119 }
120 else
121 {
122 XmlUtil.beginElement( strXml, TAG );
123 XmlUtil.addElement( strXml, TAG_NAME, "" );
124 XmlUtil.addElement( strXml, TAG_URL, "" );
125 XmlUtil.addElement( strXml, TAG_WEIGHT, "" );
126 XmlUtil.endElement( strXml, TAG );
127 }
128 }
129
130 XmlUtil.endElement( strXml, TAG_PORTLET_TAGCLOUD );
131
132
133 return addPortletTags( strXml );
134 }
135
136
137
138
139 public void update( )
140 {
141 TagCloudPortletHome.getInstance( ).update( this );
142 }
143
144
145
146
147 public void remove( )
148 {
149 TagCloudPortletHome.getInstance( ).remove( this );
150 }
151
152
153
154
155
156 public int getIdPortlet( )
157 {
158 return _nIdPortlet;
159 }
160
161
162
163
164
165 public void setIdPortlet( int nIdPortlet )
166 {
167 _nIdPortlet = nIdPortlet;
168 }
169
170
171
172
173
174 public int getIdCloud( )
175 {
176 return _nIdCloud;
177 }
178
179
180
181
182
183 public void setIdCloud( int nIdCloud )
184 {
185 _nIdCloud = nIdCloud;
186 }
187 }