001: /**
002: * Copyright 2003 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.wsrp.producer.markup.impl;
013:
014: import java.util.Map;
015: import java.util.HashMap;
016: import java.util.List;
017: import java.util.ArrayList;
018: import java.util.logging.Logger;
019: import java.net.URLEncoder;
020:
021: import com.sun.portal.container.*;
022: import com.sun.portal.providers.context.ProviderContext;
023:
024: import com.sun.portal.wsrp.common.stubs.*;
025: import com.sun.portal.wsrp.common.WSRPSpecKeys;
026:
027: import javax.servlet.http.HttpServletRequest;
028: import javax.servlet.http.HttpServletResponse;
029:
030: import com.iplanet.am.util.Debug;
031:
032: public class ProducerChannelURLFactory implements ChannelURLFactory {
033:
034: private ProviderContext _pc = null;
035: private Templates _templates = null;
036: private Debug _debug = null;
037: private Map _baseMap = null;
038: private List _channelURLList = null;
039: private boolean _requiresConsumerRewriting = false;
040:
041: public ProducerChannelURLFactory(ProviderContext pc,
042: Templates templates, Map baseParamMap, Debug debug) {
043: _pc = pc;
044: _templates = templates;
045: _baseMap = baseParamMap;
046: _channelURLList = new ArrayList();
047: }
048:
049: public ChannelURL createChannelURL() {
050: ChannelURL channelURL = new ProducerChannelURL(_debug,
051: _templates, _baseMap);
052: _channelURLList.add(channelURL);
053: return channelURL;
054: }
055:
056: public String encodeURL(HttpServletRequest request,
057: HttpServletResponse response, String url) {
058:
059: String fullURL = null;
060:
061: // URL has to be fully qualified.
062: if (url.indexOf("://") == -1) {
063: fullURL = _pc.getRequestServer(request).append(url)
064: .toString();
065: } else {
066: fullURL = url;
067: }
068: fullURL = URLEncoder.encode(response.encodeURL(fullURL));
069:
070: if (_templates == null
071: || _templates.getResourceTemplate() == null) {
072:
073: _requiresConsumerRewriting = true;
074:
075: StringBuffer urlsb = new StringBuffer(
076: WSRPSpecKeys.URL_REWRITE_START);
077: urlsb.append(WSRPSpecKeys.URL_TYPE);
078: urlsb.append("=");
079: urlsb.append(WSRPSpecKeys.URL_TYPE_RESOURCE);
080: urlsb.append("&");
081: urlsb.append(WSRPSpecKeys.URL);
082: urlsb.append("=");
083: urlsb.append(fullURL);
084: urlsb.append("&");
085: urlsb.append(WSRPSpecKeys.REQUIRES_REWRITE);
086: urlsb.append("=");
087: urlsb.append(WSRPSpecKeys.REQUIRES_REWRITE_FALSE);
088: urlsb.append(WSRPSpecKeys.URL_REWRITE_END);
089: return urlsb.toString();
090: } else {
091: //Producer rewriting
092: _requiresConsumerRewriting = false;
093:
094: Map paramMap = new HashMap();
095: paramMap.putAll(_baseMap);
096: paramMap.put(WSRPSpecKeys.URL, fullURL);
097: paramMap.put(WSRPSpecKeys.REQUIRES_REWRITE,
098: WSRPSpecKeys.REQUIRES_REWRITE_FALSE);
099: ProducerRewriter pr = new ProducerRewriter(_debug);
100: return pr.rewrite(_templates.getResourceTemplate(),
101: paramMap);
102: }
103: }
104:
105: public String getRenderTemplate() {
106: return null;
107: }
108:
109: public String getActionTemplate() {
110: return null;
111: }
112:
113: public String getSecurityErrorURL() {
114: return null;
115: }
116:
117: /**
118: * Determines whether consumer rewriting is needed. If any of the
119: * URLs in the markup requires consumer rewriting, then consumer
120: * rewriting is required.
121: **/
122: public boolean requiresConsumerRewriting() {
123:
124: ProducerChannelURL channelURL = null;
125:
126: if (_requiresConsumerRewriting == false) {
127: for (int i = 0; i < _channelURLList.size(); i++) {
128: channelURL = (ProducerChannelURL) _channelURLList
129: .get(i);
130: if (channelURL.requiresConsumerRewriting()) {
131: return true;
132: }
133: }
134: }
135: return _requiresConsumerRewriting;
136: }
137: }
|