KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > clipbuilder > html > web > Url > Impl > PortletUrlEncoder


1 package org.jahia.clipbuilder.html.web.Url.Impl;
2
3 import javax.portlet.*;
4 import org.jahia.clipbuilder.html.web.Url.URLMap;
5 import org.jahia.clipbuilder.html.util.Constants;
6
7 /**
8  * Encoder for portlets
9  *
10  *@author Tlili Khaled
11  */

12 public class PortletUrlEncoder extends BaseUrlEncoder {
13     private RenderRequest request;
14     private RenderResponse response;
15     private String JavaDoc encodedUrl_;
16     private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(PortletUrlEncoder.class);
17
18
19     /**
20      * Constructor for the PortletUrlEncoder object
21      *
22      *@param request Description of Parameter
23      *@param response Description of Parameter
24      */

25     public PortletUrlEncoder(RenderRequest request, RenderResponse response) {
26         setRequest(request);
27         setResponse(response);
28     }
29
30
31     /**
32      * Sets the Request attribute of the PortletUrlEncoder object
33      *
34      *@param request The new Request value
35      */

36     public void setRequest(RenderRequest request) {
37         this.request = request;
38     }
39
40
41     /**
42      * Sets the Response attribute of the PortletUrlEncoder object
43      *
44      *@param response The new Response value
45      */

46     public void setResponse(RenderResponse response) {
47         this.response = response;
48     }
49
50
51     /**
52      * Gets the Request attribute of the PortletUrlEncoder object
53      *
54      *@return The Request value
55      */

56     public RenderRequest getRequest() {
57         return request;
58     }
59
60
61     /**
62      * Gets the Response attribute of the PortletUrlEncoder object
63      *
64      *@return The Response value
65      */

66     public RenderResponse getResponse() {
67         return response;
68     }
69
70
71     /**
72      * Gets the EncodedUrl attribute of the PortletUrlEncoder object
73      *
74      *@return The EncodedUrl value
75      */

76     public String JavaDoc getEncodedUrl() {
77         if (encodedUrl_ == null) {
78             encodeUrl();
79         }
80         return encodedUrl_;
81     }
82
83         /**
84          * Gets the LocalUriResource attribute of the UrlEncoder object
85          *
86          *@param resourcePath Description of Parameter
87          *@return The LocalUriResource value
88          */

89         public String JavaDoc getLocalUriResource(String JavaDoc resourcePath) {
90                 String JavaDoc uri = getRequest().getContextPath() + resourcePath;
91                 return uri;
92         }
93
94
95         /**
96          * Gets the LocalUrl attribute of the UrlEncoder object
97          *
98          *@param url Description of Parameter
99          *@return The LocalUrl value
100          */

101         public String JavaDoc getLocalUrl(String JavaDoc url) {
102                 String JavaDoc localUrl = getRequest().getContextPath() + url;
103                 return getResponse().encodeURL(localUrl);
104         }
105
106
107
108     /**
109      * Description of the Method
110      */

111     public void encodeUrl() {
112                 if(getResponse() == null){
113                     encodedUrl_ = "http://www.google.ch";
114                     return;
115                 }
116                 PortletURL encodedURL = getResponse().createActionURL();
117         try {
118             logger.debug("[ Encoding the url ]");
119             String JavaDoc action = getAction();
120
121             // record in the urlMap
122
String JavaDoc hash = getUrlWrapper().getHash();
123             URLMap map = (URLMap) getRequest().getPortletSession().getAttribute(Constants.URL_MAP);
124             map.addSourceUrl(getUrlWrapper(), hash);
125
126             // build the new url
127
encodedURL.setParameter("show", action);
128             encodedURL.setParameter(org.jahia.clipbuilder.html.struts.Util.Constants.LINK_HASH, action);
129                         String JavaDoc nameSpace = getResponse().getNamespace();
130                         encodedURL.setParameter(org.jahia.clipbuilder.html.struts.Util.Constants.NAME_SPACE,nameSpace);
131             encodedUrl_ = encodedURL.toString();
132         }
133         catch (Exception JavaDoc ex) {
134             logger.error("Error Exception: " + ex.toString());
135             ex.printStackTrace();
136         }
137
138
139     }
140 }
141
Popular Tags