4343
4444/**
4545 * Takes a data table and returns a json string.
46- *
46+ *
47+ * The renderer renders a response which primarily contains the serializing of a data table.
48+ * The response type can be either json or jsonp (a json format wrapped inside a callback method).
49+ * The main difference regarding data table serialization between the two types, is the way dates
50+ * are serialized. Dates have no standard representation in json thus they are rendered according
51+ * to the future use of the response. When the response type is jsonp, the data table is likely to
52+ * be evaluated with standard browser 'eval' and therefore date represented by Date constructor
53+ * will be transformed into javaScript dates (as expected), e.g new Date(2011,1,1).
54+ * When the response type is json, Date constructors can not be used (not defined in the json
55+ * standard) and so custom date strings are used instead. In this case, custom parsing of the string
56+ * is required to construct dates objects from their respective strings, e.g "Date(2011,1,1)".
57+ *
4758 * @author Nimrod T.
4859 */
4960public class JsonRenderer {
@@ -92,11 +103,37 @@ private static String getFaultString(ReasonType reasonType, String description)
92103 }
93104
94105 /**
106+ * @deprecated As of version 1.1.1, isJsonp is removed and instead is inferred from dsParams.
107+ * Please use:
108+ * renderJsonResponse(DataSourceParameters dsParams, ResponseStatus responseStatus,
109+ * DataTable data)
110+ *
95111 * Returns the json response for the given data table.
96112 *
97113 * @param dsParams The datasource parameters.
98114 * @param responseStatus The response status.
99115 * @param data The data table.
116+ * @param True if response should be rendered as jsonp, otherwise False.
117+ *
118+ * @return The json response for the given data table and parameters.
119+ */
120+ @ Deprecated public static CharSequence renderJsonResponse (
121+ DataSourceParameters dsParams ,
122+ ResponseStatus responseStatus ,
123+ DataTable data ,
124+ boolean isJsonp ) {
125+ dsParams .setOutputType (OutputType .JSONP );
126+ return renderJsonResponse (dsParams , responseStatus , data );
127+ }
128+
129+ /**
130+ * Returns the json response for the given data table.
131+ *
132+ * @param dsParams The datasource parameters. If the OutputType parameter is set to
133+ * JSONP the response will be rendered as JSONP. Otherwise a plain JSON string will
134+ * be returned.
135+ * @param responseStatus The response status.
136+ * @param data The data table.
100137 *
101138 * @return The json response for the given data table and parameters.
102139 */
@@ -166,6 +203,25 @@ public static CharSequence renderJsonResponse(
166203 return sb .toString ();
167204 }
168205
206+ /**
207+ * @deprecated As of version 1.1.1, renderDateAsDateConstructor parameter added. Please use:
208+ * renderDataTable(DataTable dataTable, boolean includeValues, boolean includeFormatting,
209+ * boolean renderDateAsDateConstructor)
210+ *
211+ * Generates a JSON representation of the data table object.
212+ *
213+ * @param includeValues False if the json should contain just meta-data and column descriptions
214+ * but without the data rows.
215+ * @param includeFormatting False if formatting information should be omitted from the
216+ * generated json.
217+ *
218+ * @return The char sequence with the Json string.
219+ */
220+ @ Deprecated public static CharSequence renderDataTable (DataTable dataTable , boolean includeValues ,
221+ boolean includeFormatting ) {
222+ return renderDataTable (dataTable , includeValues , includeFormatting , true );
223+ }
224+
169225 /**
170226 * Generates a JSON representation of the data table object.
171227 *
@@ -179,7 +235,7 @@ public static CharSequence renderJsonResponse(
179235 * False if it should should be rendered as string.
180236 * For example, when rendering the date 1/1/2011 as Date object constructor its value
181237 * in the json string will be new Date(2011,1,1), and when rendered as string
182- * will be "Date(2011,1,1)"
238+ * will be "Date(2011,1,1)". For further explanation, see class comment.
183239 *
184240 * @return The char sequence with the Json string.
185241 */
@@ -252,6 +308,23 @@ public static CharSequence renderDataTable(DataTable dataTable, boolean includeV
252308 sb .append ("}" ); // table.
253309 return sb ;
254310 }
311+
312+ /**
313+ * @deprecated As of version 1.1.1, changed visibility to private.
314+ *
315+ * Appends a Json representing a cell to the string buffer.
316+ *
317+ * @param cell The cell to write Json for.
318+ * @param sb The string buffer to append to.
319+ * @param includeFormatting Flase if formatting information should be omitted from the json.
320+ * @param isLastColumn Is this the last column in the row.
321+ *
322+ * @return The input string builder.
323+ */
324+ @ Deprecated public static StringBuilder appendCellJson (TableCell cell ,
325+ StringBuilder sb , boolean includeFormatting , boolean isLastColumn ) {
326+ return appendCellJson (cell , sb , includeFormatting , isLastColumn , true );
327+ }
255328
256329 /**
257330 * Appends a Json representing a cell to the string buffer.
@@ -266,11 +339,11 @@ public static CharSequence renderDataTable(DataTable dataTable, boolean includeV
266339 * False if it should should be rendered as string.
267340 * For example, when rendering the date 1/1/2011 as Date object constructor its value
268341 * in the json string will be new Date(2011,1,1), and when rendered as string
269- * will be "Date(2011,1,1)"
342+ * will be "Date(2011,1,1)". For further explanation, see class comment.
270343 *
271344 * @return The input string builder.
272345 */
273- public static StringBuilder appendCellJson (TableCell cell ,
346+ static StringBuilder appendCellJson (TableCell cell ,
274347 StringBuilder sb , boolean includeFormatting , boolean isLastColumn ,
275348 boolean renderDateAsDateConstructor ) {
276349 Value value = cell .getValue ();
0 commit comments