protected void prepare(IResourceUrn urn) {
    String path = urn.getResourceId();
    int pos = path.indexOf('/', 1);

    if (pos > 0) {
      String warName = path.substring(1, pos);
      ResourceRuntimeConfig config = ResourceRuntime.INSTANCE.findConfigByWarName(warName);

      if (config == null) {
        String contextPath = path.substring(0, pos);

        config = ResourceRuntime.INSTANCE.getConfig(contextPath);
      }

      if (config != null) {
        m_contextPath = config.getContextPath();
        m_jsBase = config.getContainer().getAttribute(String.class, ResourceConstant.Js.Base);
      } else {
        throw new ResourceException(
            String.format("Js(%s) not found, please make sure war(%s) configured!", urn, warName));
      }
    } else {
      throw new RuntimeException(String.format("Invalid resource urn(%s) found!", urn));
    }
  }
Beispiel #2
0
  @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);
    }
  }