View Javadoc

1   /*
2    * $Id: SerializationParams.java 799110 2009-07-29 22:44:26Z musachy $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.struts2.json;
22  
23  import javax.servlet.http.HttpServletResponse;
24  
25  import org.apache.commons.lang.xwork.StringUtils;
26  
27  public class SerializationParams {
28      private static final String DEFAULT_CONTENT_TYPE = "application/json";
29  
30      private final HttpServletResponse response;
31      private final String encoding;
32      private final boolean wrapWithComments;
33      private final String serializedJSON;
34      private final boolean smd;
35      private final boolean gzip;
36      private final boolean noCache;
37      private final int statusCode;
38      private final int errorCode;
39      private final boolean prefix;
40      private String contentType = DEFAULT_CONTENT_TYPE;
41      private String wrapPrefix;
42      private String wrapSuffix;
43  
44      public SerializationParams(HttpServletResponse response, String encoding, boolean wrapWithComments,
45              String serializedJSON, boolean smd, boolean gzip, boolean noCache, int statusCode, int errorCode,
46              boolean prefix, String contentType, String wrapPrefix, String wrapSuffix) {
47          this.response = response;
48          this.encoding = encoding;
49          this.wrapWithComments = wrapWithComments;
50          this.serializedJSON = serializedJSON;
51          this.smd = smd;
52          this.gzip = gzip;
53          this.noCache = noCache;
54          this.statusCode = statusCode;
55          this.errorCode = errorCode;
56          this.prefix = prefix;
57          this.contentType = StringUtils.defaultString(contentType, DEFAULT_CONTENT_TYPE);
58          this.wrapPrefix = wrapPrefix;
59          this.wrapSuffix = wrapSuffix;
60      }
61  
62      public SerializationParams(HttpServletResponse response, String defaultEncoding,
63              boolean wrapWithComments, String json, boolean b, boolean b1, boolean noCache, int i, int i1,
64              boolean prefix, String contentType) {
65          this(response, defaultEncoding, wrapWithComments, json, b, b1, noCache, i, i1, prefix, contentType,
66                  null, null);
67      }
68  
69      public String getWrapSuffix() {
70          return wrapSuffix;
71      }
72  
73      public String getWrapPrefix() {
74          return wrapPrefix;
75      }
76  
77      public HttpServletResponse getResponse() {
78          return response;
79      }
80  
81      public String getEncoding() {
82          return encoding;
83      }
84  
85      public boolean isWrapWithComments() {
86          return wrapWithComments;
87      }
88  
89      public String getSerializedJSON() {
90          return serializedJSON;
91      }
92  
93      public boolean isSmd() {
94          return smd;
95      }
96  
97      public boolean isGzip() {
98          return gzip;
99      }
100 
101     public boolean isNoCache() {
102         return noCache;
103     }
104 
105     public int getStatusCode() {
106         return statusCode;
107     }
108 
109     public int getErrorCode() {
110         return errorCode;
111     }
112 
113     public boolean isPrefix() {
114         return prefix;
115     }
116 
117     public String getContentType() {
118         return contentType;
119     }
120 }