// Path: weave/client/src/main/java/org/emergent/android/weave/client/CollectionNode.java
// public enum CollectionNode {
// 
//   STORAGE_CLIENTS("clients"),
//   STORAGE_BOOKMARKS("bookmarks"),
//   STORAGE_PASSWORDS("passwords"),
//   ;
// 
//   public final String engineName;
//   public final String nodePath;
// 
//   CollectionNode(String engineName) {
//     this.engineName = engineName;
//     this.nodePath = "/storage/" + this.engineName;
//   }
// }
// 
// Path: weave/client/src/main/java/org/emergent/android/weave/client/WeaveBasicObject.java
// public class WeaveBasicObject {
// 
//   private URI m_uri = null;
//   private final URI m_queryUri;
//   private final JSONObject m_nodeObj;
// 
//   public WeaveBasicObject(URI queryUri, JSONObject nodeObj) {
//     m_queryUri = queryUri;
//     m_nodeObj = nodeObj;
//   }
// 
//   public String getId() throws JSONException {
//     return m_nodeObj.getString("id");
//   }
// 
//   public String getSortIndex() throws JSONException {
//     return m_nodeObj.getString("sortindex");
//   }
// 
//   public String getModified() throws JSONException {
//     return m_nodeObj.getString("modified");
//   }
// 
//   public Date getModifiedDate() throws JSONException {
//     return WeaveUtil.toModifiedTimeDate(getModified());
//   }
// 
//   public URI getUri() throws JSONException {
//     if (m_uri == null) {
//       try {
//         String baseUriStr = m_queryUri.toASCIIString();
//         String queryPart = m_queryUri.getRawQuery();
//         if (queryPart != null)
//           baseUriStr = baseUriStr.substring(0, baseUriStr.indexOf(queryPart) - 1);
//         if (!baseUriStr.endsWith("/"))
//           baseUriStr += "/";
//         String nodeUriStr = baseUriStr + new URI(null,null,getId(), null).toASCIIString();
//         m_uri = new URI(nodeUriStr);
//       } catch (URISyntaxException e) {
//         throw new JSONException(e.getMessage());
//       }
//     }
//     return m_uri;
//   }
// 
//   public JSONObject getPayload() throws JSONException {
//     return new JSONObject(m_nodeObj.getString("payload"));
//   }
// 
//   public JSONObject getEncryptedPayload(BulkKeyTool bulkTool) throws JSONException, IOException, WeaveException {
//     return getEncryptedPayload(bulkTool.getBulkKeyCouplet());
//   }
// 
//   private JSONObject getEncryptedPayload(BulkKeyCouplet bulkKeyPair) throws JSONException, IOException, WeaveException {
//     try {
//       WeaveEncryptedObject weo = new WeaveEncryptedObject(getPayload());
//       return weo.decryptObject(bulkKeyPair);
//     } catch (GeneralSecurityException e) {
//       throw new WeaveException(e);
//     }
//   }
// 
// 
//   public JSONObject getEncryptedPayload(Key bulkKey, Key hmacKey)
//       throws JSONException, IOException, GeneralSecurityException, WeaveException {
//     WeaveEncryptedObject weo = new WeaveEncryptedObject(getPayload());
//     return weo.decryptObject(bulkKey, hmacKey);
//   }
// 
//   public JSONObject toJSONObject() {
//     return m_nodeObj;
//   }
// 
//   public String toJSONObjectString() throws JSONException {
//     return toJSONObject().toString(0);
//   }
// 
//   public static class WeaveEncryptedObject {
// 
//     private final JSONObject m_nodeObj;
// 
//     public WeaveEncryptedObject(JSONObject nodeObj) {
//       m_nodeObj = nodeObj;
//     }
// 
//     public String getHmac() throws JSONException {
//       return m_nodeObj.getString("hmac");
//     }
// 
//     public String getCiphertext() throws JSONException {
//       return m_nodeObj.getString("ciphertext");
//     }
// 
//     public String getIv() throws JSONException {
//       return m_nodeObj.getString("IV");
//     }
// 
//     public JSONObject decryptObject(BulkKeyCouplet keyPair) throws GeneralSecurityException, JSONException {
//       return decryptObject(keyPair.cipherKey, keyPair.hmacKey);
//     }
// 
//     public JSONObject decryptObject(Key key, Key hmacKey) throws GeneralSecurityException, JSONException {
//       String plaintext = WeaveCryptoUtil.getInstance().decrypt(key, hmacKey, getCiphertext(), getIv(), getHmac());
//       return new JSONObject(plaintext);
//     }
//   }
// }


import org.emergent.android.weave.client.CollectionNode;
import org.emergent.android.weave.client.WeaveBasicObject;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.provider.BaseColumns;
import java.util.Date;
import java.util.List;
package org.emergent.android.weave.persistence;




/**
 * @author Patrick Woodworth
 */
public class Weaves {

  public static void setBasicContentValues(ContentValues values, Record info) throws JSONException {
    boolean isDeleted = info.isDeleted();
    putColumnValue(values, Columns.UUID, info.getId());
    putColumnValue(values, Columns.IS_DELETED, isDeleted);
    putColumnValue(values, Columns.LAST_MODIFIED, info.getModifiedInSeconds());
  }

  public static void putColumnValue(ContentValues values, String colName, String value) {
    values.put(colName, value);
  }

  public static void putColumnValue(ContentValues values, String colName, long value) {
    values.put(colName, value);
  }

  public static void putColumnValue(ContentValues values, String colName, boolean value) {
    values.put(colName, value);
  }

  public static class Columns implements BaseColumns {

    // BaseColumn contains _id.

    public static final String UUID = "uuid";
    public static final String SORT_INDEX = "sortIndex";
    public static final String LAST_MODIFIED = "lastModified";
    public static final String IS_DELETED = "isDeleted";
  }

  public static abstract class Updater {

    private final Uri m_authority;
// Path: weave/client/src/main/java/org/emergent/android/weave/client/CollectionNode.java
// public enum CollectionNode {
// 
//   STORAGE_CLIENTS("clients"),
//   STORAGE_BOOKMARKS("bookmarks"),
//   STORAGE_PASSWORDS("passwords"),
//   ;
// 
//   public final String engineName;
//   public final String nodePath;
// 
//   CollectionNode(String engineName) {
//     this.engineName = engineName;
//     this.nodePath = "/storage/" + this.engineName;
//   }
// }
// 
// Path: weave/client/src/main/java/org/emergent/android/weave/client/WeaveBasicObject.java
// public class WeaveBasicObject {
// 
//   private URI m_uri = null;
//   private final URI m_queryUri;
//   private final JSONObject m_nodeObj;
// 
//   public WeaveBasicObject(URI queryUri, JSONObject nodeObj) {
//     m_queryUri = queryUri;
//     m_nodeObj = nodeObj;
//   }
// 
//   public String getId() throws JSONException {
//     return m_nodeObj.getString("id");
//   }
// 
//   public String getSortIndex() throws JSONException {
//     return m_nodeObj.getString("sortindex");
//   }
// 
//   public String getModified() throws JSONException {
//     return m_nodeObj.getString("modified");
//   }
// 
//   public Date getModifiedDate() throws JSONException {
//     return WeaveUtil.toModifiedTimeDate(getModified());
//   }
// 
//   public URI getUri() throws JSONException {
//     if (m_uri == null) {
//       try {
//         String baseUriStr = m_queryUri.toASCIIString();
//         String queryPart = m_queryUri.getRawQuery();
//         if (queryPart != null)
//           baseUriStr = baseUriStr.substring(0, baseUriStr.indexOf(queryPart) - 1);
//         if (!baseUriStr.endsWith("/"))
//           baseUriStr += "/";
//         String nodeUriStr = baseUriStr + new URI(null,null,getId(), null).toASCIIString();
//         m_uri = new URI(nodeUriStr);
//       } catch (URISyntaxException e) {
//         throw new JSONException(e.getMessage());
//       }
//     }
//     return m_uri;
//   }
// 
//   public JSONObject getPayload() throws JSONException {
//     return new JSONObject(m_nodeObj.getString("payload"));
//   }
// 
//   public JSONObject getEncryptedPayload(BulkKeyTool bulkTool) throws JSONException, IOException, WeaveException {
//     return getEncryptedPayload(bulkTool.getBulkKeyCouplet());
//   }
// 
//   private JSONObject getEncryptedPayload(BulkKeyCouplet bulkKeyPair) throws JSONException, IOException, WeaveException {
//     try {
//       WeaveEncryptedObject weo = new WeaveEncryptedObject(getPayload());
//       return weo.decryptObject(bulkKeyPair);
//     } catch (GeneralSecurityException e) {
//       throw new WeaveException(e);
//     }
//   }
// 
// 
//   public JSONObject getEncryptedPayload(Key bulkKey, Key hmacKey)
//       throws JSONException, IOException, GeneralSecurityException, WeaveException {
//     WeaveEncryptedObject weo = new WeaveEncryptedObject(getPayload());
//     return weo.decryptObject(bulkKey, hmacKey);
//   }
// 
//   public JSONObject toJSONObject() {
//     return m_nodeObj;
//   }
// 
//   public String toJSONObjectString() throws JSONException {
//     return toJSONObject().toString(0);
//   }
// 
//   public static class WeaveEncryptedObject {
// 
//     private final JSONObject m_nodeObj;
// 
//     public WeaveEncryptedObject(JSONObject nodeObj) {
//       m_nodeObj = nodeObj;
//     }
// 
//     public String getHmac() throws JSONException {
//       return m_nodeObj.getString("hmac");
//     }
// 
//     public String getCiphertext() throws JSONException {
//       return m_nodeObj.getString("ciphertext");
//     }
// 
//     public String getIv() throws JSONException {
//       return m_nodeObj.getString("IV");
//     }
// 
//     public JSONObject decryptObject(BulkKeyCouplet keyPair) throws GeneralSecurityException, JSONException {
//       return decryptObject(keyPair.cipherKey, keyPair.hmacKey);
//     }
// 
//     public JSONObject decryptObject(Key key, Key hmacKey) throws GeneralSecurityException, JSONException {
//       String plaintext = WeaveCryptoUtil.getInstance().decrypt(key, hmacKey, getCiphertext(), getIv(), getHmac());
//       return new JSONObject(plaintext);
//     }
//   }
// }


// Path: src/org/emergent/android/weave/persistence/Weaves.java
import org.emergent.android.weave.client.CollectionNode;
import org.emergent.android.weave.client.WeaveBasicObject;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.provider.BaseColumns;
import java.util.Date;
import java.util.List;

package org.emergent.android.weave.persistence;




/**
 * @author Patrick Woodworth
 */
public class Weaves {

  public static void setBasicContentValues(ContentValues values, Record info) throws JSONException {
    boolean isDeleted = info.isDeleted();
    putColumnValue(values, Columns.UUID, info.getId());
    putColumnValue(values, Columns.IS_DELETED, isDeleted);
    putColumnValue(values, Columns.LAST_MODIFIED, info.getModifiedInSeconds());
  }

  public static void putColumnValue(ContentValues values, String colName, String value) {
    values.put(colName, value);
  }

  public static void putColumnValue(ContentValues values, String colName, long value) {
    values.put(colName, value);
  }

  public static void putColumnValue(ContentValues values, String colName, boolean value) {
    values.put(colName, value);
  }

  public static class Columns implements BaseColumns {

    // BaseColumn contains _id.

    public static final String UUID = "uuid";
    public static final String SORT_INDEX = "sortIndex";
    public static final String LAST_MODIFIED = "lastModified";
    public static final String IS_DELETED = "isDeleted";
  }

  public static abstract class Updater {

    private final Uri m_authority;
    private final CollectionNode m_collectionNode;