View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.springframework.extensions.webscripts;
20  
21  import java.io.IOException;
22  import java.io.OutputStream;
23  import java.io.Writer;
24  
25  
26  /**
27   * Web Script Response
28   * 
29   * @author davidc
30   */
31  public interface WebScriptResponse
32  {
33      // API Formats
34      public static final String HTML_FORMAT = "html";
35      public static final String ATOM_FORMAT = "atom";
36      public static final String RSS_FORMAT = "rss";
37      public static final String XML_FORMAT = "xml";
38      public static final String JSON_FORMAT = "json";
39      public static final String OPENSEARCH_DESCRIPTION_FORMAT = "opensearchdescription";
40  
41      // Headers
42      public static final String HEADER_LOCATION = "Location";
43      
44      
45      /**
46       * Sets the Response Status
47       * 
48       * @param status
49       */
50      public void setStatus(int status);
51      
52      /**
53       * Set a response header with the given name and value.  If the header has
54       * already been set, the new value overwrites the previous one.
55       * 
56       * @param name  header name
57       * @param value  header value
58       */
59      public void setHeader(String name, String value);
60  
61      /**
62       * Adds a response header with the given name and value.  This method
63       * allows a response header to have multiple values.
64       * 
65       * @param name  header name
66       * @param value  header value
67       */
68      public void addHeader(String name, String value);
69      
70      /**
71       * Sets the Content Type
72       * 
73       * @param contentType
74       */
75      public void setContentType(String contentType);
76      
77      /**
78       * Sets the Content Encoding
79       * 
80       * @param contentEncoding
81       */
82      public void setContentEncoding(String contentEncoding);
83      
84      /**
85       * Sets the Cache control
86       * 
87       * @param  cache  cache control
88       */
89      public void setCache(Cache cache);
90      
91      /**
92       * Gets the Writer
93       * 
94       * @return writer
95       * @throws IOException
96       */
97      public Writer getWriter() throws IOException;
98      
99      /**
100      * Gets the Output Stream
101      * 
102      * @return output stream
103      * @throws IOException
104      */
105     public OutputStream getOutputStream() throws IOException;
106     
107     /**
108      * Clears response buffer
109      */
110     public void reset();
111         
112     /**
113      * Encode a script URL
114      * 
115      * Note: Some Web Script Runtime environments (e.g. JSR-168, JSF) require urls to be re-written.
116      * 
117      * @param url  to encode
118      * @return encoded url
119      */
120     public String encodeScriptUrl(String url);
121     
122     /**
123      * Return a client side javascript function to build urls to this service
124      *  
125      * @param name      Generated function name
126      *  
127      * @return javascript function definition
128      */
129     public String getEncodeScriptUrlFunction(String name);
130         
131     /**
132      * Gets the initiating runtime
133      * 
134      * @return  runtime that constructed this response
135      */
136     public Runtime getRuntime();
137         
138 }