PageRenderTime 44ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/b3log-solo/core/src/main/java/org/b3log/solo/util/QueryResults.java

http://b3log-solo.googlecode.com/
Java | 76 lines | 21 code | 7 blank | 48 comment | 0 complexity | e46b03fd14ef7a90cff84645165d90a8 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. /*
  2. * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.b3log.solo.util;
  17. import org.b3log.latke.Keys;
  18. import org.b3log.latke.model.Pagination;
  19. import org.json.JSONArray;
  20. import org.json.JSONObject;
  21. /**
  22. * Query result utilities.
  23. *
  24. * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
  25. * @version 1.0.0.1, Oct 25, 2011
  26. * @since 0.3.5
  27. */
  28. public final class QueryResults {
  29. /**
  30. * Constructs a default query result.
  31. *
  32. * @return a default query result,
  33. * <pre>
  34. * {
  35. * "sc": false
  36. * }
  37. * </pre>
  38. */
  39. public static JSONObject defaultResult() {
  40. return new JSONObject().put(Keys.STATUS_CODE, false);
  41. }
  42. /**
  43. * Constructs a default query results.
  44. *
  45. * @return a default query results,
  46. * <pre>
  47. * {
  48. * "pagination": {
  49. * "paginationPageCount": 0
  50. * },
  51. * "rslts": []
  52. * }
  53. * </pre>
  54. */
  55. public static JSONObject defaultResults() {
  56. final JSONObject ret = new JSONObject();
  57. final JSONObject pagination = new JSONObject();
  58. ret.put(Pagination.PAGINATION, pagination);
  59. pagination.put(Pagination.PAGINATION_PAGE_COUNT, 0);
  60. final JSONArray results = new JSONArray();
  61. ret.put(Keys.RESULTS, results);
  62. return ret;
  63. }
  64. /**
  65. * Private constructor.
  66. */
  67. private QueryResults() {
  68. }
  69. }