abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1173209 [8/49] - in /abdera/abdera2: ./ .settings/ activities/ activities/src/ activities/src/main/ activities/src/main/java/ activities/src/main/java/org/ activities/src/main/java/org/apache/ activities/src/main/java/org/apache/abdera2/ a...
Date Tue, 20 Sep 2011 15:57:20 GMT
Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URIRoute.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URIRoute.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URIRoute.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URIRoute.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.anno;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * The URITemplate annotation can be used to associate a URI Template with a particular Java class. Instances of that
+ * class can then be expanded using the associated URI Template. The public fields and getter methods on the class will
+ * be automatically mapped to URI Template variable names. Alternative varnames can be specified for each field/getter
+ * using the VarName annotation
+ */
+@Retention(RUNTIME)
+@Target(TYPE)
+public @interface URIRoute {
+    String value();
+
+    boolean isiri() default false;
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URIRoute.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URITemplate.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URITemplate.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URITemplate.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URITemplate.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.anno;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * The URITemplate annotation can be used to associate a URI Template with a particular Java class. Instances of that
+ * class can then be expanded using the associated URI Template. The public fields and getter methods on the class will
+ * be automatically mapped to URI Template variable names. Alternative varnames can be specified for each field/getter
+ * using the VarName annotation
+ */
+@Retention(RUNTIME)
+@Target(TYPE)
+public @interface URITemplate {
+    String value();
+
+    boolean isiri() default false;
+    
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/URITemplate.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Version.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Version.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Version.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Version.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.anno;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Retention(RUNTIME)
+@Target( {TYPE})
+@Inherited
+public @interface Version {
+
+  String value(); // Version Number
+  String name();  // App Name
+  String uri();   // App URI
+  
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/anno/Version.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/DateTime.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/DateTime.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/DateTime.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/DateTime.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.date;
+
+import java.io.Serializable;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+/**
+ * <p>
+ * Provides an implementation of the RFC 3339 date-time.
+ * </p>
+ * <p>
+ * Accessors on this class are not synchronized.
+ * </p>
+ */
+public final class DateTime implements Cloneable, Serializable {
+
+    private static final long serialVersionUID = 3491429176989953135L;
+    private final Date value;
+
+    /**
+     * Create an AtomDate using the current date and time
+     */
+    public DateTime() {
+        this(new Date());
+    }
+
+    /**
+     * Create an AtomDate using the serialized string format (e.g. 2003-12-13T18:30:02Z).
+     * 
+     * @param value The serialized RFC3339 date/time value
+     */
+    public DateTime(String value) {
+        this(parse(value));
+    }
+
+    /**
+     * Create an AtomDate using a java.util.Date
+     * 
+     * @param value The java.util.Date value
+     * @throws NullPointerException if {@code date} is {@code null}
+     */
+    public DateTime(Date value) {
+        this.value = (Date)value.clone();
+    }
+
+    /**
+     * Create an AtomDate using a java.util.Calendar.
+     * 
+     * @param value The java.util.Calendar value
+     * @throws NullPointerException if {@code value} is {@code null}
+     */
+    public DateTime(Calendar value) {
+        this(value.getTime());
+    }
+
+    /**
+     * Create an AtomDate using the number of milliseconds since January 1, 1970, 00:00:00 GMT
+     * 
+     * @param value The number of milliseconds since January 1, 1970, 00:00:00 GMT
+     */
+    public DateTime(long value) {
+        this(new Date(value));
+    }
+
+    /**
+     * Return the serialized string form of the Atom date
+     * 
+     * @return the serialized string form of the date as specified by RFC4287
+     */
+    public String getValue() {
+        return format(value);
+    }
+
+  /**
+     * Returns the value of this Atom Date
+     * 
+     * @return A java.util.Date representing this Atom Date
+     */
+    public Date getDate() {
+      // copy it in case the user decides to change the value since 
+      // date objects themselves are not immutable
+        return (Date)value.clone();
+    }
+
+    /**
+     * Returns the value of this Atom Date as a java.util.Calendar
+     * 
+     * @return A java.util.Calendar representing this Atom Date
+     */
+    public Calendar getCalendar() {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(value);
+        return cal;
+    }
+
+    /**
+     * Returns the value of this Atom Date as the number of milliseconds since January 1, 1970, 00:00:00 GMT
+     * 
+     * @return The number of milliseconds since January 1, 1970, 00:00:00 GMT
+     */
+    public long getTime() {
+        return value.getTime();
+    }
+
+    @Override
+    public String toString() {
+        return getValue();
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + value.hashCode();
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        boolean answer = false;
+        if (obj instanceof Date) {
+            Date d = (Date)obj;
+            answer = (this.value.equals(d));
+        } else if (obj instanceof String) {
+            Date d = parse((String)obj);
+            answer = (this.value.equals(d));
+        } else if (obj instanceof Calendar) {
+            Calendar c = (Calendar)obj;
+            answer = (this.value.equals(c.getTime()));
+        } else if (obj instanceof DateTime) {
+            Date d = ((DateTime)obj).value;
+            answer = (this.value.equals(d));
+        }
+        return answer;
+    }
+
+    @Override
+    public Object clone() {
+        try {
+            return super.clone();
+        } catch (CloneNotSupportedException e) {
+            throw new AssertionError(e);
+        }
+    }
+
+    private static boolean sep(char c) {
+      return "-:.TtZz+".indexOf(c) > -1;
+    }
+    
+    public static Date parse(String date) {
+      if (date == null || date.length() == 0)
+        throw new IllegalArgumentException();
+      int nexttoken = 1;
+      Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+      cal.set(Calendar.MILLISECOND, 0);
+      cal.set(Calendar.SECOND,0);
+      cal.set(Calendar.MINUTE,0);
+      cal.set(Calendar.HOUR_OF_DAY, 0);
+      cal.set(Calendar.DATE,1);
+      cal.set(Calendar.MONTH,0);
+      cal.set(Calendar.YEAR,0);
+      for (int s = 0, r = 0; r < date.length(); r++) {
+        char c = date.charAt(r);
+        if (sep(c) || r+1==date.length()) {
+          if (nexttoken == -1) {
+            String sub = date.substring(s-1);
+            TimeZone tz = TimeZone.getTimeZone("GMT"+sub);
+            cal.setTimeZone(tz);
+            break;
+          } else {
+            String sub = date.substring(s,r);
+            s = r+1;
+            int val = Integer.parseInt(sub);
+            switch(nexttoken) {
+            case 1:
+              cal.set(Calendar.YEAR, val);
+              nexttoken = c == '-' ? 2 : c == 'T' ? 8 : c == '.' ? 64 : -1;
+              break;
+            case 2:
+              cal.set(Calendar.MONTH, val-1);
+              nexttoken = c == '-' ? 4 : c == 'T' ? 8 : c == '.' ? 64 : -1;
+              break;
+            case 4:
+              cal.set(Calendar.DATE, val);
+              nexttoken = c == 'T' || c == 't' ? 8 : -1;
+              break;
+            case 8:
+              cal.set(Calendar.HOUR_OF_DAY, val);
+              nexttoken = c == ':' ? 16 : c == '.' ? 64 : -1;
+              break;
+            case 16:
+              cal.set(Calendar.MINUTE, val);
+              nexttoken = c == ':' ? 32 : c == '.' ? 64 : -1;
+              break;
+            case 32:
+              cal.set(Calendar.SECOND, val); 
+              nexttoken = c == '.' ? 64 : -1;
+              break;
+            case 64:
+              cal.set(Calendar.MILLISECOND, val);
+              nexttoken = -1;
+              break;
+            }
+          }
+        }
+      }
+      return cal.getTime();
+    }
+
+    /**
+     * Create the serialized string form from a java.util.Date
+     * 
+     * @param d A java.util.Date
+     * @return The serialized string form of the date
+     */
+    public static String format(Date date) {
+      Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+      c.setTime(date);
+      return String.format("%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
+          c.get(Calendar.YEAR),
+          c.get(Calendar.MONTH)+1,
+          c.get(Calendar.DATE),
+          c.get(Calendar.HOUR_OF_DAY),
+          c.get(Calendar.MINUTE), 
+          c.get(Calendar.SECOND),
+          c.get(Calendar.MILLISECOND));
+    }
+    
+    public static String formatNow() {
+      return format(new Date());
+    }
+
+    /**
+     * Create a new Atom Date instance from the serialized string form
+     * 
+     * @param value The serialized string form of the date
+     * @return The created AtomDate
+     */
+    public static DateTime valueOf(String value) {
+        return new DateTime(value);
+    }
+
+    /**
+     * Create a new Atom Date instance from a java.util.Date
+     * 
+     * @param value a java.util.Date
+     * @return The created AtomDate
+     */
+    public static DateTime valueOf(Date value) {
+        return new DateTime(value);
+    }
+
+    /**
+     * Create a new Atom Date instance from a java.util.Calendar
+     * 
+     * @param value A java.util.Calendar
+     * @return The created AtomDate
+     */
+    public static DateTime valueOf(Calendar value) {
+        return new DateTime(value);
+    }
+
+    /**
+     * Create a new Atom Date instance using the number of milliseconds since January 1, 1970, 00:00:00 GMT
+     * 
+     * @param value The number of milliseconds since January 1, 1970, 00:00:00 GMT
+     * @return The created AtomDate
+     */
+    public static DateTime valueOf(long value) {
+        return new DateTime(value);
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/DateTime.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/Duration.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/Duration.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/Duration.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/Duration.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,213 @@
+package org.apache.abdera2.common.date;
+/**
+ * Basic implementation of the ISO 8601 Duration format. 
+ * Currently, the only duration format supported is the 
+ * P[n]Y[n]M[n]DT[n]H[n]M[n]S syntax. The alternative 
+ * PYYYYMMDDThhmmss and P[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]
+ * forms are NOT supported.
+ */
+public class Duration {
+
+  private final double y, m, w, d, h, i, s;
+
+  public Duration(double s) {
+    this(0,0,0,0,0,0,s);
+  }
+  
+  public Duration(double i, double s) {
+    this(0,0,0,0,0,i,s);
+  }
+  
+  public Duration(double h, double i, double s) {
+    this(0,0,0,0,h,i,s);
+  }
+  
+  public Duration(double d, double h, double i, double s) {
+    this(0,0,0,d,h,i,s);
+  }
+  
+  public Duration(double w, double d, double h, double i, double s) {
+    this(0,0,w,d,h,i,s);
+  }
+  
+  public Duration(double m, double w, double d, double h, double i, double s) {
+    this(0,m,w,d,h,i,s);
+  }
+  
+  public Duration(double y, double m, double w, double d, double h, double i, double s) {
+    this.y = Math.max(0, y);
+    this.m = Math.max(0, m);
+    this.w = Math.max(0, w);
+    this.d = Math.max(0, d);
+    this.h = Math.max(0, h);
+    this.i = Math.max(0, i);
+    this.s = Math.max(0, s);
+    if (is_frac(y)&&!is_smallest(m,w,d,h,i,s)) 
+      throw new IllegalArgumentException();
+    if (is_frac(m)&&!is_smallest(w,d,h,i,s)) 
+      throw new IllegalArgumentException();
+    if (is_frac(w)&&!is_smallest(d,h,i,s)) 
+      throw new IllegalArgumentException();
+    if (is_frac(d)&&!is_smallest(h,i,s)) 
+      throw new IllegalArgumentException();
+    if (is_frac(h)&&!is_smallest(i,s)) 
+      throw new IllegalArgumentException();
+    if (is_frac(i)&&!is_smallest(s)) 
+      throw new IllegalArgumentException();
+  }
+  
+  public double years() {
+    return y;
+  }
+  
+  public double months() {
+    return m;
+  }
+  
+  public double weeks() {
+    return w;
+  }
+  
+  public double days() {
+    return d;
+  }
+  
+  public double hours() {
+    return h;
+  }
+  
+  public double minutes() {
+    return i;
+  }
+  
+  public double seconds() {
+    return s;
+  }
+    
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    long temp;
+    temp = Double.doubleToLongBits(d);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    temp = Double.doubleToLongBits(h);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    temp = Double.doubleToLongBits(i);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    temp = Double.doubleToLongBits(m);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    temp = Double.doubleToLongBits(s);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    temp = Double.doubleToLongBits(w);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    temp = Double.doubleToLongBits(y);
+    result = prime * result + (int) (temp ^ (temp >>> 32));
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    Duration other = (Duration) obj;
+    if (Double.doubleToLongBits(d) != Double.doubleToLongBits(other.d))
+      return false;
+    if (Double.doubleToLongBits(h) != Double.doubleToLongBits(other.h))
+      return false;
+    if (Double.doubleToLongBits(i) != Double.doubleToLongBits(other.i))
+      return false;
+    if (Double.doubleToLongBits(m) != Double.doubleToLongBits(other.m))
+      return false;
+    if (Double.doubleToLongBits(s) != Double.doubleToLongBits(other.s))
+      return false;
+    if (Double.doubleToLongBits(w) != Double.doubleToLongBits(other.w))
+      return false;
+    if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
+      return false;
+    return true;
+  }
+
+  public String toString() {
+    StringBuilder buf = new StringBuilder("P");
+    
+    if (y > 0) 
+      buf.append(is_smallest(m,w,d,h,i,s)&&is_frac(y)?Double.toString(y):Integer.toString((int)y))
+         .append('Y');
+    
+    if (m > 0) 
+      buf.append(is_smallest(w,d,h,i,s)&&is_frac(m)?Double.toString(m):Integer.toString((int)m))
+         .append('M');
+    
+    if (w > 0) 
+      buf.append(is_smallest(d,h,i,s)&&is_frac(w)?Double.toString(w):Integer.toString((int)w))
+         .append('W');
+    
+    if (d > 0) 
+      buf.append(is_smallest(h,i,s)&&is_frac(d)?Double.toString(d):Integer.toString((int)d))
+         .append('D');
+    
+    if (h > 0 || i > 0 || s > 0)
+      buf.append('T');
+    
+    if (h > 0) 
+      buf.append(is_smallest(i,s)&&is_frac(h)?Double.toString(h):Integer.toString((int)h))
+         .append('H');
+    
+    if (i > 0) 
+      buf.append(is_smallest(s)&&is_frac(i)?Double.toString(i):Integer.toString((int)i))
+         .append('M');
+    
+    if (s > 0) 
+      buf.append(is_frac(s)?Double.toString(s):Integer.toString((int)s))
+         .append('S');
+
+    return buf.toString();
+  }
+  
+  private boolean is_frac(double d) {
+    return d%1!=0;
+  }
+  
+  private boolean is_smallest(double... ds) {
+    for (double i : ds)
+      if (i > 0) return false;
+    return true;
+  }
+  
+  public static Duration parse(String val) {
+    double y = 0, m = 0, w = 0, d = 0, h = 0, i = 0, s = 0;
+    if (val == null) return null;
+    int p = 0, l = val.length();
+    if (val.charAt(p) != 'P' && val.charAt(p) != 'p')
+      throw new IllegalArgumentException();
+    int r = ++p;
+    boolean t = false;
+    while(p < l) {
+      while(digit(val.charAt(r)) && r < l) r++;
+      String v = val.substring(p,r);
+      double dv = Double.parseDouble(v);
+      switch(val.charAt(r)) {
+      case 'Y': case 'y': y = dv; break;
+      case 'M': case 'm': if (!t) m = dv; else i = dv; break;
+      case 'W': case 'w': w = dv; break;
+      case 'H': case 'h': h = dv; break;
+      case 'D': case 'd': d = dv; break;
+      case 'S': case 's': s = dv; break;
+      case 'T': case 't': t = true; break;
+      default:  throw new IllegalArgumentException();
+      }
+      p = r+1;
+      r = p;
+    }
+    return new Duration(y,m,w,d,h,i,s);
+  }
+  
+  private static boolean digit(char c) {
+    return (c >= '0' && c <= '9') || c == '.' || c==',';
+  }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/Duration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/Interval.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/Interval.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/Interval.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/Interval.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,168 @@
+package org.apache.abdera2.common.date;
+
+/** 
+ * Limited implementation of the ISO 8601 Interval construct. Not all valid
+ * ISO 8601 interval representations can be represented -- only those that
+ * use DateTime constructs compatible with the limited ISO 8601 DateTime
+ * construct required for Atom
+ */
+public class Interval {
+
+  private final int repeats;
+  private final DateTime start;
+  private final DateTime end;
+  private final Duration duration;
+  
+  public Interval(DateTime start, DateTime end, int repeats) {
+    this(start,end,null,repeats);
+  }
+  
+  public Interval(DateTime start, Duration duration, int repeats) {
+    this(start,null,duration,repeats);
+  }
+
+  public Interval(Duration duration, DateTime end, int repeats) {
+    this(null,end,duration,repeats);
+  }
+  
+  public Interval(DateTime start, DateTime end) {
+    this(start,end,null,0);
+  }
+  
+  public Interval(DateTime start, Duration duration) {
+    this(start,null,duration,0);
+  }
+
+  public Interval(Duration duration, DateTime end) {
+    this(null,end,duration,0);
+  }
+  
+  public Interval(Duration duration) {
+    this(null,null,duration,0);
+  }
+  
+  public Interval(Duration duration,int repeats) {
+    this(null,null,duration,repeats);
+  }
+  
+  private Interval(
+    DateTime start, 
+    DateTime end, 
+    Duration duration, 
+    int repeats) {
+    this.start = start;
+    this.end = end;
+    this.duration = duration;
+    this.repeats = repeats;
+  }
+  
+  public DateTime start() {
+    return start;
+  }
+  
+  public DateTime end() {
+    return end;
+  }
+  
+  public Duration duration() {
+    return duration;
+  }
+  
+  public int repeats() {
+    return repeats;
+  }
+  
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((duration == null) ? 0 : duration.hashCode());
+    result = prime * result + ((end == null) ? 0 : end.hashCode());
+    result = prime * result + repeats;
+    result = prime * result + ((start == null) ? 0 : start.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    Interval other = (Interval) obj;
+    if (duration == null) {
+      if (other.duration != null)
+        return false;
+    } else if (!duration.equals(other.duration))
+      return false;
+    if (end == null) {
+      if (other.end != null)
+        return false;
+    } else if (!end.equals(other.end))
+      return false;
+    if (repeats != other.repeats)
+      return false;
+    if (start == null) {
+      if (other.start != null)
+        return false;
+    } else if (!start.equals(other.start))
+      return false;
+    return true;
+  }
+
+  public String toString() {
+    StringBuilder buf = new StringBuilder();
+    if (repeats > 0)
+      buf.append('R')
+         .append(repeats)
+         .append('/');
+    if (start != null) 
+      buf.append(start.toString());
+    if (start != null && (end != null || duration != null)) 
+      buf.append('/');
+    if (duration != null)
+      buf.append(duration.toString());
+    if (end != null && duration != null)
+      buf.append('/');
+    if (end != null) 
+      buf.append(end.toString());
+    return buf.toString();
+  }
+  
+  public static Interval parse(String val) {
+    if (val == null || val.length() == 0) return null;
+    int repeats = 0;
+    DateTime start = null, end = null;
+    Duration duration = null;
+    String[] segments = val.split("/",3);
+    int pos = 0;
+    if (segments[pos].charAt(0) == 'R' ||
+        segments[pos].charAt(0) == 'r') {
+      repeats = Integer.parseInt(segments[0].substring(1));
+      pos++;
+    }
+    if (segments[pos].charAt(0) == 'P' || 
+        segments[pos].charAt(0) == 'p') {
+      start = null;
+      duration = Duration.parse(segments[pos]);
+      pos++;
+    } else {
+      start = DateTime.valueOf(segments[pos]);
+      pos++;
+    }
+    if (duration == null && 
+        (segments[pos].charAt(0) == 'P' || 
+         segments[pos].charAt(0) == 'p')) {
+      duration = Duration.parse(segments[pos]);
+      pos++;
+    } else if (pos < segments.length){
+      end = DateTime.valueOf(segments[pos]);
+    }
+    if (end == null && pos < segments.length) {
+      end = DateTime.valueOf(segments[pos]);
+    }
+    return new Interval(start,end,duration,repeats);
+  }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/date/Interval.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Box.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Box.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Box.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Box.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.geo;
+
+public class Box extends Multiple {
+
+    private static final String TWO_COORDINATES = "A box must have two coordinates";
+    private static final long serialVersionUID = 3994252648307511152L;
+
+    public Box() {
+        super();
+    }
+
+    public Box(Multiple multiple) {
+        super(multiple);
+        if (this.coordinates.size() != 2)
+            throw new IllegalArgumentException(TWO_COORDINATES);
+    }
+
+    public Box(Point lowerCorner, Point upperCorner) {
+        super(lowerCorner, upperCorner);
+    }
+
+    public Box(Coordinate lowerCorner, Coordinate upperCorner) {
+        super(lowerCorner,upperCorner);
+    }
+
+    public Box(Coordinates coordinates) {
+        super(coordinates);
+        if (this.coordinates.size() != 2)
+            throw new IllegalArgumentException(TWO_COORDINATES);
+    }
+
+    public Box(String value) {
+        super(value);
+        if (this.coordinates.size() != 2)
+            throw new IllegalArgumentException(TWO_COORDINATES);
+    }
+
+    public Box(Multiple... multiples) {
+        super(multiples);
+        if (this.coordinates.size() != 2)
+            throw new IllegalArgumentException(TWO_COORDINATES);
+    }
+
+    public Box(Point... points) {
+        super(points);
+        if (this.coordinates.size() != 2)
+            throw new IllegalArgumentException(TWO_COORDINATES);
+    }
+
+    public Box(double... values) {
+        super(values);
+        if (this.coordinates.size() != 2)
+            throw new IllegalArgumentException(TWO_COORDINATES);
+    }
+
+    @Override
+    public void setCoordinates(Coordinates coordinates) {
+        super.setCoordinates(coordinates);
+        if (this.coordinates.size() > 2)
+            throw new IllegalArgumentException(TWO_COORDINATES);
+    }
+
+    public Coordinate getUpperCorner() {
+        return coordinates.size() > 1 ? coordinates.get(1) : null;
+    }
+
+    public Coordinate getLowerCorner() {
+        return coordinates.size() > 0 ? coordinates.get(0) : null;
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Box.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinate.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinate.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinate.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinate.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.geo;
+
+import java.io.Serializable;
+
+public class Coordinate implements Serializable, Cloneable, Comparable<Coordinate> {
+
+    private static final long serialVersionUID = -916272885213668761L;
+
+    private double latitude = 0.0f;
+    private double longitude = 0.0f;
+
+    public Coordinate() {
+    }
+    
+    public Coordinate(IsoPosition pos) {
+      this(pos.getLatitude(),pos.getLongitude());
+    }
+
+    public Coordinate(double latitude, double longitude) {
+        setLatitude(latitude);
+        setLongitude(longitude);
+    }
+
+    public Coordinate(String value) {
+        Coordinate c = parse(value);
+        setLatitude(c.latitude);
+        setLongitude(c.longitude);
+    }
+
+    public double getLatitude() {
+        return latitude;
+    }
+
+    public void setLatitude(double latitude) {
+        if (Double.compare(longitude, 90.0d) > 0)
+            throw new IllegalArgumentException("Latitude > 90.0 degrees");
+        if (Double.compare(longitude, -90.0d) < 0)
+            throw new IllegalArgumentException("Latitude < 90.0 degrees");
+        this.latitude = latitude;
+    }
+
+    public double getLongitude() {
+        return longitude;
+    }
+
+    public void setLongitude(double longitude) {
+        if (Double.compare(longitude, 180.0d) > 0)
+            throw new IllegalArgumentException("Longitude > 180.0 degrees");
+        if (Double.compare(longitude, -180.0d) < 0)
+            throw new IllegalArgumentException("Longitude < 180.0 degrees");
+        this.longitude = longitude;
+    }
+
+    public String toString() {
+        return Double.toString(latitude) + " " + Double.toString(longitude);
+    }
+    
+    public IsoPosition asIsoPosition() {
+      return new IsoPosition(latitude,longitude,0.0);
+    }
+    
+    public String toIsoString() {
+        return asIsoPosition().toString();
+    }
+
+    public Coordinate clone() {
+        try {
+            return (Coordinate)super.clone();
+        } catch (CloneNotSupportedException e) {
+            return new Coordinate(latitude, longitude); // not going to happen
+        }
+    }
+
+    @Override
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = 1;
+        long temp;
+        temp = Double.doubleToLongBits(latitude);
+        result = PRIME * result + (int)(temp ^ (temp >>> 32));
+        temp = Double.doubleToLongBits(longitude);
+        result = PRIME * result + (int)(temp ^ (temp >>> 32));
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final Coordinate other = (Coordinate)obj;
+        if (Double.doubleToLongBits(latitude) != Double.doubleToLongBits(other.latitude))
+            return false;
+        if (Double.doubleToLongBits(longitude) != Double.doubleToLongBits(other.longitude))
+            return false;
+        return true;
+    }
+
+    public static Coordinate parse(String value) {
+        try {
+            String[] points = value.trim().split("\\s+", 2);
+            double latitude = Double.parseDouble(points[0].trim());
+            double longitude = Double.parseDouble(points[1].trim());
+            return new Coordinate(latitude, longitude);
+        } catch (Throwable t) {
+            throw new RuntimeException("Error parsing coordinate pair", t);
+        }
+    }
+    
+    public static Coordinate parseIso(String value) {
+      return new Coordinate(IsoPosition.parse(value));
+    }
+
+    public int compareTo(Coordinate o) {
+        if (o == null || equals(o))
+            return 0;
+        int l1 = Double.compare(latitude, o.latitude);
+        int l2 = Double.compare(longitude, o.longitude);
+        if (l1 < 0)
+            return -1;
+        if (l1 == 0 && l2 < -1)
+            return -1;
+        if (l1 == 0 && l2 == 0)
+            return 0;
+        return 1;
+    }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinate.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinates.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinates.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinates.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinates.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.geo;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+public class Coordinates implements Iterable<Coordinate>, Serializable, Cloneable, Comparable<Coordinates> {
+
+    private static final long serialVersionUID = 1640788106113796699L;
+    protected List<Coordinate> coords = new ArrayList<Coordinate>();
+
+    public Coordinates() {
+    }
+
+    public Coordinates(Coordinate... coordinates) {
+        for (Coordinate coord : coordinates)
+            add(coord);
+    }
+
+    public Coordinates(Coordinates coordinates) {
+        coords.addAll(coordinates.coords);
+    }
+
+    public Coordinates(String value) {
+        Coordinates cs = parse(value);
+        this.coords = cs.coords;
+    }
+
+    public synchronized Coordinate get(int n) {
+        return coords.get(n);
+    }
+
+    public synchronized void add(Coordinates coordinates) {
+        coords.addAll(coordinates.coords);
+    }
+
+    public synchronized void add(Coordinate coordinate) {
+        coords.add(coordinate);
+    }
+
+    public synchronized void add(Coordinate... coordinates) {
+        for (Coordinate c : coordinates)
+            add(c);
+    }
+
+    public synchronized void add(double latitude, double longitude) {
+        coords.add(new Coordinate(latitude, longitude));
+    }
+
+    public synchronized void add(String value) {
+        coords.add(new Coordinate(value));
+    }
+
+    public synchronized void remove(Coordinate coordinate) {
+        if (coords.contains(coordinate))
+            coords.remove(coordinate);
+    }
+
+    public synchronized void remove(Coordinate... coordinates) {
+        for (Coordinate c : coordinates)
+            remove(c);
+    }
+
+    public synchronized void remove(double latitude, double longitude) {
+        remove(new Coordinate(latitude, longitude));
+    }
+
+    public synchronized void remove(String value) {
+        remove(new Coordinate(value));
+    }
+
+    public synchronized boolean contains(double latitude, double longitude) {
+        return contains(new Coordinate(latitude, longitude));
+    }
+
+    public synchronized boolean contains(String value) {
+        return contains(new Coordinate(value));
+    }
+
+    public synchronized boolean contains(Coordinate coordinate) {
+        return coords.contains(coordinate);
+    }
+
+    public synchronized boolean contains(Coordinate... coordinates) {
+        for (Coordinate c : coordinates)
+            if (!coords.contains(c))
+                return false;
+        return true;
+    }
+
+    public Iterator<Coordinate> iterator() {
+        return coords.iterator();
+    }
+
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+        for (Coordinate coord : coords) {
+            if (buf.length() > 0)
+                buf.append(" ");
+            buf.append(coord);
+        }
+        return buf.toString();
+    }
+
+    @Override
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = 1;
+        result = PRIME * result + ((coords == null) ? 0 : coords.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final Coordinates other = (Coordinates)obj;
+        if (coords == null) {
+            if (other.coords != null)
+                return false;
+        } else if (!coords.equals(other.coords))
+            return false;
+        return true;
+    }
+
+    public static Coordinates parseIso(String value) {
+      Coordinates cs = new Coordinates();
+      try {
+          String[] points = value.trim().split("\\s+");
+          for (int n = 0; n < points.length; n = n + 2) {
+              IsoPosition pos = IsoPosition.parse(points[n]);
+              cs.add(new Coordinate(pos));
+          }
+          return cs;
+      } catch (Throwable t) {
+          throw new RuntimeException("Error parsing coordinate pairs", t);
+      }      
+    }
+    
+    public static Coordinates parse(String value) {
+        Coordinates cs = new Coordinates();
+        try {
+            String[] points = value.trim().split("\\s+");
+            for (int n = 0; n < points.length; n = n + 2) {
+                double lat = Double.parseDouble(points[n]);
+                double lon = Double.parseDouble(points[n + 1]);
+                Coordinate c = new Coordinate(lat, lon);
+                cs.add(c);
+            }
+            return cs;
+        } catch (Throwable t) {
+            throw new RuntimeException("Error parsing coordinate pairs", t);
+        }
+    }
+
+    public int size() {
+        return coords.size();
+    }
+
+    public void clear() {
+        coords.clear();
+    }
+
+    public Coordinates clone() {
+        try {
+            return (Coordinates)super.clone();
+        } catch (CloneNotSupportedException e) {
+            return new Coordinates(this); // Not going to happen
+        }
+    }
+
+    public Coordinates sort() {
+        return sort(false);
+    }
+
+    public Coordinates sort(boolean reverse) {
+        Coordinates c = clone();
+        if (reverse)
+            Collections.sort(c.coords, Collections.reverseOrder());
+        else
+            Collections.sort(c.coords);
+        return c;
+    }
+
+    public int compareTo(Coordinates o) {
+        if (o == null || equals(o))
+            return 0;
+        if (size() < o.size())
+            return -1;
+        if (o.size() < size())
+            return 1;
+        for (int n = 0; n < size(); n++) {
+            Coordinate c1 = coords.get(n);
+            Coordinate c2 = o.coords.get(n);
+            int c = c1.compareTo(c2);
+            if (c != 0)
+                return c;
+        }
+        return 0;
+    }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Coordinates.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.geo;
+
+import java.io.Serializable;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * ISO 6709 Position
+ */
+public final class IsoPosition 
+  implements Serializable {
+
+  private static final long serialVersionUID = -2330958817323976941L;
+  private final Double alt, d_lat, d_lon;
+  
+  public IsoPosition(double lat, Double lon) {
+    this(lat,lon,null);
+  }
+  
+  public IsoPosition(
+    Double lat, Double lon, Double alt) {
+    this.d_lat = lat;
+    this.d_lon = lon;
+    this.alt = alt;
+  }
+ 
+  private static void toDMSString(StringBuilder buf, double dec, boolean lat) {
+    boolean z = dec<0;
+    dec = Math.abs(dec);
+    int d = (int)dec;
+    double mm = (dec-d)*60;
+    int m = (int)mm;
+    double ss = (mm-m)*60;
+    buf.append(String.format("%+0"+(lat?"3":"4")+"d%02d",z?-d:d,m));
+    if (ss < 10) buf.append('0');
+    buf.append(String.format("%.6f",ss));
+  }
+  
+  public String toString(boolean usedms) {
+    StringBuilder buf = 
+      new StringBuilder();
+    if (!usedms) {
+      double ln = getLatitude();
+      String lat = String.format("%+f",getLatitude());
+      if (ln < 10 && ln > -10)
+        lat = lat.replaceFirst("([+-])","$10");    
+      buf.append(lat);
+      
+      ln = getLongitude();
+      String lon = String.format("%+f",ln);
+      if (ln < 100 && ln > -100)
+        lon = lon.replaceFirst("([+-])","$10");
+      if (ln < 10 && ln > -10)
+        lon = lon.replaceFirst("([+-])","$10");
+      buf.append(lon);
+    } else {
+      toDMSString(buf,getLatitude(),true);
+      toDMSString(buf,getLongitude(),false);
+    }
+    if (alt != null) 
+      buf.append(String.format("%+f",getAltitude()));
+    return buf.append('/').toString();  
+  }
+  
+  public String toString() {
+    return toString(false);
+  }
+  
+  public double getLatitude() {
+    return d_lat;
+  }
+  
+  public double getLongitude() {
+    return d_lon;
+  }
+  
+  public double getAltitude() {
+    return alt;
+  }
+  
+  private static double toDegrees(
+      Integer d1, 
+      Integer m1, 
+      Integer s1, 
+      Double f1) {
+    double d = Math.abs(d1);
+    double m = m1 != null ? m1 : 0.0;
+    double s = s1 != null ? s1 : 0.0;
+    if (s1 != null && f1 != null)
+      s += f1;
+    else if (m1 != null && f1 != null)
+      m += f1;
+    else if (f1 != null)
+      d += f1;
+    double ret = d + (m/60) + (s/3600);
+    return d1 < 0 ? -ret : ret;
+  }
+  
+  public static IsoPosition parse(String val) {
+    Pattern pattern = 
+      Pattern.compile(
+        "(([+-]\\d{2})(\\d{2})?(\\d{2})?(\\.\\d+)?)(([+-]\\d{3})(\\d{2})?(\\d{2})?(\\.\\d+)?)([+-]\\d+(\\.\\d+)?)?");
+    Matcher matcher = pattern.matcher(val);
+    Integer latd = null, latm = null, lats = null, 
+            lond = null, lonm = null, lons = null;
+    Double latf = null, lonf = null, alt = null;
+    if (matcher.find()) {
+      if (matcher.group(1) != null) {
+        String sdeg = matcher.group(2);
+        String smin = matcher.group(3);
+        String ssec = matcher.group(4);
+        String sfrac = matcher.group(5);
+        latd = sdeg != null ? 
+            Integer.valueOf(
+                sdeg.charAt(0) == '+'?sdeg.substring(1):sdeg) : null;
+        latm = smin != null ? Integer.valueOf(smin) : null;
+        lats = ssec != null ? Integer.valueOf(ssec) : null;
+        latf = sfrac != null ? Double.valueOf(sfrac) : null;
+      }
+      if (matcher.group(6) != null) {
+        String sdeg = matcher.group(7);
+        String smin = matcher.group(8);
+        String ssec = matcher.group(9);
+        String sfrac = matcher.group(10);
+        lond = sdeg != null ? 
+            Integer.valueOf(
+              sdeg.charAt(0) == '+'?sdeg.substring(1):sdeg) : null;
+        lonm = smin != null ? Integer.valueOf(smin) : null;
+        lons = ssec != null ? Integer.valueOf(ssec) : null;
+        lonf = sfrac != null ? Double.valueOf(sfrac) : null;
+      }
+      if (matcher.group(11) != null) {
+        String s= matcher.group(11);
+        alt = s != null ? 
+            Double.valueOf(
+                s.charAt(0) == '+'?s.substring(1):s) : null;
+      }
+      return new IsoPosition(
+        toDegrees(latd,latm,lats,latf),
+        toDegrees(lond,lonm,lons,lonf),
+        alt);
+    } else {
+      throw new IllegalArgumentException();
+    }
+  }
+  
+}
\ No newline at end of file

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/IsoPosition.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Line.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Line.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Line.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Line.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.geo;
+
+public class Line extends Multiple {
+
+    private static final long serialVersionUID = 2852975001208906285L;
+
+    public Line() {
+    }
+
+    public Line(Multiple multiple) {
+        super(multiple);
+        verify();
+    }
+
+    public Line(Point point) {
+        super(point);
+        verify();
+    }
+
+    public Line(Coordinate... coordinates) {
+        super(coordinates);
+        verify();
+    }
+
+    public Line(Coordinates coordinates) {
+        super(coordinates);
+        verify();
+    }
+
+    public Line(String value) {
+        super(value);
+        verify();
+    }
+
+    public Line(Multiple... multiples) {
+        super(multiples);
+        verify();
+    }
+
+    public Line(Point... points) {
+        super(points);
+        verify();
+    }
+
+    public Line(double... values) {
+        super(values);
+        verify();
+    }
+
+    @Override
+    public void setCoordinates(Coordinates coordinates) {
+        super.setCoordinates(coordinates);
+        verify();
+    }
+
+    public void verify() {
+        super.verify179Rule();
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Line.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Multiple.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Multiple.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Multiple.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Multiple.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.geo;
+
+import java.util.Iterator;
+
+public abstract class Multiple extends Position implements Iterable<Coordinate> {
+
+  private static final long serialVersionUID = -401256381030284678L;
+    protected Coordinates coordinates;
+
+    public Multiple() {
+    }
+
+    public Multiple(Multiple... multiples) {
+        this.coordinates = new Coordinates();
+        for (Multiple m : multiples)
+            coordinates.add(m.getCoordinates());
+    }
+
+    public Multiple(Multiple multiple) {
+        this(multiple.getCoordinates().clone());
+    }
+
+    public Multiple(Point point) {
+        this(point.getCoordinate().clone());
+    }
+
+    public Multiple(Point... points) {
+        this.coordinates = new Coordinates();
+        for (Point p : points)
+            coordinates.add(p.getCoordinate());
+    }
+
+    public Multiple(Coordinates coordinates) {
+        this.coordinates = coordinates;
+    }
+
+    public Multiple(Coordinate... coordinates) {
+        this.coordinates = new Coordinates(coordinates);
+    }
+
+    public Multiple(String value) {
+        this.coordinates = new Coordinates(value);
+    }
+
+    public Multiple(double... values) {
+        this.coordinates = new Coordinates();
+        for (int n = 0; n < values.length; n = n + 2) {
+            Coordinate c = new Coordinate(values[n], values[n + 1]);
+            this.coordinates.add(c);
+        }
+    }
+
+    public Coordinates getCoordinates() {
+        return coordinates;
+    }
+
+    public void setCoordinates(Coordinates coordinates) {
+        this.coordinates = coordinates;
+    }
+
+    public Iterator<Coordinate> iterator() {
+        return coordinates.iterator();
+    }
+
+    @Override
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = super.hashCode();
+        result = PRIME * result + ((coordinates == null) ? 0 : coordinates.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final Multiple other = (Multiple)obj;
+        if (coordinates == null) {
+            if (other.coordinates != null)
+                return false;
+        } else if (!coordinates.equals(other.coordinates))
+            return false;
+        return true;
+    }
+
+    public int compareTo(Position o) {
+        if (o == null || !this.getClass().isInstance(o) || equals(o))
+            return 0;
+        return coordinates.compareTo(((Multiple)o).coordinates);
+    }
+
+    protected void verify179Rule() {
+        for (Coordinate c1 : getCoordinates()) {
+            for (Coordinate c2 : getCoordinates()) {
+                check179(c1.getLatitude(), c2.getLatitude());
+                check179(c1.getLongitude(), c2.getLongitude());
+            }
+        }
+    }
+
+    private void check179(double d1, double d2) {
+        if (Math.abs(Math.max(d1, d2)) - Math.abs(Math.min(d1, d2)) > 179)
+            throw new RuntimeException("Values are greater than 179 degrees");
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Multiple.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Point.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Point.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Point.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Point.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.geo;
+
+public class Point extends Position {
+
+    private static final long serialVersionUID = 7540202474168797239L;
+
+    private Coordinate coordinate;
+
+    public Point() {}
+
+    public Point(Point point) {
+        this.coordinate = point.getCoordinate().clone();
+    }
+
+    public Point(Coordinate coordinate) {
+        this.coordinate = coordinate;
+    }
+
+    public Point(double latitude, double longitude) {
+        this.coordinate = new Coordinate(latitude, longitude);
+    }
+
+    public Point(String value) {
+        this.coordinate = new Coordinate(value);
+    }
+
+    public Point(IsoPosition pos) {
+        this.coordinate = new Coordinate(pos);
+    }
+    
+    public Coordinate getCoordinate() {
+        return coordinate;
+    }
+
+    public void setCoordinate(IsoPosition pos) {
+      this.coordinate = new Coordinate(pos);
+    }
+    
+    public void setCoordinate(Coordinate coordinate) {
+        this.coordinate = coordinate;
+    }
+
+    public void setCoordinate(double latitude, double longitude) {
+        this.coordinate = new Coordinate(latitude, longitude);
+    }
+
+    public void setCoordinate(String value) {
+        this.coordinate = new Coordinate(value);
+    }
+
+    @Override
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = super.hashCode();
+        result = PRIME * result + ((coordinate == null) ? 0 : coordinate.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (!super.equals(obj))
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final Point other = (Point)obj;
+        if (coordinate == null) {
+            if (other.coordinate != null)
+                return false;
+        } else if (!coordinate.equals(other.coordinate))
+            return false;
+        return true;
+    }
+
+    public int compareTo(Position o) {
+        if (o == null || !(o instanceof Point) || equals(o))
+            return 0;
+        return coordinate.compareTo(((Point)o).coordinate);
+    }
+
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Point.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Polygon.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Polygon.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Polygon.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Polygon.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.geo;
+
+public class Polygon extends Multiple {
+
+    private static final long serialVersionUID = 5387230171535985909L;
+
+    public Polygon() {
+        super();
+    }
+
+    public Polygon(Multiple multiple) {
+        super(multiple);
+        verify();
+    }
+
+    public Polygon(Point point) {
+        super(point);
+        verify();
+    }
+
+    public Polygon(Coordinate... coordinates) {
+        super(coordinates);
+        verify();
+    }
+
+    public Polygon(Coordinates coordinates) {
+        super(coordinates);
+        verify();
+    }
+
+    public Polygon(String value) {
+        super(value);
+        verify();
+    }
+
+    public Polygon(Multiple... multiples) {
+        super(multiples);
+        verify();
+    }
+
+    public Polygon(Point... points) {
+        super(points);
+        verify();
+    }
+
+    public Polygon(double... values) {
+        super(values);
+        verify();
+    }
+
+    @Override
+    public void setCoordinates(Coordinates coordinates) {
+        super.setCoordinates(coordinates);
+        verify();
+    }
+
+    public void verify() {
+        super.verify179Rule();
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Polygon.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Position.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Position.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Position.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Position.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.geo;
+
+import java.io.Serializable;
+
+public abstract class Position implements Serializable, Cloneable, Comparable<Position> {
+
+  private static final long serialVersionUID = 2024463162259330581L;
+    public static final String DEFAULT_FEATURE_TYPE_TAG = "location";
+    public static final String DEFAULT_RELATIONSHIP_TAG = "is-located-at";
+
+    protected String featureTypeTag;
+    protected String relationshipTag;
+    protected Double elevation;
+    protected Double floor;
+    protected Double radius;
+
+    public Double getElevation() {
+        return elevation;
+    }
+
+    public void setElevation(Double elevation) {
+        this.elevation = elevation;
+    }
+
+    public String getFeatureTypeTag() {
+        return featureTypeTag;
+    }
+
+    public void setFeatureTypeTag(String featureTypeTag) {
+        this.featureTypeTag = featureTypeTag;
+    }
+
+    public Double getFloor() {
+        return floor;
+    }
+
+    public void setFloor(Double floor) {
+        this.floor = floor;
+    }
+
+    public Double getRadius() {
+        return radius;
+    }
+
+    public void setRadius(Double radius) {
+        this.radius = radius;
+    }
+
+    public String getRelationshipTag() {
+        return relationshipTag;
+    }
+
+    public void setRelationshipTag(String relationshipTag) {
+        this.relationshipTag = relationshipTag;
+    }
+
+    @Override
+    public int hashCode() {
+        final int PRIME = 31;
+        // int result = super.hashCode();
+        int result = this.getClass().hashCode();
+        result = PRIME * result + ((elevation == null) ? 0 : elevation.hashCode());
+        result =
+            PRIME * result
+                + ((featureTypeTag == null) ? DEFAULT_FEATURE_TYPE_TAG.hashCode() : featureTypeTag.hashCode());
+        result = PRIME * result + ((floor == null) ? 0 : floor.hashCode());
+        result = PRIME * result + ((radius == null) ? 0 : radius.hashCode());
+        result =
+            PRIME * result
+                + ((relationshipTag == null) ? DEFAULT_RELATIONSHIP_TAG.hashCode() : relationshipTag.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (getClass() != obj.getClass())
+            return false;
+        final Position other = (Position)obj;
+        if (elevation == null) {
+            if (other.elevation != null)
+                return false;
+        } else if (!elevation.equals(other.elevation))
+            return false;
+        if (featureTypeTag == null) {
+            if (other.featureTypeTag != null && !other.featureTypeTag.equalsIgnoreCase(DEFAULT_FEATURE_TYPE_TAG))
+                return false;
+        } else {
+            String s = other.featureTypeTag != null ? other.featureTypeTag : DEFAULT_FEATURE_TYPE_TAG;
+            if (!featureTypeTag.equalsIgnoreCase(s))
+                return false;
+        }
+        if (floor == null) {
+            if (other.floor != null)
+                return false;
+        } else if (!floor.equals(other.floor))
+            return false;
+        if (radius == null) {
+            if (other.radius != null)
+                return false;
+        } else if (!radius.equals(other.radius))
+            return false;
+        if (relationshipTag == null) {
+            if (other.relationshipTag != null && !other.relationshipTag.equalsIgnoreCase(DEFAULT_RELATIONSHIP_TAG))
+                return false;
+        } else {
+            String s = other.relationshipTag != null ? other.relationshipTag : DEFAULT_RELATIONSHIP_TAG;
+            if (!relationshipTag.equalsIgnoreCase(s))
+                return false;
+        }
+        return true;
+    }
+
+    public Object clone() {
+        try {
+            return super.clone();
+        } catch (CloneNotSupportedException e) {
+            return null; // should never happen
+        }
+    }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/geo/Position.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Authentication.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Authentication.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Authentication.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Authentication.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,275 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.http;
+
+import java.io.ByteArrayOutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.abdera2.common.text.Codec;
+import static org.apache.abdera2.common.text.CharUtils.unquote;
+import static org.apache.abdera2.common.text.CharUtils.quotedIfNotToken;
+import static org.apache.abdera2.common.text.CharUtils.isToken;
+import static org.apache.abdera2.common.text.CharUtils.quoted;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.StringUtils;
+
+/**
+ * Implementation of the HTTP Challenge/Credentials Construct. This is helpful when 
+ * using custom authentication mechanisms with an HTTP Request. It provides
+ * a simple means of working with the WWW-Authenticate and Proxy-Authenticate
+ * headers.
+ **/
+public class Authentication implements Iterable<String>, Serializable {
+
+  private static final long serialVersionUID = 7237004814934751226L;
+  public final static String BASIC = "basic";
+  public final static String DIGEST = "digest";
+  
+  private final static String TOKEN = "[\\!\\#\\$\\%\\&\\'\\*\\+\\-\\.\\^\\_\\`\\|\\~a-zA-Z0-9]+";
+  private final static String B64 = "([a-zA-Z0-9\\-\\.\\_\\~\\+\\/]+\\=*)";
+  private final static String PARAM = TOKEN+"\\s*={1}\\s*(?:(?:\"[^\"]+\")|(?:"+TOKEN+"))";
+  private final static String PARAMS = "(" + PARAM + "(?:\\s*,\\s*"+PARAM+")*)";
+  private final static String B64orPARAM = "(?:" + PARAMS + "|" + B64 + ")";
+  private final static String PATTERN = "("+TOKEN+")(?:\\s+" + B64orPARAM + ")?";
+  private final static Pattern pattern = 
+    Pattern.compile(PATTERN);
+  private final static Pattern param = 
+    Pattern.compile("("+PARAM+")");
+  
+  private final static Set<String> ALWAYS = 
+    new HashSet<String>();
+  static {
+      ALWAYS.add("domain");
+      ALWAYS.add("nonce");
+      ALWAYS.add("opaque");
+      ALWAYS.add("qop");
+      ALWAYS.add("realm");
+  }
+  
+  public static void alwaysQuote(String name) {
+    if (name == null)
+      throw new IllegalArgumentException();
+    ALWAYS.add(name);
+  }
+  
+  public static Iterable<Authentication> parse(String challenge) {
+    List<Authentication> challenges = new ArrayList<Authentication>();
+    Matcher matcher = pattern.matcher(challenge);
+    while (matcher.find()) {
+      String scheme = matcher.group(1);
+      String params = matcher.group(2);
+      String b64token = matcher.group(3); 
+      Authentication chal = 
+        new Authentication(scheme,b64token);
+      if (params != null) {
+        Matcher mparams = param.matcher(params);
+        while(mparams.find()) {
+          String p = mparams.group(1);
+          String[] ps = p.split("\\s*=\\s*", 2);
+          String name = ps[0];
+          if (name.charAt(name.length()-1)=='*')
+            name = name.substring(0,name.length()-1);
+          chal.add(name, Codec.decode(unquote(ps[1])));
+        }
+      }
+      challenges.add(chal);
+    }
+    return challenges;
+  }
+  
+  private final String scheme;
+  private final String b64token;
+  private final Map<String,String> params = 
+    new HashMap<String,String>();
+  private final Set<String> quoted = 
+    new HashSet<String>();
+    
+  public Authentication(String scheme) {
+    this(scheme,null);
+  }
+  
+  public Authentication(String scheme, String b64token) {
+    if (scheme == null)
+      throw new IllegalArgumentException();
+    this.scheme = scheme.toLowerCase(Locale.US);
+    this.b64token = b64token;
+  }
+  
+  private void add(String name, String value) {
+    params.put(name,value);
+  }
+  
+  public String getScheme() {
+    return scheme;
+  }
+  
+  public String getBase64Token() {
+    return b64token;
+  }
+  
+  public String getParam(String name) {
+    return params.get(name);
+  }
+  
+  private static boolean is_always_quoted(String name) {
+    return name != null ? ALWAYS.contains(name) : false;
+  }
+  
+  public void setParam(String name, String val) {
+    if (val == null)
+      params.remove(name);
+    else
+      params.put(name, val);
+  }
+  
+  public void setQuotedParam(String name, String val) {
+    setParam(name,val);
+    quoted.add(name);
+  }
+  
+  public void setQuotedParam(String name) {
+    quoted.add(name);
+  }
+  
+  public boolean hasParam(String name) {
+    return params.containsKey(name);
+  }
+  
+  public Iterator<String> iterator() {
+    return params.keySet().iterator();
+  }
+  
+  private boolean isquoted(String param) {
+    return quoted.contains(param);
+  }
+  
+  public String toString() {
+    StringBuilder buf = new StringBuilder(scheme);
+    if (b64token != null || params.size() > 0)
+      buf.append(' ');
+    if (b64token != null)
+      buf.append(b64token);
+    else {
+      boolean first = true;
+      for (String param : this) {
+        if (!first) {
+          buf.append(',').append(' ');
+        } else first = false;
+        String val = getParam(param);
+        buf.append(param);
+        boolean always = is_always_quoted(param) || isquoted(param);
+        if (!isToken(val) && !always) {
+          buf.append('*')
+             .append('=')
+             .append(Codec.encode(val,Codec.STAR));
+        } else {
+          buf.append('=')
+             .append(always?quoted(val,true):quotedIfNotToken(val));
+        }
+      }
+    }
+    return buf.toString();
+  }
+
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + ((b64token == null) ? 0 : b64token.hashCode());
+    result = prime * result + ((params == null) ? 0 : params.hashCode());
+    result = prime * result + ((scheme == null) ? 0 : scheme.hashCode());
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    Authentication other = (Authentication) obj;
+    if (b64token == null) {
+      if (other.b64token != null)
+        return false;
+    } else if (!b64token.equals(other.b64token))
+      return false;
+    if (params == null) {
+      if (other.params != null)
+        return false;
+    } else if (!params.equals(other.params))
+      return false;
+    if (scheme == null) {
+      if (other.scheme != null)
+        return false;
+    } else if (!scheme.equals(other.scheme))
+      return false;
+    return true;
+  }
+  
+  public static Authentication basic(String userid, String password) {
+    String b64token = 
+      StringUtils.newStringUsAscii(
+        Base64.encodeBase64(
+          bytes(userid,":",password)));
+    return new Authentication(BASIC, b64token);
+  }
+  
+  private static byte[] bytes(String val, String... vals) {
+    if (val == null) return new byte[0];
+    ByteArrayOutputStream out = 
+      new ByteArrayOutputStream();
+    try {
+      out.write(StringUtils.getBytesUtf8(val));
+      for (String v : vals)
+        out.write(StringUtils.getBytesUtf8(v));
+    } catch (Throwable t) {}
+    return out.toByteArray();
+  }
+  
+  public static String toString(Authentication auth, Authentication... auths) {
+    if (auth == null) return null;
+    StringBuilder buf = new StringBuilder();
+    buf.append(auth.toString());
+    for (Authentication a : auths)
+      buf.append(", ").append(a.toString());
+    return buf.toString();
+  }
+  
+  public static String toString(Iterable<Authentication> auths) {
+    StringBuilder buf = new StringBuilder();
+    boolean first = true;
+    for (Authentication auth : auths) {
+      if (!first) buf.append(", ");
+      else first = !first;
+      buf.append(auth.toString());
+    }
+    return buf.toString();
+  }
+}

Propchange: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/Authentication.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControl.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControl.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControl.java (added)
+++ abdera/abdera2/common/src/main/java/org/apache/abdera2/common/http/CacheControl.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,319 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.common.http;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+public final class CacheControl implements Serializable {
+
+  private static final long serialVersionUID = 3554586802963893228L;
+  public final static int NOCACHE = 1,
+                          NOSTORE = 2,
+                          NOTRANSFORM = 4,
+                          PUBLIC = 8,
+                          PRIVATE = 16,
+                          REVALIDATE = 32,
+                          PROXYREVALIDATE = 64,
+                          ONLYIFCACHED = 128;
+  protected int flags = 0;
+  protected String[] nocache_headers = null,
+                     private_headers = null;
+  protected long max_age = -1,
+                 max_stale = -1,
+                 min_fresh = -1,
+                 smax_age = -1,
+                 staleiferror = -1,
+                 stalewhilerevalidate = -1;
+  protected HashMap<String,Object> exts =
+    new HashMap<String,Object>();
+  
+  public CacheControl() {}
+  
+  public CacheControl(String cc) {
+    CacheControlUtil.parseCacheControl(cc, this);
+  }
+  
+  public CacheControl setExtensions(Map<String,Object> exts) {
+    this.exts.putAll(exts);
+    return this;
+  }
+  
+  public CacheControl setExtension(String name, Object value) {
+    exts.put(name,value);
+    return this;
+  }
+  
+  public Object getExtension(String name) {
+    return exts.get(name);
+  }
+  
+  public String[] listExtensions() {
+    return exts.keySet().toArray(new String[exts.size()]);
+  }
+  
+  protected boolean check(int flag) {
+    return (flags & flag) == flag;
+  }
+
+  protected void toggle(boolean val, int flag) {
+      if (val)
+          flags |= flag;
+      else
+          flags &= ~flag;
+  }
+  
+  public void setDefaults() {
+    setNoCache(false);
+    setNoStore(false);
+    setNoTransform(false);
+    setOnlyIfCached(false);
+    setMaxAge(-1);
+    setMaxStale(-1);
+    setMinFresh(-1);
+    setStaleIfError(-1);
+    setStaleWhileRevalidate(-1);
+    setMustRevalidate(false);
+    setPrivate(false);
+    setPublic(false);
+    setMaxAge(-1);
+  }
+  
+  public boolean isNoCache() {
+    return check(NOCACHE);
+  }
+  
+  public boolean isNoStore() {
+      return check(NOSTORE);
+  }
+  
+  public boolean isNoTransform() {
+      return check(NOTRANSFORM);
+  }
+  
+  public long getMaxAge() {
+      return max_age;
+  }
+  
+  public String[] getNoCacheHeaders() {
+    return isNoCache() ? nocache_headers : null;
+  }
+
+  public String[] getPrivateHeaders() {
+    return isPrivate() ? private_headers : null;
+  }
+
+  public long getSMaxAge() {
+      return smax_age;
+  }
+
+  public boolean isMustRevalidate() {
+    return check(REVALIDATE);
+  }
+
+  public boolean isPrivate() {
+    return check(PRIVATE);
+  }
+
+  public boolean isProxyRevalidate() {
+    return check(PROXYREVALIDATE);
+  }
+
+  public boolean isPublic() {
+    return check(PUBLIC);
+  }
+
+  public long getStaleIfError() {
+    return staleiferror;
+  }
+  
+  public long getStaleWhileRevalidate() {
+    return stalewhilerevalidate;
+  }
+  
+  public CacheControl setStaleIfError(long delta) {
+    this.staleiferror = Math.max(-1,delta);
+    return this;
+  }
+  
+  public CacheControl setStaleWhileRevalidate(long delta) {
+    this.stalewhilerevalidate = Math.max(-1,delta);
+    return this;
+  }
+  
+  public CacheControl setMaxAge(long max_age) {
+    this.max_age = Math.max(-1,max_age);
+    return this;
+  }
+
+  public CacheControl setMustRevalidate(boolean val) {
+    toggle(val,REVALIDATE);
+    return this;
+  }
+
+  public CacheControl setProxyRevalidate(boolean val) {
+    toggle(val,PROXYREVALIDATE);
+    return this;
+  }
+
+  public CacheControl setNoCache(boolean val) {
+    toggle(val,NOCACHE);
+    return this;
+  }
+
+  public CacheControl setNoStore(boolean val) {
+    toggle(val,NOSTORE);
+    return this;
+  }
+
+  public CacheControl setNoTransform(boolean val) {
+    toggle(val,NOTRANSFORM);
+    return this;
+  }
+  
+  public CacheControl setPublic(boolean val) {
+    toggle(val,PUBLIC);
+    return this;
+  }
+
+  public CacheControl setPrivate(boolean val) {
+    toggle(val,PRIVATE);
+    return this;
+  }
+
+  public CacheControl setPrivateHeaders(String... headers) {
+    this.private_headers = headers;
+    return this;
+  }
+
+  public CacheControl setNoCacheHeaders(String... headers) {
+    this.nocache_headers = headers;
+    return this;
+  }
+  
+  public boolean isOnlyIfCached() {
+    return check(ONLYIFCACHED);
+  }
+  
+  public long getMaxStale() {
+    return max_stale;
+  }
+
+  public long getMinFresh() {
+    return min_fresh;
+  }
+  
+  public CacheControl setMaxStale(long max_stale) {
+    this.max_stale = max_stale;
+    return this;
+  }
+
+  public CacheControl setMinFresh(long min_fresh) {
+    this.min_fresh = min_fresh;
+    return this;
+  }
+  
+  public CacheControl setOnlyIfCached(boolean val) {
+    toggle(val,ONLYIFCACHED);
+    return this;
+  }
+  
+  public String toString() {
+    return CacheControlUtil.buildCacheControl(this);
+  }
+  
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + flags;
+    result = prime * result + (int) (max_age ^ (max_age >>> 32));
+    result = prime * result + (int) (max_stale ^ (max_stale >>> 32));
+    result = prime * result + (int) (min_fresh ^ (min_fresh >>> 32));
+    result = prime * result + Arrays.hashCode(nocache_headers);
+    result = prime * result + Arrays.hashCode(private_headers);
+    result = prime * result + (int) (smax_age ^ (smax_age >>> 32));
+    result = prime * result + (int) (staleiferror ^ (staleiferror >>> 32));
+    result = prime * result
+        + (int) (stalewhilerevalidate ^ (stalewhilerevalidate >>> 32));
+    return result;
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj)
+      return true;
+    if (obj == null)
+      return false;
+    if (getClass() != obj.getClass())
+      return false;
+    CacheControl other = (CacheControl) obj;
+    if (flags != other.flags)
+      return false;
+    if (max_age != other.max_age)
+      return false;
+    if (max_stale != other.max_stale)
+      return false;
+    if (min_fresh != other.min_fresh)
+      return false;
+    if (!Arrays.equals(nocache_headers, other.nocache_headers))
+      return false;
+    if (!Arrays.equals(private_headers, other.private_headers))
+      return false;
+    if (smax_age != other.smax_age)
+      return false;
+    if (staleiferror != other.staleiferror)
+      return false;
+    if (stalewhilerevalidate != other.stalewhilerevalidate)
+      return false;
+    return true;
+  }
+  
+  public static CacheControl NOCACHE() {
+    CacheControl cc = new CacheControl();
+    cc.setNoCache(true);
+    return cc;
+  }
+  
+  public static CacheControl NOSTORE() {
+    CacheControl cc = new CacheControl();
+    cc.setNoStore(true);
+    return cc;
+  }
+  
+  public static CacheControl MAXAGE(long age) {
+    CacheControl cc = new CacheControl();
+    cc.setMaxAge(age);
+    return cc;
+  }
+  
+  public static CacheControl PUBLIC() {
+    CacheControl cc = new CacheControl();
+    cc.setPublic(true);
+    return cc;
+  }
+  
+  public static CacheControl PRIVATE() {
+    CacheControl cc = new CacheControl();
+    cc.setPrivate(true);
+    return cc;
+  }
+  
+}



Mime
View raw message