Author: mir
Date: Mon Dec 14 16:55:55 2009
New Revision: 890403
URL: http://svn.apache.org/viewvc?rev=890403&view=rev
Log:
CLEREZZA-26: implemented jax-rs method to POST infoDiscoBits in platform.content
Added:
incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentManager.java
Added:
incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentManager.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentManager.java?rev=890403&view=auto
==============================================================================
---
incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentManager.java
(added)
+++
incubator/clerezza/issues/CLEREZZA-26/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/ContentManager.java
Mon Dec 14 16:55:55 2009
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. 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.
+ */
+package org.apache.clerezza.platform.content;
+
+
+import java.net.URI;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+
+import javax.ws.rs.core.Response;
+import org.apache.clerezza.jaxrs.utils.form.FormFile;
+import org.apache.clerezza.jaxrs.utils.form.MultiPartBody;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+
+/**
+ * This Jax-rs root resource provides a method to post content to the content
+ * graph
+ *
+ * @author mir
+ */
+...@component
+...@service(Object.class)
+...@property(name="javax.ws.rs", boolValue=true)
+...@path("content")
+public class ContentManager {
+
+ @Reference
+ private DiscobitsHandler handler;
+
+ /**
+ * Uploads a content into the content graph.
+ * This JAX-RS method is available under the path "content". It requires
+ * two query parameters: "content", which is the content to be uploaded
into
+ * the content graph and "uri" which is the uri will be the uri of the
content
+ * in the graph.
+ *
+ * @param form
+ * @return Returns a 201 (Created) response, if the info bit was
successfully
+ * uploaded. Returns 400 (Bad Request), if required query parameters
are missing.
+ */
+ @POST
+ @Consumes("multipart/form")
+ public Response postContent(MultiPartBody form) {
+ FormFile formFile =
form.getFormFileParameterValues("content")[0];
+ String uri = form.getTextParameterValues("uri")[0];
+ byte[] content = formFile.getContent();
+ if (content == null || uri == null) {
+ return Response.status(400).build();
+ }
+ handler.put(new UriRef(uri), formFile.getMediaType(), content);
+ return Response.created(URI.create(uri)).build();
+ }
+
+}