KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > jsp > tags > InfoTag


1 package org.apache.jetspeed.services.jsp.tags;
2
3 /*
4  * Copyright 2000-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.util.Date JavaDoc;
20 import java.text.DateFormat JavaDoc;
21
22 import javax.servlet.jsp.JspException JavaDoc;
23 import javax.servlet.jsp.PageContext JavaDoc;
24 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
25
26 // Turbine Classes
27
import org.apache.turbine.util.RunData;
28 import org.apache.turbine.services.jsp.JspService;
29
30 // Jetspeed classes
31
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
32 import org.apache.jetspeed.services.logging.JetspeedLogger;
33
34 /**
35  * Supporting class for the info tag.
36  * Sends the screens ecs element's content to the output stream.
37  *
38  * @author <a HREF="mailto:ingo@raleigh.ibm.com">Ingo Schuster</a>
39  * @author <a HREF="mailto:paulsp@apache.org">Paul Spencer</a>
40  */

41 public class InfoTag extends TagSupport JavaDoc
42 {
43     /**
44      * Static initialization of the logger for this class
45      */

46     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(InfoTag.class.getName());
47     
48     /**
49      * requestedInfo parameter defines type of Info that is being requested
50      */

51     private String JavaDoc requestedInfo;
52
53     /**
54      * The setter for requestedInfo parameter
55      */

56     public void setRequestedInfo(String JavaDoc requestedInfo)
57     {
58         this.requestedInfo = requestedInfo;
59     }
60
61
62     public int doStartTag() throws JspException JavaDoc
63     {
64         RunData data = (RunData)pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
65         
66         try
67         {
68             String JavaDoc result = "jetspeed-InfoTag: unknown parameter >" + requestedInfo +"<";
69
70             /* Server Date */
71             if (requestedInfo.equalsIgnoreCase("ServerDate")) {
72                 result = DateFormat.getDateTimeInstance().format( new Date JavaDoc());
73             }
74
75             /* User Name */
76             if (requestedInfo.equalsIgnoreCase("UserName")) {
77               result = data.getUser().getUserName();
78             }
79
80             /* First Name */
81             if (requestedInfo.equalsIgnoreCase("FirstName")) {
82               result = data.getUser().getFirstName();
83             }
84
85             /* Last Name */
86             if (requestedInfo.equalsIgnoreCase("LastName")) {
87               result = data.getUser().getLastName();
88             }
89
90             /* EMail */
91             if (requestedInfo.equalsIgnoreCase("EMail")) {
92               result = data.getUser().getEmail();
93             }
94             pageContext.getOut().print(result);
95         }
96         catch (Exception JavaDoc e)
97         {
98             String JavaDoc message = "Error processing info-tag, parameter: "+ requestedInfo;
99             logger.error(message, e);
100             try
101             {
102                 data.getOut().print("Error processing info-tag, parameter: "+ requestedInfo);
103             }
104             catch(java.io.IOException JavaDoc ioe) {}
105         }
106         return EVAL_BODY_INCLUDE;
107     }
108 }
109
Popular Tags