001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.widget.netvibes.provider;
023:
024: import java.net.MalformedURLException;
025: import java.net.URL;
026:
027: import org.jboss.portal.common.text.FastURLEncoder;
028: import org.jboss.portal.widget.WidgetQuery;
029:
030: /**
031: * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
032: * @version $Revision$
033: */
034: public class NetvibesQuery implements WidgetQuery {
035:
036: /** . */
037: private static final org.jboss.logging.Logger log = org.jboss.logging.Logger
038: .getLogger(NetvibesQuery.class);
039:
040: /** . */
041: private final int start;
042:
043: /** Zero or negative means it is not used. */
044: private int count = 10;
045:
046: /** . */
047: private final String cat;
048:
049: /** . */
050: private final String type = "uwa";
051:
052: /** .*/
053: private final String sort;
054:
055: /** . */
056: private final String q;
057:
058: /** . */
059: // private Locale locale;
060: /** . */
061: private int hashCode;
062:
063: public NetvibesQuery(int start, int num, String cat, String sort,
064: String q) {
065: if (start < 0) {
066: throw new IllegalArgumentException("No negative start");
067: }
068: if (cat != null && cat.length() == 0) {
069: cat = null;
070: }
071: if (q != null && q.length() == 0) {
072: q = null;
073: }
074:
075: //
076: this .start = start;
077: this .count = num;
078: this .cat = cat;
079: this .sort = sort;
080: this .q = q;
081: this .hashCode = start + num
082: + (cat == null ? 0 : 1 + cat.hashCode())
083: + (q == null ? 0 : 1 + q.hashCode())
084: + (sort == null ? 0 : 1 + sort.hashCode());
085: }
086:
087: public int getStart() {
088: return start;
089: }
090:
091: public int getNum() {
092: return count;
093: }
094:
095: public String getCat() {
096: return cat;
097: }
098:
099: public String getQ() {
100: return q;
101: }
102:
103: public boolean equals(Object obj) {
104: if (obj == this ) {
105: return true;
106: }
107: if (obj instanceof NetvibesQuery) {
108: NetvibesQuery that = (NetvibesQuery) obj;
109: return (this .start == that.start)
110: && (this .count == that.count)
111: && (this .cat == null ? that.cat == null : this .cat
112: .equals(that.cat))
113: && (this .q == null ? that.q == null : this .q
114: .equals(that.q))
115: && (this .sort == null ? that.sort == null
116: : this .sort.equals(that.sort));
117: }
118: return false;
119: }
120:
121: public int hashCode() {
122: return hashCode;
123: }
124:
125: public URL buildQueryURL() throws MalformedURLException {
126: // Building url - and only allow UWA compatible widgets (type=uwa)
127: StringBuffer buffer = new StringBuffer(
128: "http://eco.netvibes.com/rss-partner.php?synd=jboss&type="
129: + type);
130: if (start > 0) {
131: buffer.append("&start=").append(start);
132: }
133: if (count > 0) {
134: buffer.append("&count=").append(count);
135: }
136: if (cat != null) {
137: buffer.append("&cat=").append(cat);
138: }
139: if (sort != null) {
140: buffer.append("&sort=").append(sort);
141: }
142: if (q != null) {
143: buffer.append("&q=").append(
144: FastURLEncoder.getUTF8Instance().encode(q));
145: }
146: return new URL(buffer.toString());
147: }
148:
149: }
|