コード例 #1
0
ファイル: JspC.java プロジェクト: faicm/tomcat
  /** Executes the compilation. */
  @Override
  public void execute() {
    if (log.isDebugEnabled()) {
      log.debug("execute() starting for " + pages.size() + " pages.");
    }

    try {
      if (uriRoot == null) {
        if (pages.size() == 0) {
          throw new JasperException(Localizer.getMessage("jsp.error.jspc.missingTarget"));
        }
        String firstJsp = pages.get(0);
        File firstJspF = new File(firstJsp);
        if (!firstJspF.exists()) {
          throw new JasperException(Localizer.getMessage("jspc.error.fileDoesNotExist", firstJsp));
        }
        locateUriRoot(firstJspF);
      }

      if (uriRoot == null) {
        throw new JasperException(Localizer.getMessage("jsp.error.jspc.no_uriroot"));
      }

      File uriRootF = new File(uriRoot);
      if (!uriRootF.isDirectory()) {
        throw new JasperException(Localizer.getMessage("jsp.error.jspc.uriroot_not_dir"));
      }

      if (loader == null) {
        loader = initClassLoader();
      }
      if (context == null) {
        initServletContext(loader);
      }

      // No explicit pages, we'll process all .jsp in the webapp
      if (pages.size() == 0) {
        scanFiles(uriRootF);
      }

      initWebXml();

      Iterator<String> iter = pages.iterator();
      while (iter.hasNext()) {
        String nextjsp = iter.next().toString();
        File fjsp = new File(nextjsp);
        if (!fjsp.isAbsolute()) {
          fjsp = new File(uriRootF, nextjsp);
        }
        if (!fjsp.exists()) {
          if (log.isWarnEnabled()) {
            log.warn(Localizer.getMessage("jspc.error.fileDoesNotExist", fjsp.toString()));
          }
          continue;
        }
        String s = fjsp.getAbsolutePath();
        if (s.startsWith(uriRoot)) {
          nextjsp = s.substring(uriRoot.length());
        }
        if (nextjsp.startsWith("." + File.separatorChar)) {
          nextjsp = nextjsp.substring(2);
        }
        processFile(nextjsp);
      }

      completeWebXml();

      if (addWebXmlMappings) {
        mergeIntoWebXml();
      }

    } catch (IOException ioe) {
      throw new BuildException(ioe);

    } catch (JasperException je) {
      Throwable rootCause = je;
      while (rootCause instanceof JasperException
          && ((JasperException) rootCause).getRootCause() != null) {
        rootCause = ((JasperException) rootCause).getRootCause();
      }
      if (rootCause != je) {
        rootCause.printStackTrace();
      }
      throw new BuildException(je);
    } finally {
      if (loader != null) {
        LogFactory.release(loader);
      }
    }
  }
コード例 #2
0
 /**
  * Release any internal references to previously created {@link LogFactory} instances, after
  * calling the instance method <code>release()</code> on each of them. This is useful in
  * environments like servlet containers, which implement application reloading by throwing away a
  * ClassLoader. Dangling references to objects in that class loader would prevent garbage
  * collection.
  */
 public static void releaseAll() {
   singleton.release();
 }