AttachContextInterceptor.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:git-webapp 作者:
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
  if (context.getEntity() != null && context.getEntity() instanceof Viewable) {
    final Viewable viewable = (Viewable) context.getEntity();

    Object model = viewable.getModel();
    if (!(model instanceof Map)) {
      model = new HashMap<String, Object>() {
        private static final long serialVersionUID = 1L;
        {
          put("model", viewable.getModel());
        }
      };
    }
    ((Map) model).put("context", getContextMap());
    ((Map) model).put("session", getSessionMap());

    if (servletRequest.getAttribute(RepositoryContext.ATTR_NAME) != null) {
      RepositoryContext repoContext = (RepositoryContext) servletRequest.getAttribute(RepositoryContext.ATTR_NAME);
      ((Map) model).put("repo", repoContext);
    }

    context.setEntity(new Viewable(viewable.getTemplateName(), model));
  }

  context.proceed();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号