KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > impl > portletAPIImp > tags > XURLTag


1 /**
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5
6 /**
7  * Created by The eXo Platform SARL
8  * Author : Mestrallet Benjamin
9  * benjmestrallet@users.sourceforge.net
10  * Date: Aug 20, 2003
11  * Time: 2:00:32 PM
12  */

13 package org.exoplatform.services.portletcontainer.impl.portletAPIImp.tags;
14
15 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
16 import javax.servlet.jsp.JspException JavaDoc;
17 import javax.portlet.*;
18
19 import java.io.IOException JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22
23 public abstract class XURLTag extends BodyTagSupport JavaDoc{
24
25   protected WindowState windowState;
26   protected PortletMode portletMode;
27   protected String JavaDoc var;
28   protected boolean secure;
29   private Map JavaDoc parameters = new HashMap JavaDoc();
30
31   public void addParameter(String JavaDoc key, String JavaDoc value){
32     parameters.put(key, new String JavaDoc[]{value});
33   }
34
35   public void setWindowState(String JavaDoc windowState) {
36     if(WindowState.MAXIMIZED.toString().equals(windowState))
37       this.windowState = WindowState.MAXIMIZED;
38     else if (WindowState.MINIMIZED.toString().equals(windowState))
39       this.windowState = WindowState.MINIMIZED;
40     else if (WindowState.NORMAL.toString().equals(windowState))
41       this.windowState = WindowState.NORMAL;
42     else
43       this.windowState = new WindowState(windowState);
44   }
45
46   public void setPortletMode(String JavaDoc portletMode) {
47     if(PortletMode.EDIT.toString().equals(portletMode))
48       this.portletMode = PortletMode.EDIT;
49     else if(PortletMode.HELP.toString().equals(portletMode))
50       this.portletMode = PortletMode.HELP;
51     else if(PortletMode.VIEW.toString().equals(portletMode))
52       this.portletMode = PortletMode.VIEW;
53     else
54       this.portletMode =new PortletMode(portletMode);
55   }
56
57   public String JavaDoc getVar() {
58     return var;
59   }
60
61   public void setVar(String JavaDoc var) {
62     this.var = var;
63   }
64
65   public void setSecure(String JavaDoc secure) {
66     if(secure.equals("true"))
67       this.secure = true;
68     else
69       this.secure = false;
70   }
71
72   public int doStartTag() throws JspException JavaDoc {
73       return EVAL_BODY_BUFFERED;
74   }
75
76   public int doEndTag() throws JspException JavaDoc {
77     PortletURL portletURL = getPortletURL();
78     portletURL.setParameters(parameters);
79     try {
80       if(portletMode != null)
81         portletURL.setPortletMode(portletMode);
82       portletURL.setSecure(secure);
83       if(windowState != null)
84         portletURL.setWindowState(windowState);
85     } catch (PortletModeException e) {
86       throw new JspException JavaDoc(e);
87     } catch (WindowStateException e) {
88       throw new JspException JavaDoc(e);
89     } catch (PortletSecurityException e) {
90       throw new JspException JavaDoc(e);
91     }
92
93     if(var == null || "".equals(var)){
94       try {
95         pageContext.getOut().print(portletURL.toString());
96       } catch (IOException JavaDoc e1) {
97         throw new JspException JavaDoc(e1);
98       }
99     } else {
100       pageContext.setAttribute(var, portletURL.toString());
101     }
102     
103     return EVAL_PAGE;
104   }
105
106   public abstract PortletURL getPortletURL();
107 }
108
Popular Tags