Package com.dianping.cat.report

Source Code of com.dianping.cat.report.ReportContext

package com.dianping.cat.report;

import java.io.File;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.unidal.web.mvc.Action;
import org.unidal.web.mvc.ActionContext;
import org.unidal.web.mvc.ActionPayload;
import org.unidal.web.mvc.Page;
import org.unidal.webres.resource.runtime.ResourceConfigurator;
import org.unidal.webres.resource.runtime.ResourceInitializer;
import org.unidal.webres.resource.runtime.ResourceRuntime;
import org.unidal.webres.resource.runtime.ResourceRuntimeContext;
import org.unidal.webres.resource.spi.IResourceRegistry;
import org.unidal.webres.tag.resource.ResourceTagConfigurator;
import org.unidal.webres.taglib.basic.ResourceTagLibConfigurator;

public class ReportContext<T extends ActionPayload<? extends Page, ? extends Action>> extends ActionContext<T> {

  @Override
  public void initialize(HttpServletRequest request, HttpServletResponse response) {
    super.initialize(request, response);

    String contextPath = request.getContextPath();

    synchronized (ResourceRuntime.INSTANCE) {
      if (!ResourceRuntime.INSTANCE.hasConfig(contextPath)) {
        ServletContext servletContext = request.getSession().getServletContext();
        File warRoot = new File(servletContext.getRealPath("/"));

        System.out.println("[INFO] Working directory is " + System.getProperty("user.dir"));
        System.out.println("[INFO] War root is " + warRoot);

        ResourceRuntime.INSTANCE.removeConfig(contextPath);
        ResourceInitializer.initialize(contextPath, warRoot);

        IResourceRegistry registry = ResourceRuntime.INSTANCE.getConfig(contextPath).getRegistry();

        new ResourceConfigurator().configure(registry);
        new ResourceTagConfigurator().configure(registry);
        new ResourceTagLibConfigurator().configure(registry);

        registry.lock();
      }

      ResourceRuntimeContext.setup(contextPath);
    }
  }

}
TOP

Related Classes of com.dianping.cat.report.ReportContext

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.