001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.jbi;
022:
023: import com.liferay.portal.kernel.util.TimeZoneUtil;
024: import com.liferay.portal.kernel.util.Validator;
025: import com.liferay.portal.model.User;
026: import com.liferay.util.Http;
027:
028: import java.io.IOException;
029:
030: import java.util.Iterator;
031: import java.util.LinkedHashMap;
032: import java.util.Map;
033:
034: /**
035: * <a href="JBIRequestURL.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public abstract class JBIRequestURL {
041:
042: public JBIRequestURL() {
043: this (null);
044: }
045:
046: public JBIRequestURL(User user) {
047: _params = new LinkedHashMap();
048:
049: if (user != null) {
050: _user = user;
051:
052: _params.put("userId", String.valueOf(_user.getUserId()));
053: _params.put("timeZoneId", _user.getTimeZone().getID());
054: } else {
055: _params.put("userId", "0");
056: _params
057: .put("timeZoneId", TimeZoneUtil.getDefault()
058: .getID());
059: }
060: }
061:
062: public void addParameterMap(Map parameterMap) {
063: Iterator itr = parameterMap.entrySet().iterator();
064:
065: while (itr.hasNext()) {
066: Map.Entry entry = (Map.Entry) itr.next();
067:
068: String key = (String) entry.getKey();
069: String[] value = (String[]) entry.getValue();
070:
071: if ((Validator.isNotNull(key)) && (value != null)
072: && (value.length > 0)
073: && (Validator.isNotNull(value[0]))) {
074:
075: _params.put(key, value[0]);
076: }
077: }
078: }
079:
080: public void setParameter(String name, boolean value) {
081: setParameter(name, String.valueOf(value));
082: }
083:
084: public void setParameter(String name, double value) {
085: setParameter(name, String.valueOf(value));
086: }
087:
088: public void setParameter(String name, float value) {
089: setParameter(name, String.valueOf(value));
090: }
091:
092: public void setParameter(String name, int value) {
093: setParameter(name, String.valueOf(value));
094: }
095:
096: public void setParameter(String name, long value) {
097: setParameter(name, String.valueOf(value));
098: }
099:
100: public void setParameter(String name, short value) {
101: setParameter(name, String.valueOf(value));
102: }
103:
104: public void setParameter(String name, String value) {
105: _params.put(name, value);
106: }
107:
108: public String getContent() throws IOException {
109: return Http.URLtoString(getURL(), null, _params, true);
110: }
111:
112: protected abstract String getURL();
113:
114: private User _user;
115: private Map _params;
116:
117: }
|