cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thors...@apache.org
Subject svn commit: r1147833 - /cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/TextResponse.java
Date Mon, 18 Jul 2011 12:35:17 GMT
Author: thorsten
Date: Mon Jul 18 12:35:17 2011
New Revision: 1147833

URL: http://svn.apache.org/viewvc?rev=1147833&view=rev
Log:
Adding simple Text response that can be configured for different output content types

Added:
    cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/TextResponse.java
  (with props)

Added: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/TextResponse.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/TextResponse.java?rev=1147833&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/TextResponse.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/TextResponse.java
Mon Jul 18 12:35:17 2011
@@ -0,0 +1,66 @@
+/*
+ * 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.cocoon.rest.controller.response;
+
+import java.io.OutputStream;
+import java.util.Map;
+
+import org.apache.cocoon.rest.controller.response.RestResponse;
+import org.apache.cocoon.rest.controller.response.RestResponseMetaData;
+import org.apache.commons.io.IOUtils;
+
+/**
+ * Simple wrapper to to write string data response to different content types.
+ * e.g. new TextResponse(dataJson.toString(), "application/json") or 
+ * return new TextResponse(test, "text/plain")
+ */
+public class TextResponse implements RestResponse {
+
+    private String data, contentType;
+    private int statusCode = 200;
+
+    public TextResponse(String data, String contentType) {
+        this.data = data;
+        this.contentType = contentType;
+    }
+
+    public TextResponse(String data, String contentType, int statusCode) {
+        this.data = data;
+        this.contentType = contentType;
+        this.statusCode = statusCode;
+    }
+    
+    public RestResponseMetaData setup(Map<String, Object> inputParameters) throws Exception
{
+        RestResponseMetaData restResponseMetaData = new RestResponseMetaData();
+        restResponseMetaData.setStatusCode(statusCode);
+        restResponseMetaData.setContentType(contentType);
+        return restResponseMetaData;
+    }
+    
+    public void execute(OutputStream outputStream) throws Exception {
+     // write the data to output
+        IOUtils.write(data, outputStream);
+    }
+
+    public int getStatusCode() {
+        return statusCode;
+    }
+
+    public void setStatusCode(int statusCode) {
+        this.statusCode = statusCode;
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/TextResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message