[Bedework-commit] carddav r16 - in trunk/server/src/org/bedework/carddav: . bwserver server server/calquery server/dirHandlers server/filter util vcard

svnadmin at bedework.org svnadmin at bedework.org
Wed Nov 26 13:19:34 EST 2008


Author: douglm
Date: 2008-11-26 13:19:32 -0500 (Wed, 26 Nov 2008)
New Revision: 16

Added:
   trunk/server/src/org/bedework/carddav/vcard/
   trunk/server/src/org/bedework/carddav/vcard/CompatibilityHints.java
   trunk/server/src/org/bedework/carddav/vcard/Param.java
   trunk/server/src/org/bedework/carddav/vcard/Property.java
   trunk/server/src/org/bedework/carddav/vcard/Tokenizer.java
   trunk/server/src/org/bedework/carddav/vcard/UnfoldingReader.java
   trunk/server/src/org/bedework/carddav/vcard/Vcard.java
Removed:
   trunk/server/src/org/bedework/carddav/server/Vcard.java
   trunk/server/src/org/bedework/carddav/util/CompatibilityHints.java
   trunk/server/src/org/bedework/carddav/util/Tokenizer.java
   trunk/server/src/org/bedework/carddav/util/UnfoldingReader.java
Modified:
   trunk/server/src/org/bedework/carddav/bwserver/BwSysIntfImpl.java
   trunk/server/src/org/bedework/carddav/bwserver/DirHandler.java
   trunk/server/src/org/bedework/carddav/server/CarddavBWIntf.java
   trunk/server/src/org/bedework/carddav/server/CarddavCardNode.java
   trunk/server/src/org/bedework/carddav/server/CarddavColNode.java
   trunk/server/src/org/bedework/carddav/server/CarddavURI.java
   trunk/server/src/org/bedework/carddav/server/SpecialUri.java
   trunk/server/src/org/bedework/carddav/server/SysIntf.java
   trunk/server/src/org/bedework/carddav/server/calquery/AddressData.java
   trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapAddrBookDirHandler.java
   trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapDirHandler.java
   trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapPrincipalDirHandler.java
   trunk/server/src/org/bedework/carddav/server/filter/Filter.java
   trunk/server/src/org/bedework/carddav/server/filter/PropFilter.java
Log:
A bit of refactoring - moved vcard classes into a separate package

Modified: trunk/server/src/org/bedework/carddav/bwserver/BwSysIntfImpl.java
===================================================================
--- trunk/server/src/org/bedework/carddav/bwserver/BwSysIntfImpl.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/bwserver/BwSysIntfImpl.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -32,13 +32,13 @@
 import org.bedework.carddav.server.CarddavCardNode;
 import org.bedework.carddav.server.CarddavColNode;
 import org.bedework.carddav.server.SysIntf;
-import org.bedework.carddav.server.Vcard;
 import org.bedework.carddav.server.PropertyHandler.PropertyType;
 import org.bedework.carddav.server.dirHandlers.DirHandlerFactory;
 import org.bedework.carddav.server.filter.Filter;
 import org.bedework.carddav.util.CardDAVConfig;
 import org.bedework.carddav.util.DirHandlerConfig;
 import org.bedework.carddav.util.User;
+import org.bedework.carddav.vcard.Vcard;
 
 import edu.rpi.cct.webdav.servlet.shared.PrincipalPropertySearch;
 import edu.rpi.cct.webdav.servlet.shared.WebdavBadRequest;

Modified: trunk/server/src/org/bedework/carddav/bwserver/DirHandler.java
===================================================================
--- trunk/server/src/org/bedework/carddav/bwserver/DirHandler.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/bwserver/DirHandler.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -29,10 +29,10 @@
 
 import org.bedework.carddav.server.CarddavCardNode;
 import org.bedework.carddav.server.CarddavCollection;
-import org.bedework.carddav.server.Vcard;
 import org.bedework.carddav.server.filter.Filter;
 import org.bedework.carddav.util.CardDAVConfig;
 import org.bedework.carddav.util.DirHandlerConfig;
+import org.bedework.carddav.vcard.Vcard;
 import org.bedework.webdav.WdCollection;
 
 import edu.rpi.cct.webdav.servlet.shared.WebdavException;

Modified: trunk/server/src/org/bedework/carddav/server/CarddavBWIntf.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/CarddavBWIntf.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/CarddavBWIntf.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -32,6 +32,7 @@
 import org.bedework.carddav.util.DirHandlerConfig;
 import org.bedework.carddav.util.Group;
 import org.bedework.carddav.util.User;
+import org.bedework.carddav.vcard.Vcard;
 import org.bedework.webdav.WdCollection;
 
 import edu.rpi.cct.webdav.servlet.common.AccessUtil;

Modified: trunk/server/src/org/bedework/carddav/server/CarddavCardNode.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/CarddavCardNode.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/CarddavCardNode.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -27,6 +27,7 @@
 package org.bedework.carddav.server;
 
 import org.bedework.carddav.server.calquery.AddressData;
+import org.bedework.carddav.vcard.Vcard;
 
 import org.w3c.dom.Element;
 

Modified: trunk/server/src/org/bedework/carddav/server/CarddavColNode.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/CarddavColNode.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/CarddavColNode.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -25,6 +25,7 @@
 */
 package org.bedework.carddav.server;
 
+import org.bedework.carddav.vcard.Vcard;
 import org.bedework.webdav.WdCollection;
 
 import edu.rpi.cct.webdav.servlet.shared.WebdavException;

Modified: trunk/server/src/org/bedework/carddav/server/CarddavURI.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/CarddavURI.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/CarddavURI.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -26,6 +26,8 @@
 
 package org.bedework.carddav.server;
 
+import org.bedework.carddav.vcard.Vcard;
+
 import edu.rpi.cmt.access.Ace;
 import edu.rpi.cmt.access.PrincipalInfo;
 

Modified: trunk/server/src/org/bedework/carddav/server/SpecialUri.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/SpecialUri.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/SpecialUri.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -29,6 +29,7 @@
 import org.bedework.carddav.server.filter.PropFilter;
 import org.bedework.carddav.server.filter.TextMatch;
 import org.bedework.carddav.util.CardDAVConfig;
+import org.bedework.carddav.vcard.Vcard;
 
 import edu.rpi.cct.webdav.servlet.shared.WebdavBadRequest;
 import edu.rpi.cct.webdav.servlet.shared.WebdavException;

Modified: trunk/server/src/org/bedework/carddav/server/SysIntf.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/SysIntf.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/SysIntf.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -29,6 +29,7 @@
 import org.bedework.carddav.server.PropertyHandler.PropertyType;
 import org.bedework.carddav.server.filter.Filter;
 import org.bedework.carddav.util.CardDAVConfig;
+import org.bedework.carddav.vcard.Vcard;
 
 import edu.rpi.cct.webdav.servlet.shared.PrincipalPropertySearch;
 import edu.rpi.cct.webdav.servlet.shared.WebdavException;

Deleted: trunk/server/src/org/bedework/carddav/server/Vcard.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/Vcard.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/Vcard.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -1,644 +0,0 @@
-/* **********************************************************************
-    Copyright 2006 Rensselaer Polytechnic Institute. All worldwide rights reserved.
-
-    Redistribution and use of this distribution in source and binary forms,
-    with or without modification, are permitted provided that:
-       The above copyright notice and this permission notice appear in all
-        copies and supporting documentation;
-
-        The name, identifiers, and trademarks of Rensselaer Polytechnic
-        Institute are not used in advertising or publicity without the
-        express prior written permission of Rensselaer Polytechnic Institute;
-
-    DISCLAIMER: The software is distributed" AS IS" without any express or
-    implied warranty, including but not limited to, any implied warranties
-    of merchantability or fitness for a particular purpose or any warrant)'
-    of non-infringement of any current or pending patent rights. The authors
-    of the software make no representations about the suitability of this
-    software for any particular purpose. The entire risk as to the quality
-    and performance of the software is with the user. Should the software
-    prove defective, the user assumes the cost of all necessary servicing,
-    repair or correction. In particular, neither Rensselaer Polytechnic
-    Institute, nor the authors of the software are liable for any indirect,
-    special, consequential, or incidental damages related to the software,
-    to the maximum extent the law permits.
-*/
-
-package org.bedework.carddav.server;
-
-import org.bedework.carddav.util.Tokenizer;
-import org.bedework.carddav.util.Uid;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StreamTokenizer;
-import java.util.ArrayList;
-import java.util.Collection;
-
-import edu.rpi.cct.webdav.servlet.shared.WebdavException;
-import edu.rpi.cmt.access.AccessPrincipal;
-import edu.rpi.sss.util.Util;
-
-/** Temp def of vcard to get us going
- *
- * @author douglm
- *
- */
-public class Vcard {
-  /**
-   * @author douglm
-   *
-   */
-  public static class Param {
-    String name;
-    String value;
-
-    /**
-     *
-     */
-    public Param() {
-    }
-
-    /**
-     * @param name
-     * @param value
-     */
-    public Param(String name, String value) {
-      this.name = name;
-      this.value = value;
-    }
-
-    /** Crude vcard parameter output method
-     *
-     * @param sb
-     */
-    public void output(StringBuilder sb) {
-      if (value == null) {
-        return;
-      }
-
-      sb.append(name);
-      sb.append("=");
-      sb.append(value);
-    }
-
-    /**
-     * @param indent
-     * @param sb
-     */
-    public void outputJson(String indent, StringBuilder sb) {
-      /* "email" : [
-      {"type" : ["pref"], "value" : "foo at example.com"},
-      {"value" : "bar at example.com"}
-    ]
-   */
-      if (value == null) {
-        return;
-      }
-
-      sb.append(indent);
-      sb.append("{\"");
-      sb.append(Util.jsonName(name));
-      sb.append("\", \"value\" : ");
-      sb.append(Util.jsonEncode(value));
-      sb.append("}");
-    }
-
-
-    /**
-     * @param tokeniser
-     * @return
-     * @throws WebdavException
-     */
-    public Param parse(Tokenizer tokeniser) throws WebdavException {
-      try {
-        tokeniser.assertWord();
-
-        name = tokeniser.sval;
-
-        if (tokeniser.nextToken() == '=') {
-          tokeniser.assertWord();
-
-          value = tokeniser.sval;
-        } else {
-          tokeniser.pushBack();
-        }
-      } catch (IOException e) {
-        throw new WebdavException(e);
-      }
-
-      return this;
-    }
-
-    public String toString() {
-      StringBuilder sb = new StringBuilder();
-
-      output(sb);
-
-      return sb.toString();
-    }
-  }
-
-  /**
-   * @author douglm
-   *
-   */
-  public static class Property {
-    String group;
-    String name;
-
-    Collection<Param> params;
-
-    String value;
-
-    /**
-     *
-     */
-    public Property() {
-    }
-
-    /**
-     * @param name
-     * @param value
-     */
-    public Property(String name, String value) {
-      this(null, name, (Collection<Param>)null, value);
-    }
-
-    /**
-     * @param group
-     * @param name
-     * @param value
-     */
-    public Property(String group, String name, String value) {
-      this(group, name, (Collection<Param>)null, value);
-    }
-
-    /**
-     * @param name
-     * @param params
-     * @param value
-     */
-    public Property(String name,
-                    Collection<Param> params,
-                    String value) {
-      this(null, name, params, value);
-    }
-
-    /**
-     * @param group
-     * @param name
-     * @param params
-     * @param value
-     */
-    public Property(String group,
-                    String name,
-                    Collection<Param> params,
-                    String value) {
-      this.group = group;
-      this.name = name;
-      this.params = params;
-      this.value = value;
-    }
-
-    /**
-     * @return String name
-     */
-    public String getName() {
-      return name;
-    }
-
-    /**
-     * @return String value
-     */
-    public String getValue() {
-      return value;
-    }
-
-    /**
-     * @param val
-     */
-    public void addParam(Param val) {
-      if (params == null) {
-        params = new ArrayList<Param>();
-      }
-
-      params.add(val);
-    }
-
-    /**
-     * @param tokeniser
-     * @return Property
-     * @throws WebdavException
-     */
-    public Property parse(Tokenizer tokeniser) throws WebdavException {
-      try {
-        tokeniser.assertWord();
-
-        String temp = tokeniser.sval;
-
-        if (tokeniser.nextToken() == ',') {
-          group = temp;
-          tokeniser.assertWord();
-
-          temp = tokeniser.sval;
-        } else {
-          tokeniser.pushBack();
-        }
-
-        name = temp;
-
-        while (tokeniser.nextToken() == ';') {
-          addParam(new Param().parse(tokeniser));
-        }
-
-        tokeniser.assertToken(':');
-      } catch (IOException e) {
-        throw new WebdavException(e);
-      }
-
-      return this;
-    }
-
-    /** Crude vcard property output method
-     *
-     * @param sb
-     */
-    public void output(StringBuilder sb) {
-      if (value == null) {
-        return;
-      }
-
-      sb.append(name);
-
-      if (params != null) {
-        for (Param par: params) {
-          sb.append(";");
-          par.output(sb);
-        }
-      }
-
-      sb.append(":");
-      sb.append(value);
-      sb.append("\n");
-    }
-
-    /**
-     * @param indent
-     * @param sb
-     */
-    public void outputJson(String indent, StringBuilder sb) {
-      /* "email" : [
-      {"type" : ["pref"], "value" : "foo at example.com"},
-      {"value" : "bar at example.com"}
-    ]
-   */
-
-      if (value == null) {
-        return;
-      }
-
-      sb.append(indent);
-      sb.append("\"");
-      sb.append(Util.jsonName(name));
-      sb.append("\" : [\n");
-
-      String saveIndent = indent;
-      indent +="  ";
-
-      if (params != null) {
-        for (Param par: params) {
-          par.outputJson(indent, sb);
-          sb.append(",\n");
-        }
-      }
-
-      sb.append(indent);
-      sb.append("{\"value\" : ");
-      sb.append(Util.jsonEncode(value));
-      sb.append("}\n");
-
-      indent = saveIndent;
-      sb.append(indent);
-      sb.append("]\n");
-    }
-
-    public String toString() {
-      StringBuilder sb = new StringBuilder();
-
-      output(sb);
-
-      return sb.toString();
-    }
-  }
-
-  private AccessPrincipal owner;
-
-  private String name;
-
-  private CarddavCollection parent;
-
-  private String created;
-
-  private Collection<Property> props;
-
-  private String strForm;
-
-  private String jsonStrForm;
-
-  private String prevLastmod;
-
-  /**
-   * @param val
-   */
-  public void setOwner(AccessPrincipal val) {
-    owner = val;
-  }
-
-  /**
-   * @return AccessPrincipal
-   */
-  public AccessPrincipal getOwner() {
-    return owner;
-  }
-
-  /** Set the name
-  *
-  * @param val    String name
-  */
- public void setName(String val) {
-   name = val;
- }
-
- /** Get the name
-  *
-  * @return String   name
-  */
- public String getName() {
-   return name;
- }
-
-  /**
-   * @param val
-   */
-  public void setCreated(String val) {
-    created = val;
-  }
-
-  /**
-   * @return String created
-   */
-  public String getCreated() {
-    return created;
-  }
-
-  /**
-   * @param val
-   */
-  public void setLastmod(String val) {
-    Property rev = findProperty("REV");
-
-    if (rev == null) {
-      rev = new Property("REV", null);
-      addProperty(rev);
-    }
-
-    rev.value = val;
-  }
-
-  /**
-   * @return String
-   */
-  public String getLastmod() {
-    Property rev = findProperty("REV");
-
-    if (rev == null) {
-      return null;
-    }
-
-    return rev.value;
-  }
-
-  /** Lastmod before any changes were made
-   *
-   * @return String
-   */
-  public String getPrevLastmod() {
-    return prevLastmod;
-  }
-
-  /**
-   * @param val
-   */
-  public void setUid(String val) {
-    Property uid = findProperty("UID");
-
-    if (uid == null) {
-      uid = new Property("UID", null);
-      addProperty(uid);
-    }
-
-    uid.value = val;
-  }
-
-  /**
-   * @return String
-   */
-  public String getUid() {
-    Property uid = findProperty("UID");
-
-    if (uid == null) {
-      setUid(Uid.getUid());
-      uid = findProperty("UID");
-    }
-
-    return uid.value;
-  }
-
-  /**
-   * @param val
-   */
-  public void setParent(CarddavCollection val) {
-    parent = val;
-  }
-
-  /**
-   * @return parent.
-   */
-  public CarddavCollection getParent() {
-    return parent;
-  }
-
-  /**
-   * @param val
-   */
-  public void addProperty(Property val) {
-    if (props == null) {
-      props = new ArrayList<Property>();
-    }
-
-    props.add(val);
-  }
-
-  /**
-   * @param name
-   * @return property or null
-   */
-  public Property findProperty(String name) {
-    if (props == null) {
-      return null;
-    }
-
-    for (Property p: props) {
-      if (name.equals(p.name)) {
-        return p;
-      }
-    }
-
-    return null;
-  }
-
-  private static final int WORD_CHAR_START = 32;
-
-  private static final int WORD_CHAR_END = 255;
-
-  private static final int WHITESPACE_CHAR_START = 0;
-
-  private static final int WHITESPACE_CHAR_END = 20;
-
-  /**
-   * @param rdr
-   * @return Vcard
-   * @throws WebdavException
-   */
-  public Vcard parse(Reader rdr) throws WebdavException {
-    Tokenizer tokeniser = new Tokenizer(rdr);
-
-    try {
-      tokeniser.resetSyntax();
-      tokeniser.wordChars(WORD_CHAR_START, WORD_CHAR_END);
-      tokeniser.whitespaceChars(WHITESPACE_CHAR_START,
-                                WHITESPACE_CHAR_END);
-      tokeniser.ordinaryChar(':');
-      tokeniser.ordinaryChar(';');
-      tokeniser.ordinaryChar('=');
-      tokeniser.ordinaryChar('\t');
-      tokeniser.eolIsSignificant(true);
-      tokeniser.whitespaceChars(0, 0);
-      tokeniser.quoteChar('"');
-
-      // BEGIN:VCALENDAR
-      tokeniser.assertToken("BEGIN");
-
-      tokeniser.assertToken(':');
-
-      tokeniser.assertToken("VCARD", true);
-
-      tokeniser.assertToken(StreamTokenizer.TT_EOL);
-
-      while (!tokeniser.testToken("END")) {
-        addProperty(new Property().parse(tokeniser));
-        tokeniser.skipWhitespace();
-      }
-
-      tokeniser.assertToken(':');
-
-      tokeniser.assertToken("VCARD", true);
-      tokeniser.skipWhitespace();
-
-      prevLastmod = getLastmod();
-
-      return this;
-    } catch (WebdavException wde) {
-      throw wde;
-    } catch (Exception e) {
-      throw new WebdavException(e);
-    }
-  }
-
-  /**
-   * @return String
-   */
-  public String output() {
-    if (strForm != null) {
-      return strForm;
-    }
-
-    StringBuilder sb = new StringBuilder();
-
-    sb.append("BEGIN:VCARD\n");
-    sb.append("VERSION:4.0\n");
-
-    if (props != null) {
-      for (Property p: props) {
-        if ("VERSION".equals(p.name)) {
-          continue;
-        }
-
-        p.output(sb);
-      }
-    }
-
-    sb.append("END:VCARD\n\n");
-
-    strForm = sb.toString();
-
-    return strForm;
-  }
-
-  /**
-   * @param indent
-   * @return String
-   */
-  public String outputJson(String indent) {
-    if (jsonStrForm != null) {
-      return jsonStrForm;
-    }
-
-    StringBuilder sb = new StringBuilder();
-
-    sb.append(indent);
-    sb.append("{\n");
-
-    indent += "";
-
-    new Property("VERSION", "4.0").outputJson(indent, sb);
-
-    if (props != null) {
-      for (Property p: props) {
-        if ("VERSION".equals(p.name)) {
-          continue;
-        }
-
-        p.outputJson(indent, sb);
-      }
-    }
-
-    sb.append(indent);
-    sb.append("}");
-
-    jsonStrForm = sb.toString();
-
-    return jsonStrForm;
-  }
-  /*
-  {
-    "microformats": {
-        "vcard": []
-    },
-    "parser-information": {
-        "name": "UfXtract",
-        "version": "0.1",
-        "page-http-status": "404",
-        "page-title": "hcard1";
-        "page-url": "http:\/\/ufxtract.com\/testsuite\/hcard\/1.0\/nofilehere.htm";
-        "time": "T000001.0002"
-    },
-    "errors": [ "URL not found" ]
-}
-  */
-
-  public String toString() {
-    return output();
-  }
-}

Modified: trunk/server/src/org/bedework/carddav/server/calquery/AddressData.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/calquery/AddressData.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/calquery/AddressData.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -26,8 +26,8 @@
 package org.bedework.carddav.server.calquery;
 
 import org.bedework.carddav.server.CarddavCardNode;
-import org.bedework.carddav.server.Vcard;
-import org.bedework.carddav.server.Vcard.Property;
+import org.bedework.carddav.vcard.Property;
+import org.bedework.carddav.vcard.Vcard;
 
 import edu.rpi.cct.webdav.servlet.shared.WebdavBadRequest;
 import edu.rpi.cct.webdav.servlet.shared.WebdavException;

Modified: trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapAddrBookDirHandler.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapAddrBookDirHandler.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapAddrBookDirHandler.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -27,9 +27,9 @@
 
 import org.bedework.carddav.server.CarddavCardNode;
 import org.bedework.carddav.server.CarddavCollection;
-import org.bedework.carddav.server.Vcard;
 import org.bedework.carddav.util.CardDAVConfig;
 import org.bedework.carddav.util.DirHandlerConfig;
+import org.bedework.carddav.vcard.Vcard;
 import org.bedework.webdav.WdCollection;
 
 import edu.rpi.cct.webdav.servlet.shared.WebdavException;

Modified: trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapDirHandler.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapDirHandler.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapDirHandler.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -26,15 +26,15 @@
 package org.bedework.carddav.server.dirHandlers;
 
 import org.bedework.carddav.server.CarddavCollection;
-import org.bedework.carddav.server.Vcard;
-import org.bedework.carddav.server.Vcard.Param;
-import org.bedework.carddav.server.Vcard.Property;
 import org.bedework.carddav.server.filter.Filter;
 import org.bedework.carddav.server.filter.PropFilter;
 import org.bedework.carddav.server.filter.TextMatch;
 import org.bedework.carddav.util.CardDAVConfig;
 import org.bedework.carddav.util.DirHandlerConfig;
 import org.bedework.carddav.util.LdapDirHandlerConfig;
+import org.bedework.carddav.vcard.Param;
+import org.bedework.carddav.vcard.Property;
+import org.bedework.carddav.vcard.Vcard;
 
 import edu.rpi.cct.webdav.servlet.shared.WebdavException;
 import edu.rpi.cct.webdav.servlet.shared.WebdavNsNode.UrlHandler;

Modified: trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapPrincipalDirHandler.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapPrincipalDirHandler.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/dirHandlers/LdapPrincipalDirHandler.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -27,10 +27,10 @@
 
 import org.bedework.carddav.server.CarddavCardNode;
 import org.bedework.carddav.server.CarddavCollection;
-import org.bedework.carddav.server.Vcard;
 import org.bedework.carddav.util.CardDAVConfig;
 import org.bedework.carddav.util.DirHandlerConfig;
 import org.bedework.carddav.util.LdapDirHandlerConfig;
+import org.bedework.carddav.vcard.Vcard;
 import org.bedework.webdav.WdCollection;
 
 import edu.rpi.cct.webdav.servlet.shared.WebdavException;

Modified: trunk/server/src/org/bedework/carddav/server/filter/Filter.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/filter/Filter.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/filter/Filter.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -26,7 +26,7 @@
 package org.bedework.carddav.server.filter;
 
 import org.bedework.carddav.server.CarddavNode;
-import org.bedework.carddav.server.Vcard;
+import org.bedework.carddav.vcard.Vcard;
 
 import edu.rpi.cct.webdav.servlet.shared.WebdavException;
 import edu.rpi.cct.webdav.servlet.shared.WebdavNsNode;

Modified: trunk/server/src/org/bedework/carddav/server/filter/PropFilter.java
===================================================================
--- trunk/server/src/org/bedework/carddav/server/filter/PropFilter.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/server/filter/PropFilter.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -29,9 +29,10 @@
 import java.util.Collection;
 
 import org.apache.log4j.Logger;
-import org.bedework.carddav.server.Vcard;
-import org.bedework.carddav.server.Vcard.Property;
 
+import org.bedework.carddav.vcard.Property;
+import org.bedework.carddav.vcard.Vcard;
+
 import edu.rpi.cct.webdav.servlet.shared.WebdavException;
 
 /**

Deleted: trunk/server/src/org/bedework/carddav/util/CompatibilityHints.java
===================================================================
--- trunk/server/src/org/bedework/carddav/util/CompatibilityHints.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/util/CompatibilityHints.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -1,106 +0,0 @@
-/*
- * $Id: CompatibilityHints.java,v 1.6 2006/11/11 04:43:29 fortuna Exp $
- *
- * Created on 9/03/2006
- *
- * Copyright (c) 2006, Ben Fortuna
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *  o Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- *  o Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- *  o Neither the name of Ben Fortuna nor the names of any other contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package org.bedework.carddav.util;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * A set of keys used to enable compatibility features.
- * @author Ben Fortuna
- */
-public final class CompatibilityHints {
-
-    /**
-     * A system property key to enable relaxed unfolding. Relaxed unfolding is enabled by setting this system property
-     * to "true".
-     */
-    public static final String KEY_RELAXED_UNFOLDING = "vcard.unfolding.relaxed";
-
-    /**
-     * A system property key to enable relaxed parsing. Relaxed parsing is enabled by setting this system property to
-     * "true".
-     */
-    public static final String KEY_RELAXED_PARSING = "vcard.parsing.relaxed";
-
-    /**
-     * A system property key to enable relaxed validation. Relaxed validation disables validation of certain conformance
-     * rules that many iCalendar implementations do not conform to. Relaxed validation is enabled by setting this system
-     * property to "true".
-     */
-    public static final String KEY_RELAXED_VALIDATION = "vcard.validation.relaxed";
-
-    /**
-     * A system property key used to enable compatibility with Outlook/Exchange-generated iCalendar files. Outlook
-     * compatibility is enabled by setting this system property to "true".
-     */
-    public static final String KEY_OUTLOOK_COMPATIBILITY = "vcard.compatibility.outlook";
-
-    /**
-     * A system property key used to enable compatibility with Lotus Notes-generated iCalendar files. Notes
-     * compatibility is enabled by setting this system property to "true".
-     */
-    public static final String KEY_NOTES_COMPATIBILITY = "vcard.compatibility.notes";
-
-    private static final Map<String, Boolean> HINTS = new HashMap<String, Boolean>();
-
-    /**
-     * Constructor made private to enforce static nature.
-     */
-    private CompatibilityHints() {
-    }
-
-    /**
-     * @param key
-     * @param enabled
-     */
-    public static void setHintEnabled(final String key, final boolean enabled) {
-      HINTS.put(key, enabled);
-    }
-
-    /**
-     * @param key
-     * @return
-     */
-    public static boolean isHintEnabled(final String key) {
-      Boolean enabled = HINTS.get(key);
-      if (enabled != null) {
-        return enabled;
-      }
-
-      return "true".equals(System.getProperty(key));
-    }
-}

Deleted: trunk/server/src/org/bedework/carddav/util/Tokenizer.java
===================================================================
--- trunk/server/src/org/bedework/carddav/util/Tokenizer.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/util/Tokenizer.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -1,187 +0,0 @@
-package org.bedework.carddav.util;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StreamTokenizer;
-
-import org.apache.log4j.Logger;
-import org.bedework.carddav.server.Debug;
-
-import edu.rpi.cct.webdav.servlet.shared.WebdavException;
-
-/**
- * @author douglm
- *
- */
-public class Tokenizer extends StreamTokenizer {
-  private transient Logger log;
-
-  /**
-   * @param rdr
-   */
-  public Tokenizer(Reader rdr) {
-    super(new UnfoldingReader(rdr));
-  }
-
-  /**
-   * Asserts that the next token in the stream matches the specified token.
-   *
-   * @param token expected token
-   * @throws WebdavException
-   */
-  public void assertToken(int token) throws WebdavException {
-    try {
-      if (nextToken() != token) {
-        throw new WebdavException("Expected [" + token + "], read [" +
-                                  ttype + "] at " + lineno());
-      }
-
-      if (Debug.enabled) {
-        debugMsg("[" + token + "]");
-      }
-    } catch (IOException e) {
-      throw new WebdavException(e);
-    }
-  }
-
-  /**
-   * @throws WebdavException
-   */
-  public void assertWord()  throws WebdavException {
-    assertToken(StreamTokenizer.TT_WORD);
-  }
-
-  /**
-   * Asserts that the next token in the stream matches the specified token.
-   * This method is case-sensitive.
-   *
-   * @param token
-   * @throws WebdavException
-   */
-  public void assertToken(String token) throws WebdavException {
-    assertToken(token, false);
-  }
-
-  /**
-   * Asserts that the next token in the stream matches the specified token.
-   *
-   * @param token expected token
-   * @param ignoreCase
-   * @throws WebdavException
-   */
-  public void assertToken(String token, boolean ignoreCase) throws WebdavException {
-    // ensure next token is a word token..
-    assertWord();
-
-    if (ignoreCase) {
-      if (!token.equalsIgnoreCase(sval)) {
-        throw new WebdavException("Expected [" + token + "], read [" +
-                                  sval + "] at " + lineno());
-      }
-    }
-    else if (!token.equals(sval)) {
-      throw new WebdavException( "Expected [" + token + "], read [" +
-                                sval + "] at " + lineno());
-    }
-
-    if (Debug.enabled) {
-      debugMsg("[" + token + "]");
-    }
-  }
-
-  /**
-   * Tests that the next token in the stream matches the specified token.
-   * This method is case-sensitive.
-   *
-   * @param token
-   * @return boolean
-   * @throws WebdavException
-   */
-  public boolean testToken(int token) throws WebdavException {
-    try {
-      boolean res = nextToken() == token;
-
-      if (!res) {
-        pushBack();
-        return false;
-      }
-
-      return true;
-    } catch (IOException e) {
-      throw new WebdavException(e);
-    }
-  }
-
-  /**
-   * Tests if the next token in the stream matches the specified token.
-   *
-   * @param token expected token
-   * @return int
-   * @throws WebdavException
-   */
-  public boolean testToken(String token) throws WebdavException {
-    return testToken(token, false);
-  }
-
-  /**
-   * Tests if the next token in the stream matches the specified token.
-   *
-   * @param token expected token
-   * @param ignoreCase
-   * @return boolean
-   * @throws WebdavException
-   */
-  public boolean testToken(String token, boolean ignoreCase) throws WebdavException {
-    // ensure next token is a word token..
-    if (!testToken(StreamTokenizer.TT_WORD)) {
-      return false;
-    }
-
-    if (ignoreCase) {
-      if (!token.equalsIgnoreCase(sval)) {
-        pushBack();
-        return false;
-      }
-    } else if (!token.equals(sval)) {
-      pushBack();
-      return false;
-    }
-
-    return true;
-  }
-
-  /**
-   * Absorbs extraneous newlines.
-   * @param tokeniser
-   * @throws WebdavException
-   */
-  public void skipWhitespace() throws WebdavException {
-    while (true) {
-      assertToken(StreamTokenizer.TT_EOL);
-    }
-  }
-
-  protected Logger getLogger() {
-    if (log == null) {
-      log = Logger.getLogger(this.getClass());
-    }
-
-    return log;
-  }
-
-  protected void error(Throwable t) {
-    getLogger().error(this, t);
-  }
-
-  protected void warn(String msg) {
-    getLogger().warn(msg);
-  }
-
-  protected void debugMsg(String msg) {
-    getLogger().debug(msg);
-  }
-
-  protected void logIt(String msg) {
-    getLogger().info(msg);
-  }
-}

Deleted: trunk/server/src/org/bedework/carddav/util/UnfoldingReader.java
===================================================================
--- trunk/server/src/org/bedework/carddav/util/UnfoldingReader.java	2008-11-25 21:12:42 UTC (rev 15)
+++ trunk/server/src/org/bedework/carddav/util/UnfoldingReader.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -1,157 +0,0 @@
-/*
- * $Id: UnfoldingReader.java,v 1.19 2007/06/19 12:28:29 fortuna Exp $ [06-Apr-2004]
- *
- * Copyright (c) 2005, Ben Fortuna
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- *  o Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- *  o Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- *  o Neither the name of Ben Fortuna nor the names of any other contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-/* Shamelessly stolen from Ben by Mike Douglass
- */
-package org.bedework.carddav.util;
-
-import java.io.IOException;
-import java.io.PushbackReader;
-import java.io.Reader;
-import java.util.Arrays;
-
-import org.apache.log4j.Logger;
-
-/**
- * A reader which performs iCalendar unfolding as it reads. Note that unfolding
- * rules may be "relaxed" to allow unfolding of non-conformant *.ics files.
- *
- * By specifying the system property "ical4j.unfolding.relaxed=true" iCalendar
- * files created with Mozilla Calendar/Sunbird may be correctly unfolded.
- * @author Ben Fortuna
- */
-public class UnfoldingReader extends PushbackReader {
-  private Logger log;
-
-  /**
-   * The pattern used to identify a fold in an iCalendar data stream.
-   */
-  private static final char[] DEFAULT_FOLD_PATTERN = { '\r', '\n', ' ' };
-
-  /**
-   * The pattern used to identify a fold in Mozilla Calendar/Sunbird and KOrganizer.
-   */
-  private static final char[] RELAXED_FOLD_PATTERN_1 = { '\n', ' ' };
-
-  /**
-   * The pattern used to identify a fold in Microsoft Outlook 2007.
-   */
-  private static final char[] RELAXED_FOLD_PATTERN_2 = { '\r', '\n', '\t' };
-
-  /**
-   * The pattern used to identify a fold in Microsoft Outlook 2007.
-   */
-  private static final char[] RELAXED_FOLD_PATTERN_3 = { '\n', '\t' };
-
-  private char[][] patterns;
-
-  private char[][] buffers;
-
-  private int linesUnfolded;
-
-  /**
-   * Creates a new unfolding reader instance. Relaxed unfolding flag is read
-   * from system property.
-   *
-   * @param in the reader to unfold from
-   */
-  public UnfoldingReader(final Reader in) {
-    this(in, CompatibilityHints
-         .isHintEnabled(CompatibilityHints.KEY_RELAXED_UNFOLDING));
-  }
-
-  /**
-   * Creates a new unfolding reader instance.
-   * @param in a reader to read from
-   * @param relaxed specifies whether unfolding is relaxed
-   */
-  public UnfoldingReader(final Reader in, final boolean relaxed) {
-    super(in, DEFAULT_FOLD_PATTERN.length);
-    if (relaxed) {
-      patterns = new char[4][];
-      patterns[0] = DEFAULT_FOLD_PATTERN;
-      patterns[1] = RELAXED_FOLD_PATTERN_1;
-      patterns[2] = RELAXED_FOLD_PATTERN_2;
-      patterns[3] = RELAXED_FOLD_PATTERN_3;
-    }
-    else {
-      patterns = new char[1][];
-      patterns[0] = DEFAULT_FOLD_PATTERN;
-    }
-    buffers = new char[patterns.length][];
-    for (int i = 0; i < patterns.length; i++) {
-      buffers[i] = new char[patterns[i].length];
-    }
-  }
-
-  /**
-   * @return number of lines unfolded so far while reading
-   */
-  public final int getLinesUnfolded() {
-    return linesUnfolded;
-  }
-
-  /**
-   * @see java.io.PushbackReader#read()
-   */
-  public final int read() throws IOException {
-    boolean didUnfold;
-
-    // need to loop since one line fold might be directly followed by another
-    do {
-      didUnfold = false;
-
-      for (int i = 0; i < buffers.length; i++) {
-        int read = super.read(buffers[i]);
-        if (read > 0) {
-          if (!Arrays.equals(patterns[i], buffers[i])) {
-            unread(buffers[i], 0, read);
-          }
-          else {
-            if (log.isDebugEnabled()) {
-              log.debug("Unfolding...");
-            }
-            linesUnfolded++;
-            didUnfold = true;
-          }
-        }
-        else {
-          return read;
-        }
-      }
-    }
-    while (didUnfold);
-
-    return super.read();
-  }
-}

Copied: trunk/server/src/org/bedework/carddav/vcard/CompatibilityHints.java (from rev 14, trunk/server/src/org/bedework/carddav/util/CompatibilityHints.java)
===================================================================
--- trunk/server/src/org/bedework/carddav/vcard/CompatibilityHints.java	                        (rev 0)
+++ trunk/server/src/org/bedework/carddav/vcard/CompatibilityHints.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -0,0 +1,106 @@
+/*
+ * $Id: CompatibilityHints.java,v 1.6 2006/11/11 04:43:29 fortuna Exp $
+ *
+ * Created on 9/03/2006
+ *
+ * Copyright (c) 2006, Ben Fortuna
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  o Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ *  o Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ *  o Neither the name of Ben Fortuna nor the names of any other contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.bedework.carddav.vcard;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A set of keys used to enable compatibility features.
+ * @author Ben Fortuna
+ */
+public final class CompatibilityHints {
+
+    /**
+     * A system property key to enable relaxed unfolding. Relaxed unfolding is enabled by setting this system property
+     * to "true".
+     */
+    public static final String KEY_RELAXED_UNFOLDING = "vcard.unfolding.relaxed";
+
+    /**
+     * A system property key to enable relaxed parsing. Relaxed parsing is enabled by setting this system property to
+     * "true".
+     */
+    public static final String KEY_RELAXED_PARSING = "vcard.parsing.relaxed";
+
+    /**
+     * A system property key to enable relaxed validation. Relaxed validation disables validation of certain conformance
+     * rules that many iCalendar implementations do not conform to. Relaxed validation is enabled by setting this system
+     * property to "true".
+     */
+    public static final String KEY_RELAXED_VALIDATION = "vcard.validation.relaxed";
+
+    /**
+     * A system property key used to enable compatibility with Outlook/Exchange-generated iCalendar files. Outlook
+     * compatibility is enabled by setting this system property to "true".
+     */
+    public static final String KEY_OUTLOOK_COMPATIBILITY = "vcard.compatibility.outlook";
+
+    /**
+     * A system property key used to enable compatibility with Lotus Notes-generated iCalendar files. Notes
+     * compatibility is enabled by setting this system property to "true".
+     */
+    public static final String KEY_NOTES_COMPATIBILITY = "vcard.compatibility.notes";
+
+    private static final Map<String, Boolean> HINTS = new HashMap<String, Boolean>();
+
+    /**
+     * Constructor made private to enforce static nature.
+     */
+    private CompatibilityHints() {
+    }
+
+    /**
+     * @param key
+     * @param enabled
+     */
+    public static void setHintEnabled(final String key, final boolean enabled) {
+      HINTS.put(key, enabled);
+    }
+
+    /**
+     * @param key
+     * @return
+     */
+    public static boolean isHintEnabled(final String key) {
+      Boolean enabled = HINTS.get(key);
+      if (enabled != null) {
+        return enabled;
+      }
+
+      return "true".equals(System.getProperty(key));
+    }
+}


Property changes on: trunk/server/src/org/bedework/carddav/vcard/CompatibilityHints.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Added: trunk/server/src/org/bedework/carddav/vcard/Param.java
===================================================================
--- trunk/server/src/org/bedework/carddav/vcard/Param.java	                        (rev 0)
+++ trunk/server/src/org/bedework/carddav/vcard/Param.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -0,0 +1,127 @@
+/* **********************************************************************
+    Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+    Redistribution and use of this distribution in source and binary forms,
+    with or without modification, are permitted provided that:
+       The above copyright notice and this permission notice appear in all
+        copies and supporting documentation;
+
+        The name, identifiers, and trademarks of Rensselaer Polytechnic
+        Institute are not used in advertising or publicity without the
+        express prior written permission of Rensselaer Polytechnic Institute;
+
+    DISCLAIMER: The software is distributed" AS IS" without any express or
+    implied warranty, including but not limited to, any implied warranties
+    of merchantability or fitness for a particular purpose or any warrant)'
+    of non-infringement of any current or pending patent rights. The authors
+    of the software make no representations about the suitability of this
+    software for any particular purpose. The entire risk as to the quality
+    and performance of the software is with the user. Should the software
+    prove defective, the user assumes the cost of all necessary servicing,
+    repair or correction. In particular, neither Rensselaer Polytechnic
+    Institute, nor the authors of the software are liable for any indirect,
+    special, consequential, or incidental damages related to the software,
+    to the maximum extent the law permits.
+*/
+package org.bedework.carddav.vcard;
+
+import edu.rpi.cct.webdav.servlet.shared.WebdavException;
+import edu.rpi.sss.util.Util;
+
+import java.io.IOException;
+
+/** Vcard parameter
+ *
+ * @author douglm
+ *
+ */
+public class Param {
+  private String name;
+
+  private String value;
+
+  /**
+   *
+   */
+  public Param() {
+  }
+
+  /**
+   * @param name
+   * @param value
+   */
+  public Param(String name, String value) {
+    this.name = name;
+    this.value = value;
+  }
+
+  /** Crude vcard parameter output method
+   *
+   * @param sb
+   */
+  public void output(StringBuilder sb) {
+    if (value == null) {
+      return;
+    }
+
+    sb.append(name);
+    sb.append("=");
+    sb.append(value);
+  }
+
+  /**
+   * @param indent
+   * @param sb
+   */
+  public void outputJson(String indent, StringBuilder sb) {
+    /* "email" : [
+    {"type" : ["pref"], "value" : "foo at example.com"},
+    {"value" : "bar at example.com"}
+  ]
+ */
+    if (value == null) {
+      return;
+    }
+
+    sb.append(indent);
+    sb.append("{\"");
+    sb.append(Util.jsonName(name));
+    sb.append("\", \"value\" : ");
+    sb.append(Util.jsonEncode(value));
+    sb.append("}");
+  }
+
+
+  /**
+   * @param tokeniser
+   * @return
+   * @throws WebdavException
+   */
+  public Param parse(Tokenizer tokeniser) throws WebdavException {
+    try {
+      tokeniser.assertWord();
+
+      name = tokeniser.sval;
+
+      if (tokeniser.nextToken() == '=') {
+        tokeniser.assertWord();
+
+        value = tokeniser.sval;
+      } else {
+        tokeniser.pushBack();
+      }
+    } catch (IOException e) {
+      throw new WebdavException(e);
+    }
+
+    return this;
+  }
+
+  public String toString() {
+    StringBuilder sb = new StringBuilder();
+
+    output(sb);
+
+    return sb.toString();
+  }
+}
\ No newline at end of file

Added: trunk/server/src/org/bedework/carddav/vcard/Property.java
===================================================================
--- trunk/server/src/org/bedework/carddav/vcard/Property.java	                        (rev 0)
+++ trunk/server/src/org/bedework/carddav/vcard/Property.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -0,0 +1,231 @@
+/* **********************************************************************
+    Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+    Redistribution and use of this distribution in source and binary forms,
+    with or without modification, are permitted provided that:
+       The above copyright notice and this permission notice appear in all
+        copies and supporting documentation;
+
+        The name, identifiers, and trademarks of Rensselaer Polytechnic
+        Institute are not used in advertising or publicity without the
+        express prior written permission of Rensselaer Polytechnic Institute;
+
+    DISCLAIMER: The software is distributed" AS IS" without any express or
+    implied warranty, including but not limited to, any implied warranties
+    of merchantability or fitness for a particular purpose or any warrant)'
+    of non-infringement of any current or pending patent rights. The authors
+    of the software make no representations about the suitability of this
+    software for any particular purpose. The entire risk as to the quality
+    and performance of the software is with the user. Should the software
+    prove defective, the user assumes the cost of all necessary servicing,
+    repair or correction. In particular, neither Rensselaer Polytechnic
+    Institute, nor the authors of the software are liable for any indirect,
+    special, consequential, or incidental damages related to the software,
+    to the maximum extent the law permits.
+*/
+package org.bedework.carddav.vcard;
+
+import edu.rpi.cct.webdav.servlet.shared.WebdavException;
+import edu.rpi.sss.util.Util;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+/** Vcard property
+ *
+ * @author douglm
+ *
+ */
+/**
+ * @author douglm
+ *
+ */
+public class Property {
+  String group;
+  String name;
+
+  Collection<Param> params;
+
+  String value;
+
+  /**
+   *
+   */
+  public Property() {
+  }
+
+  /**
+   * @param name
+   * @param value
+   */
+  public Property(String name, String value) {
+    this(null, name, (Collection<Param>)null, value);
+  }
+
+  /**
+   * @param group
+   * @param name
+   * @param value
+   */
+  public Property(String group, String name, String value) {
+    this(group, name, (Collection<Param>)null, value);
+  }
+
+  /**
+   * @param name
+   * @param params
+   * @param value
+   */
+  public Property(String name,
+                  Collection<Param> params,
+                  String value) {
+    this(null, name, params, value);
+  }
+
+  /**
+   * @param group
+   * @param name
+   * @param params
+   * @param value
+   */
+  public Property(String group,
+                  String name,
+                  Collection<Param> params,
+                  String value) {
+    this.group = group;
+    this.name = name;
+    this.params = params;
+    this.value = value;
+  }
+
+  /**
+   * @return String name
+   */
+  public String getName() {
+    return name;
+  }
+
+  /**
+   * @return String value
+   */
+  public String getValue() {
+    return value;
+  }
+
+  /**
+   * @param val
+   */
+  public void addParam(Param val) {
+    if (params == null) {
+      params = new ArrayList<Param>();
+    }
+
+    params.add(val);
+  }
+
+  /**
+   * @param tokeniser
+   * @return Property
+   * @throws WebdavException
+   */
+  public Property parse(Tokenizer tokeniser) throws WebdavException {
+    try {
+      tokeniser.assertWord();
+
+      String temp = tokeniser.sval;
+
+      if (tokeniser.nextToken() == ',') {
+        group = temp;
+        tokeniser.assertWord();
+
+        temp = tokeniser.sval;
+      } else {
+        tokeniser.pushBack();
+      }
+
+      name = temp;
+
+      while (tokeniser.nextToken() == ';') {
+        addParam(new Param().parse(tokeniser));
+      }
+
+      tokeniser.assertToken(':');
+    } catch (IOException e) {
+      throw new WebdavException(e);
+    }
+
+    return this;
+  }
+
+  /** Crude vcard property output method
+   *
+   * @param sb
+   */
+  public void output(StringBuilder sb) {
+    if (value == null) {
+      return;
+    }
+
+    sb.append(name);
+
+    if (params != null) {
+      for (Param par: params) {
+        sb.append(";");
+        par.output(sb);
+      }
+    }
+
+    sb.append(":");
+    sb.append(value);
+    sb.append("\n");
+  }
+
+  /**
+   * @param indent
+   * @param sb
+   */
+  public void outputJson(String indent, StringBuilder sb) {
+    /* "email" : [
+    {"type" : ["pref"], "value" : "foo at example.com"},
+    {"value" : "bar at example.com"}
+  ]
+ */
+
+    if (value == null) {
+      return;
+    }
+
+    sb.append(indent);
+    sb.append("\"");
+    sb.append(Util.jsonName(name));
+    sb.append("\" : [\n");
+
+    String saveIndent = indent;
+    indent +="  ";
+
+    if (params != null) {
+      for (Param par: params) {
+        par.outputJson(indent, sb);
+        sb.append(",\n");
+      }
+    }
+
+    sb.append(indent);
+    sb.append("{\"value\" : ");
+    sb.append(Util.jsonEncode(value));
+    sb.append("}\n");
+
+    indent = saveIndent;
+    sb.append(indent);
+    sb.append("]\n");
+  }
+
+  public String toString() {
+    StringBuilder sb = new StringBuilder();
+
+    output(sb);
+
+    return sb.toString();
+  }
+}
\ No newline at end of file

Copied: trunk/server/src/org/bedework/carddav/vcard/Tokenizer.java (from rev 14, trunk/server/src/org/bedework/carddav/util/Tokenizer.java)
===================================================================
--- trunk/server/src/org/bedework/carddav/vcard/Tokenizer.java	                        (rev 0)
+++ trunk/server/src/org/bedework/carddav/vcard/Tokenizer.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -0,0 +1,187 @@
+package org.bedework.carddav.vcard;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StreamTokenizer;
+
+import org.apache.log4j.Logger;
+import org.bedework.carddav.server.Debug;
+
+import edu.rpi.cct.webdav.servlet.shared.WebdavException;
+
+/**
+ * @author douglm
+ *
+ */
+public class Tokenizer extends StreamTokenizer {
+  private transient Logger log;
+
+  /**
+   * @param rdr
+   */
+  public Tokenizer(Reader rdr) {
+    super(new UnfoldingReader(rdr));
+  }
+
+  /**
+   * Asserts that the next token in the stream matches the specified token.
+   *
+   * @param token expected token
+   * @throws WebdavException
+   */
+  public void assertToken(int token) throws WebdavException {
+    try {
+      if (nextToken() != token) {
+        throw new WebdavException("Expected [" + token + "], read [" +
+                                  ttype + "] at " + lineno());
+      }
+
+      if (Debug.enabled) {
+        debugMsg("[" + token + "]");
+      }
+    } catch (IOException e) {
+      throw new WebdavException(e);
+    }
+  }
+
+  /**
+   * @throws WebdavException
+   */
+  public void assertWord()  throws WebdavException {
+    assertToken(StreamTokenizer.TT_WORD);
+  }
+
+  /**
+   * Asserts that the next token in the stream matches the specified token.
+   * This method is case-sensitive.
+   *
+   * @param token
+   * @throws WebdavException
+   */
+  public void assertToken(String token) throws WebdavException {
+    assertToken(token, false);
+  }
+
+  /**
+   * Asserts that the next token in the stream matches the specified token.
+   *
+   * @param token expected token
+   * @param ignoreCase
+   * @throws WebdavException
+   */
+  public void assertToken(String token, boolean ignoreCase) throws WebdavException {
+    // ensure next token is a word token..
+    assertWord();
+
+    if (ignoreCase) {
+      if (!token.equalsIgnoreCase(sval)) {
+        throw new WebdavException("Expected [" + token + "], read [" +
+                                  sval + "] at " + lineno());
+      }
+    }
+    else if (!token.equals(sval)) {
+      throw new WebdavException( "Expected [" + token + "], read [" +
+                                sval + "] at " + lineno());
+    }
+
+    if (Debug.enabled) {
+      debugMsg("[" + token + "]");
+    }
+  }
+
+  /**
+   * Tests that the next token in the stream matches the specified token.
+   * This method is case-sensitive.
+   *
+   * @param token
+   * @return boolean
+   * @throws WebdavException
+   */
+  public boolean testToken(int token) throws WebdavException {
+    try {
+      boolean res = nextToken() == token;
+
+      if (!res) {
+        pushBack();
+        return false;
+      }
+
+      return true;
+    } catch (IOException e) {
+      throw new WebdavException(e);
+    }
+  }
+
+  /**
+   * Tests if the next token in the stream matches the specified token.
+   *
+   * @param token expected token
+   * @return int
+   * @throws WebdavException
+   */
+  public boolean testToken(String token) throws WebdavException {
+    return testToken(token, false);
+  }
+
+  /**
+   * Tests if the next token in the stream matches the specified token.
+   *
+   * @param token expected token
+   * @param ignoreCase
+   * @return boolean
+   * @throws WebdavException
+   */
+  public boolean testToken(String token, boolean ignoreCase) throws WebdavException {
+    // ensure next token is a word token..
+    if (!testToken(StreamTokenizer.TT_WORD)) {
+      return false;
+    }
+
+    if (ignoreCase) {
+      if (!token.equalsIgnoreCase(sval)) {
+        pushBack();
+        return false;
+      }
+    } else if (!token.equals(sval)) {
+      pushBack();
+      return false;
+    }
+
+    return true;
+  }
+
+  /**
+   * Absorbs extraneous newlines.
+   * @param tokeniser
+   * @throws WebdavException
+   */
+  public void skipWhitespace() throws WebdavException {
+    while (true) {
+      assertToken(StreamTokenizer.TT_EOL);
+    }
+  }
+
+  protected Logger getLogger() {
+    if (log == null) {
+      log = Logger.getLogger(this.getClass());
+    }
+
+    return log;
+  }
+
+  protected void error(Throwable t) {
+    getLogger().error(this, t);
+  }
+
+  protected void warn(String msg) {
+    getLogger().warn(msg);
+  }
+
+  protected void debugMsg(String msg) {
+    getLogger().debug(msg);
+  }
+
+  protected void logIt(String msg) {
+    getLogger().info(msg);
+  }
+}


Property changes on: trunk/server/src/org/bedework/carddav/vcard/Tokenizer.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: trunk/server/src/org/bedework/carddav/vcard/UnfoldingReader.java (from rev 14, trunk/server/src/org/bedework/carddav/util/UnfoldingReader.java)
===================================================================
--- trunk/server/src/org/bedework/carddav/vcard/UnfoldingReader.java	                        (rev 0)
+++ trunk/server/src/org/bedework/carddav/vcard/UnfoldingReader.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -0,0 +1,157 @@
+/*
+ * $Id: UnfoldingReader.java,v 1.19 2007/06/19 12:28:29 fortuna Exp $ [06-Apr-2004]
+ *
+ * Copyright (c) 2005, Ben Fortuna
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  o Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ *  o Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ *  o Neither the name of Ben Fortuna nor the names of any other contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/* Shamelessly stolen from Ben by Mike Douglass
+ */
+package org.bedework.carddav.vcard;
+
+import java.io.IOException;
+import java.io.PushbackReader;
+import java.io.Reader;
+import java.util.Arrays;
+
+import org.apache.log4j.Logger;
+
+/**
+ * A reader which performs iCalendar unfolding as it reads. Note that unfolding
+ * rules may be "relaxed" to allow unfolding of non-conformant *.ics files.
+ *
+ * By specifying the system property "ical4j.unfolding.relaxed=true" iCalendar
+ * files created with Mozilla Calendar/Sunbird may be correctly unfolded.
+ * @author Ben Fortuna
+ */
+public class UnfoldingReader extends PushbackReader {
+  private Logger log;
+
+  /**
+   * The pattern used to identify a fold in an iCalendar data stream.
+   */
+  private static final char[] DEFAULT_FOLD_PATTERN = { '\r', '\n', ' ' };
+
+  /**
+   * The pattern used to identify a fold in Mozilla Calendar/Sunbird and KOrganizer.
+   */
+  private static final char[] RELAXED_FOLD_PATTERN_1 = { '\n', ' ' };
+
+  /**
+   * The pattern used to identify a fold in Microsoft Outlook 2007.
+   */
+  private static final char[] RELAXED_FOLD_PATTERN_2 = { '\r', '\n', '\t' };
+
+  /**
+   * The pattern used to identify a fold in Microsoft Outlook 2007.
+   */
+  private static final char[] RELAXED_FOLD_PATTERN_3 = { '\n', '\t' };
+
+  private char[][] patterns;
+
+  private char[][] buffers;
+
+  private int linesUnfolded;
+
+  /**
+   * Creates a new unfolding reader instance. Relaxed unfolding flag is read
+   * from system property.
+   *
+   * @param in the reader to unfold from
+   */
+  public UnfoldingReader(final Reader in) {
+    this(in, CompatibilityHints
+         .isHintEnabled(CompatibilityHints.KEY_RELAXED_UNFOLDING));
+  }
+
+  /**
+   * Creates a new unfolding reader instance.
+   * @param in a reader to read from
+   * @param relaxed specifies whether unfolding is relaxed
+   */
+  public UnfoldingReader(final Reader in, final boolean relaxed) {
+    super(in, DEFAULT_FOLD_PATTERN.length);
+    if (relaxed) {
+      patterns = new char[4][];
+      patterns[0] = DEFAULT_FOLD_PATTERN;
+      patterns[1] = RELAXED_FOLD_PATTERN_1;
+      patterns[2] = RELAXED_FOLD_PATTERN_2;
+      patterns[3] = RELAXED_FOLD_PATTERN_3;
+    }
+    else {
+      patterns = new char[1][];
+      patterns[0] = DEFAULT_FOLD_PATTERN;
+    }
+    buffers = new char[patterns.length][];
+    for (int i = 0; i < patterns.length; i++) {
+      buffers[i] = new char[patterns[i].length];
+    }
+  }
+
+  /**
+   * @return number of lines unfolded so far while reading
+   */
+  public final int getLinesUnfolded() {
+    return linesUnfolded;
+  }
+
+  /**
+   * @see java.io.PushbackReader#read()
+   */
+  public final int read() throws IOException {
+    boolean didUnfold;
+
+    // need to loop since one line fold might be directly followed by another
+    do {
+      didUnfold = false;
+
+      for (int i = 0; i < buffers.length; i++) {
+        int read = super.read(buffers[i]);
+        if (read > 0) {
+          if (!Arrays.equals(patterns[i], buffers[i])) {
+            unread(buffers[i], 0, read);
+          }
+          else {
+            if (log.isDebugEnabled()) {
+              log.debug("Unfolding...");
+            }
+            linesUnfolded++;
+            didUnfold = true;
+          }
+        }
+        else {
+          return read;
+        }
+      }
+    }
+    while (didUnfold);
+
+    return super.read();
+  }
+}


Property changes on: trunk/server/src/org/bedework/carddav/vcard/UnfoldingReader.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Copied: trunk/server/src/org/bedework/carddav/vcard/Vcard.java (from rev 15, trunk/server/src/org/bedework/carddav/server/Vcard.java)
===================================================================
--- trunk/server/src/org/bedework/carddav/vcard/Vcard.java	                        (rev 0)
+++ trunk/server/src/org/bedework/carddav/vcard/Vcard.java	2008-11-26 18:19:32 UTC (rev 16)
@@ -0,0 +1,340 @@
+/* **********************************************************************
+    Copyright 2006 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+    Redistribution and use of this distribution in source and binary forms,
+    with or without modification, are permitted provided that:
+       The above copyright notice and this permission notice appear in all
+        copies and supporting documentation;
+
+        The name, identifiers, and trademarks of Rensselaer Polytechnic
+        Institute are not used in advertising or publicity without the
+        express prior written permission of Rensselaer Polytechnic Institute;
+
+    DISCLAIMER: The software is distributed" AS IS" without any express or
+    implied warranty, including but not limited to, any implied warranties
+    of merchantability or fitness for a particular purpose or any warrant)'
+    of non-infringement of any current or pending patent rights. The authors
+    of the software make no representations about the suitability of this
+    software for any particular purpose. The entire risk as to the quality
+    and performance of the software is with the user. Should the software
+    prove defective, the user assumes the cost of all necessary servicing,
+    repair or correction. In particular, neither Rensselaer Polytechnic
+    Institute, nor the authors of the software are liable for any indirect,
+    special, consequential, or incidental damages related to the software,
+    to the maximum extent the law permits.
+*/
+
+package org.bedework.carddav.vcard;
+
+import org.bedework.carddav.server.CarddavCollection;
+import org.bedework.carddav.util.Uid;
+
+import java.io.Reader;
+import java.io.StreamTokenizer;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import edu.rpi.cct.webdav.servlet.shared.WebdavException;
+import edu.rpi.cmt.access.AccessPrincipal;
+
+/** Temp def of vcard to get us going
+ *
+ * @author douglm
+ *
+ */
+public class Vcard {
+
+  private AccessPrincipal owner;
+
+  private String name;
+
+  private CarddavCollection parent;
+
+  private String created;
+
+  private Collection<Property> props;
+
+  private String strForm;
+
+  private String jsonStrForm;
+
+  private String prevLastmod;
+
+  /**
+   * @param val
+   */
+  public void setOwner(AccessPrincipal val) {
+    owner = val;
+  }
+
+  /**
+   * @return AccessPrincipal
+   */
+  public AccessPrincipal getOwner() {
+    return owner;
+  }
+
+  /** Set the name
+  *
+  * @param val    String name
+  */
+ public void setName(String val) {
+   name = val;
+ }
+
+ /** Get the name
+  *
+  * @return String   name
+  */
+ public String getName() {
+   return name;
+ }
+
+  /**
+   * @param val
+   */
+  public void setCreated(String val) {
+    created = val;
+  }
+
+  /**
+   * @return String created
+   */
+  public String getCreated() {
+    return created;
+  }
+
+  /**
+   * @param val
+   */
+  public void setLastmod(String val) {
+    Property rev = findProperty("REV");
+
+    if (rev == null) {
+      rev = new Property("REV", null);
+      addProperty(rev);
+    }
+
+    rev.value = val;
+  }
+
+  /**
+   * @return String
+   */
+  public String getLastmod() {
+    Property rev = findProperty("REV");
+
+    if (rev == null) {
+      return null;
+    }
+
+    return rev.value;
+  }
+
+  /** Lastmod before any changes were made
+   *
+   * @return String
+   */
+  public String getPrevLastmod() {
+    return prevLastmod;
+  }
+
+  /**
+   * @param val
+   */
+  public void setUid(String val) {
+    Property uid = findProperty("UID");
+
+    if (uid == null) {
+      uid = new Property("UID", null);
+      addProperty(uid);
+    }
+
+    uid.value = val;
+  }
+
+  /**
+   * @return String
+   */
+  public String getUid() {
+    Property uid = findProperty("UID");
+
+    if (uid == null) {
+      setUid(Uid.getUid());
+      uid = findProperty("UID");
+    }
+
+    return uid.value;
+  }
+
+  /**
+   * @param val
+   */
+  public void setParent(CarddavCollection val) {
+    parent = val;
+  }
+
+  /**
+   * @return parent.
+   */
+  public CarddavCollection getParent() {
+    return parent;
+  }
+
+  /**
+   * @param val
+   */
+  public void addProperty(Property val) {
+    if (props == null) {
+      props = new ArrayList<Property>();
+    }
+
+    props.add(val);
+  }
+
+  /**
+   * @param name
+   * @return property or null
+   */
+  public Property findProperty(String name) {
+    if (props == null) {
+      return null;
+    }
+
+    for (Property p: props) {
+      if (name.equals(p.name)) {
+        return p;
+      }
+    }
+
+    return null;
+  }
+
+  private static final int WORD_CHAR_START = 32;
+
+  private static final int WORD_CHAR_END = 255;
+
+  private static final int WHITESPACE_CHAR_START = 0;
+
+  private static final int WHITESPACE_CHAR_END = 20;
+
+  /**
+   * @param rdr
+   * @return Vcard
+   * @throws WebdavException
+   */
+  public Vcard parse(Reader rdr) throws WebdavException {
+    Tokenizer tokeniser = new Tokenizer(rdr);
+
+    try {
+      tokeniser.resetSyntax();
+      tokeniser.wordChars(WORD_CHAR_START, WORD_CHAR_END);
+      tokeniser.whitespaceChars(WHITESPACE_CHAR_START,
+                                WHITESPACE_CHAR_END);
+      tokeniser.ordinaryChar(':');
+      tokeniser.ordinaryChar(';');
+      tokeniser.ordinaryChar('=');
+      tokeniser.ordinaryChar('\t');
+      tokeniser.eolIsSignificant(true);
+      tokeniser.whitespaceChars(0, 0);
+      tokeniser.quoteChar('"');
+
+      // BEGIN:VCALENDAR
+      tokeniser.assertToken("BEGIN");
+
+      tokeniser.assertToken(':');
+
+      tokeniser.assertToken("VCARD", true);
+
+      tokeniser.assertToken(StreamTokenizer.TT_EOL);
+
+      while (!tokeniser.testToken("END")) {
+        addProperty(new Property().parse(tokeniser));
+        tokeniser.skipWhitespace();
+      }
+
+      tokeniser.assertToken(':');
+
+      tokeniser.assertToken("VCARD", true);
+      tokeniser.skipWhitespace();
+
+      prevLastmod = getLastmod();
+
+      return this;
+    } catch (WebdavException wde) {
+      throw wde;
+    } catch (Exception e) {
+      throw new WebdavException(e);
+    }
+  }
+
+  /**
+   * @return String
+   */
+  public String output() {
+    if (strForm != null) {
+      return strForm;
+    }
+
+    StringBuilder sb = new StringBuilder();
+
+    sb.append("BEGIN:VCARD\n");
+    sb.append("VERSION:4.0\n");
+
+    if (props != null) {
+      for (Property p: props) {
+        if ("VERSION".equals(p.name)) {
+          continue;
+        }
+
+        p.output(sb);
+      }
+    }
+
+    sb.append("END:VCARD\n\n");
+
+    strForm = sb.toString();
+
+    return strForm;
+  }
+
+  /**
+   * @param indent
+   * @return String
+   */
+  public String outputJson(String indent) {
+    if (jsonStrForm != null) {
+      return jsonStrForm;
+    }
+
+    StringBuilder sb = new StringBuilder();
+
+    sb.append(indent);
+    sb.append("{\n");
+
+    indent += "";
+
+    new Property("VERSION", "4.0").outputJson(indent, sb);
+
+    if (props != null) {
+      for (Property p: props) {
+        if ("VERSION".equals(p.name)) {
+          continue;
+        }
+
+        p.outputJson(indent, sb);
+      }
+    }
+
+    sb.append(indent);
+    sb.append("}");
+
+    jsonStrForm = sb.toString();
+
+    return jsonStrForm;
+  }
+
+  public String toString() {
+    return output();
+  }
+}


Property changes on: trunk/server/src/org/bedework/carddav/vcard/Vcard.java
___________________________________________________________________
Name: svn:mergeinfo
   + 



More information about the Bedework-commit mailing list