1 package org.apache.jetspeed.portal.controls;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import org.apache.ecs.html.IMG;
22 import org.apache.ecs.html.B;
23 import org.apache.ecs.html.Table;
24 import org.apache.ecs.html.TD;
25 import org.apache.ecs.html.TR;
26 import org.apache.ecs.ConcreteElement;
27 import org.apache.ecs.ElementContainer;
28
29
30
31 import org.apache.jetspeed.util.JetspeedException;
32 import org.apache.jetspeed.util.MimeType;
33 import org.apache.jetspeed.util.URILookup;
34 import org.apache.jetspeed.capability.CapabilityMap;
35 import org.apache.jetspeed.capability.CapabilityMapFactory;
36 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
37 import org.apache.jetspeed.services.logging.JetspeedLogger;
38 import org.apache.jetspeed.services.resources.JetspeedResources;
39
40
41 import org.apache.turbine.util.ContentURI;
42 import org.apache.turbine.util.RunData;
43
44
45 import java.util.Vector;
46
47 /***
48 <p>
49 This control renders the title of a portlet for MimeTyps WML and HTML.
50 For WML only the title (represented as a link) is returned. In case that
51 the device requests html the title will be rendered within a titlebar (with
52 buttons for editing or maximizing the portlet).
53 </p>
54 @author <a href="mailto:sasalda@de.ibm.com">Sascha Alda</a>
55 @author <a href="mailto:stephan.hesmer@de.ibm.com">Stephan Hesmer</a>
56 @author <a href="mailto:sgala@apache.org">Santiago Gala</a>
57 @version $Id: TitleControl.java,v 1.14 2004/02/23 03:25:35 jford Exp $
58 */
59 public class TitleControl extends AbstractPortletControl {
60
61 /***
62 * Static initialization of the logger for this class
63 */
64 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(TitleControl.class.getName());
65
66 /***
67 Method checks, which MimeType is requested. According to this MimeTyp, the
68 appropriate method is invoked (getWMLContent() or getHTMLContent() ).
69 @param rundata RunData object from Turbine.
70 @return ConcreteElement object, including the complete ECS code for rendering
71 the page.
72 */
73 public ConcreteElement getContent( RunData rundata ) {
74 CapabilityMap cm = CapabilityMapFactory.getCapabilityMap( rundata );
75 if ( cm.getPreferredType().equals( MimeType.HTML ) ) {
76 return getHTMLContent( rundata );
77 }
78 if ( cm.getPreferredType().equals( MimeType.WML ) ) {
79 return getWMLContent( rundata );
80 }
81 logger.error("The Given MIME-Type is not supportet for this control");
82 return null;
83 }
84
85
86 /***
87 Method returns content for html, in case that the requested MimeTyp is html.
88 @param rundata RunData object from Turbine.
89 @return ConcreteElement object, including the complete ECS code for rendering
90 the html page.
91 */
92 public ConcreteElement getHTMLContent( RunData rundata ) {
93
94 ElementContainer base = new ElementContainer();
95
96
97 Table t = new Table()
98 .setBgColor( this.getColor() )
99 .setBorder(0)
100 .setCellPadding(1)
101 .setCellSpacing(0)
102 .setWidth( getWidth() )
103 .setAlign( "center" );
104
105
106 ConcreteElement[] options = this.getPortletOptions( rundata );
107
108 TR finalTitle = new TR()
109 .setBgColor( this.getTitleColor() )
110 .addElement( new TD()
111 .setBgColor( this.getTitleColor() )
112 .setNoWrap( true )
113 .setWidth("100%")
114 .setVAlign("middle")
115 .addElement( new B()
116 .addElement( getPortlet().getTitle() )
117 .addElement(" ") ) );
118
119 if ( options.length > 0 ) {
120
121 ElementContainer alloptions = new ElementContainer();
122 for (int i = 0; i < options.length; ++i) {
123 alloptions.addElement( options[i] );
124 }
125
126 finalTitle.addElement( new TD()
127 .setBgColor( this.getTitleColor() )
128 .setNoWrap( true )
129 .setAlign("right")
130 .setVAlign("middle")
131 .addElement( alloptions ) );
132
133 }
134
135
136
137 t.addElement( finalTitle );
138
139 base.addElement( t );
140
141 return base;
142 }
143
144 /***
145 Method returns content for WML, in case that the requested MimeTyp is WML.
146 @param rundata RunData object from Turbine.
147 @return ConcreteElement object, including the complete ECS code for rendering
148 the html page.
149 */
150 public ConcreteElement getWMLContent( RunData rundata ) {
151 ElementContainer ec = new ElementContainer();
152 try {
153 ec.addElement(new org.apache.ecs.wml.P()
154 .addElement(
155 new org.apache.ecs.wml.A(
156 URILookup.getURI( URILookup.TYPE_HOME,
157 URILookup.SUBTYPE_MAXIMIZE,
158 getName(),
159 rundata ) )
160 .addElement( getTitle() ) ) );
161 }
162 catch (JetspeedException e) {
163 logger.error("Exception", e);
164 }
165 return ec;
166 }
167
168
169 /***
170 Method returns the title of the portlet, which is placed within this control.
171 @return String object, representing the portlet's title.
172 */
173 public String getTitle(){
174 return getPortlet().getTitle();
175 }
176
177 /***
178 Method checks whether the requested MimeTyp is supported by this control.
179 Moreover, it checks, if the included portlet fits the given MimeTyp as well.
180 Thus, the method returns true, iff both the control and the portlet(set) support
181 the requested MimeType. Otherwise false is returned.
182 @param mimeType MimeType object describing the requested MimeTyp.
183 @return Boolean true if MimeTyp is supported, false if not.
184 */
185 public boolean supportsType( MimeType mimeType ) {
186 if ( (!MimeType.HTML.equals( mimeType )) &&
187 (!MimeType.WML.equals( mimeType )) ){
188 return false;
189 }
190
191 return getPortlet().supportsType( mimeType );
192 }
193
194 /***
195 Get the options for this portlet.
196 */
197 private ConcreteElement[] getPortletOptions( RunData rundata ) {
198
199 Vector v = new Vector();
200 ContentURI content = new ContentURI( rundata );
201
202 int type = URILookup.getURIType(this.getPortlet(),
203 rundata);
204 int subtype = URILookup.SUBTYPE_NONE;
205 try {
206 subtype = URILookup.getURISubType(this.getPortlet(),
207 rundata);
208 }
209 catch (JetspeedException e) {
210 logger.error("Exception", e);
211 }
212
213 if ( type != URILookup.TYPE_EDIT_ACCOUNT) {
214 if ( ( rundata.getUser() != null ) &&
215 ( rundata.getUser().hasLoggedIn()) ) {
216 if ( this.getPortlet().getAllowEdit( rundata ) ) {
217 if (type!=URILookup.TYPE_INFO) {
218 try {
219 org.apache.ecs.html.A edit =
220 new org.apache.ecs.html.A(
221 URILookup.getURI( URILookup.TYPE_INFO,
222 URILookup.SUBTYPE_MARK,
223 this.getPortlet(),
224 rundata ) )
225 .addElement( new IMG( content.getURI( JetspeedResources.INFO_IMAGE ) )
226 .setBorder( 0 ) );
227
228 v.addElement( edit );
229 }
230 catch (JetspeedException e) {
231 logger.error("Exception", e);
232 }
233 }
234 }
235
236 }
237
238 if ( this.getPortlet().getAllowMaximize( rundata ) ) {
239 try {
240 if ( subtype != URILookup.SUBTYPE_MAXIMIZE ) {
241 org.apache.ecs.html.A max =
242 new org.apache.ecs.html.A(
243 URILookup.getURI( URILookup.TYPE_HOME,
244 URILookup.SUBTYPE_MAXIMIZE,
245 this.getPortlet(),
246 rundata ) )
247 .addElement( new IMG( content.getURI( JetspeedResources.MAX_IMAGE ) )
248 .setBorder( 0 ) );
249
250 v.addElement( max );
251 }
252 }
253 catch (JetspeedException e) {
254 logger.error("Exception", e);
255 }
256 }
257 }
258
259 ConcreteElement[] elements = new ConcreteElement[v.size()];
260 v.copyInto(elements);
261 return elements;
262 }
263
264
265
266 }