Permalink
Browse files

added methods for putting and getting attachments

  • Loading branch information...
theaspect authored and mbreese committed Feb 21, 2010
1 parent 1039eeb commit 254e545d0c5bb94b3bc860bbd7db0a75ffe0da15
@@ -1,31 +1,31 @@
-/*
- Copyright 2007 Fourspaces Consulting, LLC
-
- Licensed 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.
-*/
-
-package com.fourspaces.couchdb;
-
-/**
- * Creates an AdHoc view... this basically just creates a new View with a name
- * of "_temp_view" and a defined function.
- *
- * @author mbreese
- *
- */
-public class AdHocView extends View {
- public AdHocView(String function) {
- super("_temp_view");
- this.function=function;
- }
-}
+/*
+ Copyright 2007 Fourspaces Consulting, LLC
+
+ Licensed 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.
+*/
+
+package com.fourspaces.couchdb;
+
+/**
+ * Creates an AdHoc view... this basically just creates a new View with a name
+ * of "_temp_view" and a defined function.
+ *
+ * @author mbreese
+ *
+ */
+public class AdHocView extends View {
+ public AdHocView(String function) {
+ super("_temp_view");
+ this.function=function;
+ }
+}
@@ -53,7 +53,6 @@
private Header[] headers;
private int statusCode;
private String methodName;
-
boolean ok = false;
private String error_id;
@@ -72,7 +71,7 @@
HttpEntity entity = response.getEntity();
body = EntityUtils.toString(entity);
-
+
path = req.getURI().getPath();
statusCode = response.getStatusLine().getStatusCode();
@@ -186,4 +185,8 @@ public String getHeader(String key) {
}
return null;
}
+
+ public String getBody() {
+ return body;
+ }
}
@@ -100,6 +100,19 @@ public ViewResults getAllDocuments() {
return view(new View("_all_docs"), false);
}
+ /**
+ * Gets all design documents
+ *
+ * @return ViewResults - all design docs
+ */
+ public ViewResults getAllDesignDocuments() {
+ View v = new View("_all_docs");
+ v.startKey = "%22_design%2F%22";
+ v.endKey = "%22_design0%22";
+ v.includeDocs = Boolean.TRUE;
+ return view(v, false);
+ }
+
/**
* Runs the standard "_all_docs" view on this database, with count
*
@@ -381,4 +394,30 @@ public boolean deleteDocument(Document d) throws IOException {
}
}
+
+ /**
+ * Gets attachment
+ *
+ * @param id
+ * @param attachment attachment body
+ * @return attachment body
+ */
+ public String getAttachment(String id, String attachment) throws IOException {
+ CouchResponse resp = session.get(name + "/" + urlEncodePath(id) + "/" + attachment);
+ return resp.getBody();
+ }
+
+ /**
+ * Puts attachment to the doc
+ *
+ * @param id
+ * @param fname attachment name
+ * @param ctype content type
+ * @param attachment attachment body
+ * @return was the delete successful?
+ */
+ public String putAttachment(String id, String fname, String ctype, String attachment) throws IOException {
+ CouchResponse resp = session.put(name + "/" + urlEncodePath(id) + "/" + fname, ctype, attachment);
+ return resp.getBody();
+ }
}
Oops, something went wrong.

0 comments on commit 254e545

Please sign in to comment.