KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > wsrp > consumer > impl > URLTemplateComposerImpl


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

5
6 package org.exoplatform.services.wsrp.consumer.impl;
7
8 import org.exoplatform.Constants;
9 import org.exoplatform.services.wsrp.WSRPConstants;
10 import org.exoplatform.services.wsrp.consumer.URLTemplateComposer;
11
12 /*
13  * @author Mestrallet Benjamin
14  * benjmestrallet@users.sourceforge.net
15  * Date: 6 févr. 2004
16  * Time: 13:05:01
17  */

18
19 public class URLTemplateComposerImpl implements URLTemplateComposer{
20
21   private static final String JavaDoc SECURE_PROTOCOL = "https://";
22   private static final String JavaDoc NON_SECURE_PROTOCOL = "http://";
23   private String JavaDoc host = "localhost";
24   private int port = 8080;
25
26   public void setHost(String JavaDoc host) {
27     this.host = host;
28   }
29
30   public void setPort(int port) {
31     this.port = port;
32   }
33
34   public String JavaDoc createBlockingActionTemplate(String JavaDoc path) {
35     StringBuffer JavaDoc sB = new StringBuffer JavaDoc();
36     sB.append(NON_SECURE_PROTOCOL);
37     manageServerPath(sB, path);
38     appendParameters(sB);
39     return sB.toString();
40   }
41
42   public String JavaDoc createSecureBlockingActionTemplate(String JavaDoc path) {
43     StringBuffer JavaDoc sB = new StringBuffer JavaDoc();
44     sB.append(SECURE_PROTOCOL);
45     manageServerPath(sB, path);
46     appendParameters(sB);
47     return sB.toString();
48   }
49
50   public String JavaDoc createRenderTemplate(String JavaDoc path) {
51     StringBuffer JavaDoc sB = new StringBuffer JavaDoc();
52     sB.append(NON_SECURE_PROTOCOL);
53     manageServerPath(sB, path);
54     appendParameters(sB);
55     return sB.toString();
56   }
57
58   public String JavaDoc createSecureRenderTemplate(String JavaDoc path) {
59     StringBuffer JavaDoc sB = new StringBuffer JavaDoc();
60     sB.append(SECURE_PROTOCOL);
61     manageServerPath(sB, path);
62     appendParameters(sB);
63     return sB.toString();
64   }
65
66   public String JavaDoc createResourceTemplate(String JavaDoc path) {
67     StringBuffer JavaDoc sB = new StringBuffer JavaDoc();
68     sB.append(NON_SECURE_PROTOCOL);
69     manageServerPath(sB, path);
70     appendParameters(sB);
71     return sB.toString();
72   }
73
74   public String JavaDoc createSecureResourceTemplate(String JavaDoc path) {
75     StringBuffer JavaDoc sB = new StringBuffer JavaDoc();
76     sB.append(SECURE_PROTOCOL);
77     manageServerPath(sB, path);
78     appendParameters(sB);
79     return sB.toString();
80   }
81
82   public String JavaDoc createDefaultTemplate(String JavaDoc path) {
83     StringBuffer JavaDoc sB = new StringBuffer JavaDoc();
84     sB.append(NON_SECURE_PROTOCOL);
85     manageServerPath(sB, path);
86     appendParameters(sB);
87     return sB.toString();
88   }
89
90   public String JavaDoc createSecureDefaultTemplate(String JavaDoc path) {
91     StringBuffer JavaDoc sB = new StringBuffer JavaDoc();
92     sB.append(SECURE_PROTOCOL);
93     manageServerPath(sB, path);
94     appendParameters(sB);
95     return sB.toString();
96   }
97
98   public String JavaDoc getNamespacePrefix() {
99     return "";
100   }
101
102   private void manageServerPath(StringBuffer JavaDoc stringBuffer, String JavaDoc path) {
103     stringBuffer.append(host);
104     if(port > 0)
105       stringBuffer.append(":").append(port);
106     stringBuffer.append(path);
107   }
108
109   private void appendParameters(StringBuffer JavaDoc stringBuffer){
110     stringBuffer.append("&" + Constants.PARAMETER_ENCODER + "type={" + WSRPConstants.WSRP_URL_TYPE + "}" );
111     stringBuffer.append("&" + Constants.PARAMETER_ENCODER + "mode={" + WSRPConstants.WSRP_MODE + "}" );
112     stringBuffer.append("&" + Constants.PARAMETER_ENCODER + "windowState={" + WSRPConstants.WSRP_WINDOW_STATE + "}" );
113     stringBuffer.append("&" + Constants.PARAMETER_ENCODER + "isSecure={" + WSRPConstants.WSRP_SECURE_URL + "}" );
114
115     stringBuffer.append("&" + WSRPConstants.WSRP_PORTLET_HANDLE + "={"
116         + WSRPConstants.WSRP_PORTLET_HANDLE + "}" );
117     stringBuffer.append("&" + WSRPConstants.WSRP_PORTLET_INSTANCE_KEY + "={"
118         + WSRPConstants.WSRP_PORTLET_INSTANCE_KEY + "}" );
119     stringBuffer.append("&" + WSRPConstants.WSRP_NAVIGATIONAL_STATE + "={"
120         + WSRPConstants.WSRP_NAVIGATIONAL_STATE + "}" );
121     stringBuffer.append("&" + WSRPConstants.WSRP_SESSION_ID + "={"
122         + WSRPConstants.WSRP_SESSION_ID + "}" );
123     stringBuffer.append("&" + WSRPConstants.WSRP_USER_CONTEXT_KEY + "={"
124         + WSRPConstants.WSRP_USER_CONTEXT_KEY + "}" );
125     stringBuffer.append("&" + WSRPConstants.WSRP_URL + "={"
126         + WSRPConstants.WSRP_URL + "}" );
127     stringBuffer.append("&" + WSRPConstants.WSRP_REQUIRES_REWRITE + "={"
128         + WSRPConstants.WSRP_REQUIRES_REWRITE + "}" );
129     stringBuffer.append("&" + WSRPConstants.WSRP_INTERACTION_STATE + "={"
130         + WSRPConstants.WSRP_INTERACTION_STATE + "}" );
131     stringBuffer.append("&" + WSRPConstants.WSRP_FRAGMENT_ID + "={"
132         + WSRPConstants.WSRP_FRAGMENT_ID + "}" );
133   }
134
135 }
Popular Tags