PageRenderTime 80ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/QingTingFanBianYi/src/com/alibaba/fastjson/support/spring/FastJsonJsonView.java

https://gitlab.com/qt-prometheus/qt-prometheus
Java | 123 lines | 104 code | 15 blank | 4 comment | 9 complexity | 54d14262436f9f5c2052ee31b2a49de8 MD5 | raw file
  1. package com.alibaba.fastjson.support.spring;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.serializer.SerializerFeature;
  4. import java.io.ByteArrayOutputStream;
  5. import java.io.OutputStream;
  6. import java.nio.charset.Charset;
  7. import java.util.HashMap;
  8. import java.util.Iterator;
  9. import java.util.Map;
  10. import java.util.Map.Entry;
  11. import java.util.Set;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14. import org.springframework.util.CollectionUtils;
  15. import org.springframework.validation.BindingResult;
  16. import org.springframework.web.servlet.view.AbstractView;
  17. public class FastJsonJsonView extends AbstractView
  18. {
  19. public static final String DEFAULT_CONTENT_TYPE = "application/json";
  20. public static final Charset UTF8 = Charset.forName("UTF-8");
  21. private Charset charset = UTF8;
  22. private boolean disableCaching = true;
  23. private Set<String> renderedAttributes;
  24. private SerializerFeature[] serializerFeatures = new SerializerFeature[0];
  25. private boolean updateContentLength = false;
  26. public FastJsonJsonView()
  27. {
  28. setContentType("application/json");
  29. setExposePathVariables(false);
  30. }
  31. protected Object filterModel(Map<String, Object> paramMap)
  32. {
  33. HashMap localHashMap = new HashMap(paramMap.size());
  34. if (!CollectionUtils.isEmpty(this.renderedAttributes));
  35. for (Set localSet = this.renderedAttributes; ; localSet = paramMap.keySet())
  36. {
  37. paramMap = paramMap.entrySet().iterator();
  38. while (paramMap.hasNext())
  39. {
  40. Map.Entry localEntry = (Map.Entry)paramMap.next();
  41. if ((!(localEntry.getValue() instanceof BindingResult)) && (localSet.contains(localEntry.getKey())))
  42. localHashMap.put(localEntry.getKey(), localEntry.getValue());
  43. }
  44. }
  45. return localHashMap;
  46. }
  47. public Charset getCharset()
  48. {
  49. return this.charset;
  50. }
  51. public SerializerFeature[] getFeatures()
  52. {
  53. return this.serializerFeatures;
  54. }
  55. protected void prepareResponse(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
  56. {
  57. setResponseContentType(paramHttpServletRequest, paramHttpServletResponse);
  58. paramHttpServletResponse.setCharacterEncoding(UTF8.name());
  59. if (this.disableCaching)
  60. {
  61. paramHttpServletResponse.addHeader("Pragma", "no-cache");
  62. paramHttpServletResponse.addHeader("Cache-Control", "no-cache, no-store, max-age=0");
  63. paramHttpServletResponse.addDateHeader("Expires", 1L);
  64. }
  65. }
  66. protected void renderMergedOutputModel(Map<String, Object> paramMap, HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
  67. throws Exception
  68. {
  69. paramHttpServletRequest = JSON.toJSONString(filterModel(paramMap), this.serializerFeatures).getBytes(this.charset);
  70. if (this.updateContentLength);
  71. for (paramMap = createTemporaryOutputStream(); ; paramMap = paramHttpServletResponse.getOutputStream())
  72. {
  73. paramMap.write(paramHttpServletRequest);
  74. if (this.updateContentLength)
  75. writeToResponse(paramHttpServletResponse, (ByteArrayOutputStream)paramMap);
  76. return;
  77. }
  78. }
  79. public void setCharset(Charset paramCharset)
  80. {
  81. this.charset = paramCharset;
  82. }
  83. public void setDisableCaching(boolean paramBoolean)
  84. {
  85. this.disableCaching = paramBoolean;
  86. }
  87. public void setFeatures(SerializerFeature[] paramArrayOfSerializerFeature)
  88. {
  89. this.serializerFeatures = paramArrayOfSerializerFeature;
  90. }
  91. public void setRenderedAttributes(Set<String> paramSet)
  92. {
  93. this.renderedAttributes = paramSet;
  94. }
  95. @Deprecated
  96. public void setSerializerFeature(SerializerFeature[] paramArrayOfSerializerFeature)
  97. {
  98. setFeatures(paramArrayOfSerializerFeature);
  99. }
  100. public void setUpdateContentLength(boolean paramBoolean)
  101. {
  102. this.updateContentLength = paramBoolean;
  103. }
  104. }
  105. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  106. * Qualified Name: com.alibaba.fastjson.support.spring.FastJsonJsonView
  107. * JD-Core Version: 0.6.2
  108. */