public void compile() throws JasperException, FileNotFoundException {
   createCompiler();
   if (jspCompiler.isOutDated()) {
     if (isRemoved()) {
       throw new FileNotFoundException(jspUri);
     }
     try {
       jspCompiler.removeGeneratedFiles();
       jspLoader = null;
       jspCompiler.compile();
       jsw.setReload(true);
       jsw.setCompilationException(null);
     } catch (JasperException ex) {
       // Cache compilation exception
       jsw.setCompilationException(ex);
       if (options.getDevelopment() && options.getRecompileOnFail()) {
         // Force a recompilation attempt on next access
         jsw.setLastModificationTest(-1);
       }
       throw ex;
     } catch (FileNotFoundException fnfe) {
       // Re-throw to let caller handle this - will result in a 404
       throw fnfe;
     } catch (Exception ex) {
       JasperException je =
           new JasperException(Localizer.getMessage("jsp.error.unable.compile"), ex);
       // Cache compilation exception
       jsw.setCompilationException(je);
       throw je;
     }
   }
 }
 public void compile() throws JasperException, FileNotFoundException {
   createCompiler();
   if (jspCompiler.isOutDated()) {
     try {
       jspCompiler.removeGeneratedFiles();
       jspLoader = null;
       jspCompiler.compile();
       jsw.setReload(true);
       jsw.setCompilationException(null);
     } catch (JasperException ex) {
       // Cache compilation exception
       jsw.setCompilationException(ex);
       throw ex;
     } catch (Exception ex) {
       JasperException je =
           new JasperException(Localizer.getMessage("jsp.error.unable.compile"), ex);
       // Cache compilation exception
       jsw.setCompilationException(je);
       throw je;
     }
   }
 }
Exemple #3
0
  protected void processFile(String file) throws JasperException {
    if (log.isDebugEnabled()) {
      log.debug("Processing file: " + file);
    }

    ClassLoader originalClassLoader = null;

    try {
      // set up a scratch/output dir if none is provided
      if (scratchDir == null) {
        String temp = System.getProperty("java.io.tmpdir");
        if (temp == null) {
          temp = "";
        }
        scratchDir = new File(new File(temp).getAbsolutePath());
      }

      String jspUri = file.replace('\\', '/');
      JspCompilationContext clctxt = new JspCompilationContext(jspUri, this, context, null, rctxt);

      /* Override the defaults */
      if ((targetClassName != null) && (targetClassName.length() > 0)) {
        clctxt.setServletClassName(targetClassName);
        targetClassName = null;
      }
      if (targetPackage != null) {
        clctxt.setServletPackageName(targetPackage);
      }

      originalClassLoader = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(loader);

      clctxt.setClassLoader(loader);
      clctxt.setClassPath(classPath);

      Compiler clc = clctxt.createCompiler();

      // If compile is set, generate both .java and .class, if
      // .jsp file is newer than .class file;
      // Otherwise only generate .java, if .jsp file is newer than
      // the .java file
      if (clc.isOutDated(compile)) {
        if (log.isDebugEnabled()) {
          log.debug(jspUri + " is out dated, compiling...");
        }

        clc.compile(compile, true);
      }

      // Generate mapping
      generateWebMapping(file, clctxt);
      if (showSuccess) {
        log.info("Built File: " + file);
      }

    } catch (JasperException je) {
      Throwable rootCause = je;
      while (rootCause instanceof JasperException
          && ((JasperException) rootCause).getRootCause() != null) {
        rootCause = ((JasperException) rootCause).getRootCause();
      }
      if (rootCause != je) {
        log.error(Localizer.getMessage("jspc.error.generalException", file), rootCause);
      }

      // Bugzilla 35114.
      if (getFailOnError()) {
        throw je;
      } else {
        log.error(je.getMessage());
      }

    } catch (Exception e) {
      if ((e instanceof FileNotFoundException) && log.isWarnEnabled()) {
        log.warn(Localizer.getMessage("jspc.error.fileDoesNotExist", e.getMessage()));
      }
      throw new JasperException(e);
    } finally {
      if (originalClassLoader != null) {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
      }
    }
  }
  /** Constructor. */
  public TagLibraryInfoImpl(
      JspCompilationContext ctxt,
      ParserController pc,
      PageInfo pi,
      String prefix,
      String uriIn,
      String[] location,
      ErrorDispatcher err)
      throws JasperException {
    super(prefix, uriIn);

    this.ctxt = ctxt;
    this.parserController = pc;
    this.pi = pi;
    this.err = err;
    InputStream in = null;
    JarFile jarFile = null;

    if (location == null) {
      // The URI points to the TLD itself or to a JAR file in which the
      // TLD is stored
      location = generateTLDLocation(uri, ctxt);
    }

    try {
      if (!location[0].endsWith("jar")) {
        // Location points to TLD file
        try {
          in = getResourceAsStream(location[0]);
          if (in == null) {
            throw new FileNotFoundException(location[0]);
          }
        } catch (FileNotFoundException ex) {
          err.jspError("jsp.error.file.not.found", location[0]);
        }

        parseTLD(ctxt, location[0], in, null);
        // Add TLD to dependency list
        PageInfo pageInfo = ctxt.createCompiler().getPageInfo();
        if (pageInfo != null) {
          pageInfo.addDependant(location[0]);
        }
      } else {
        // Tag library is packaged in JAR file
        try {
          URL jarFileUrl = new URL("jar:" + location[0] + "!/");
          JarURLConnection conn = (JarURLConnection) jarFileUrl.openConnection();
          conn.setUseCaches(false);
          conn.connect();
          jarFile = conn.getJarFile();
          ZipEntry jarEntry = jarFile.getEntry(location[1]);
          in = jarFile.getInputStream(jarEntry);
          parseTLD(ctxt, location[0], in, jarFileUrl);
        } catch (Exception ex) {
          err.jspError("jsp.error.tld.unable_to_read", location[0], location[1], ex.toString());
        }
      }
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (Throwable t) {
        }
      }
      if (jarFile != null) {
        try {
          jarFile.close();
        } catch (Throwable t) {
        }
      }
    }
  }