@Override protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { String jspName = ServletRequestUtils.getStringParameter(request, "source", null); ServletContext sctx = context.getServletContext(); ServletConfig scfg = (ServletConfig) context.findChild("jsp"); Options opt = new EmbeddedServletOptions(scfg, sctx); String encoding = opt.getJavaEncoding(); String content = null; if (jspName != null) { String servletName = getContainerWrapper().getTomcatContainer().getServletFileNameForJsp(context, jspName); if (servletName != null) { File servletFile = new File(servletName); if (servletFile.exists()) { try (InputStream fis = Files.newInputStream(servletFile.toPath())) { content = Utils.highlightStream(jspName, fis, "java", encoding); } } } } return new ModelAndView(getViewName(), "content", content); }
public File getScratchDir() { return options.getScratchDir(); }
Summary summary, URLClassLoader classLoader, int level, boolean compile) { ServletContext sctx = ctx.getServletContext(); Set<String> paths = sctx.getResourcePaths(jspName); name.endsWith(".jsp") || name.endsWith(".jspx") || opt.getJspConfig().isJspPage(name); } catch (Exception e) { org.apache.jasper.compiler.Compiler compiler = jcctx.createCompiler(); if (compile) { compiler.compile();
if (log.isDebugEnabled()) { if (loader != null) { log.debug(Localizer.getMessage("jsp.message.parent_class_loader_is", loader.toString())); } else { log.debug(Localizer.getMessage("jsp.message.parent_class_loader_is", "<none>")); String appBase = context.getRealPath("/"); if (!options.getDevelopment() && appBase != null && options.getCheckInterval() > 0) { lastCompileCheck = System.currentTimeMillis(); if (options.getMaxLoadedJsps() > 0) { jspQueue = new FastRemovalDequeue<>(options.getMaxLoadedJsps()); if (log.isDebugEnabled()) { log.debug(Localizer.getMessage("jsp.message.jsp_queue_created", "" + options.getMaxLoadedJsps(), context.getContextPath())); jspIdleTimeout = options.getJspIdleTimeout() * 1000;
cpath.append(options.getScratchDir() + sep); String cp = (String) context.getAttribute(Constants.SERVLET_CLASSPATH); if (cp == null || cp.equals("")) { cp = options.getClassPath(); if(log.isDebugEnabled()) { log.debug("Compilation classpath initialized: " + path);
String sep = System.getProperty("path.separator"); cpath.append(options.getScratchDir() + sep); String cp = (String) context.getAttribute(Constants.SERVLET_CLASSPATH); if (cp == null || cp.equals("")) { cp = options.getClassPath();
ExceptionUtils.handleThrowable(e); log.warn("Failed to load engineOptionsClass", e); jspFile = config.getInitParameter("jspFile"); try { if (null == context.getResource(jspFile)) { throw new ServletException("missing jspFile: [" + jspFile + "]"); if (log.isDebugEnabled()) { log.debug(Localizer.getMessage("jsp.message.scratch.dir.is", options.getScratchDir().toString())); log.debug(Localizer.getMessage("jsp.message.dont.modify.servlets"));
/** * Create a JspRuntimeContext for a web application context. * * Loads in any previously generated dependencies from file. * * @param context ServletContext for web application */ public JspRuntimeContext(ServletContext context, Options options) { this.context = context; this.options = options; // Get the parent class loader parentClassLoader = Thread.currentThread().getContextClassLoader(); if (parentClassLoader == null) { parentClassLoader = this.getClass().getClassLoader(); } JasperLogger.COMPILER_LOGGER.logParentClassLoader((parentClassLoader != null) ? parentClassLoader.toString() : "[none]"); initClassPath(); if (Constants.IS_SECURITY_ENABLED) { initSecurity(); } // If this web application context is running from a // directory, start the background compilation thread String appBase = context.getRealPath("/"); if (!options.getDevelopment() && appBase != null && options.getCheckInterval() > 0) { lastCheck = System.currentTimeMillis(); } }
&& (ctxt.getOptions().getModificationTestInterval() > 0)) { + (ctxt.getOptions().getModificationTestInterval() * 1000) > System .currentTimeMillis()) { return false; Long jspRealLastModified = ctxt.getLastModified(ctxt.getJspFile()); if (jspRealLastModified.longValue() < 0) { if (log.isDebugEnabled()) { log.debug("Compiler: outdated: " + targetFile + " " + targetLastModified); if (log.isDebugEnabled()) log.debug("Problem accessing resource. Treat as outdated.", e);
String javaEncoding = ctxt.getOptions().getJavaEncoding(); String javaFileName = ctxt.getServletJavaFileName(); String classpath = ctxt.getClassPath(); srcPath.setLocation(options.getScratchDir()); info.append(" work dir=" + options.getScratchDir() + "\n"); if(ctxt.getOptions().getFork()) { String endorsed = System.getProperty("java.endorsed.dirs"); if(endorsed != null) { javac.setDebug(ctxt.getOptions().getClassDebugInfo()); javac.setSrcdir(srcPath); javac.setTempdir(options.getScratchDir()); javac.setFork(ctxt.getOptions().getFork()); info.append(" srcDir=" + srcPath + "\n" ); if (options.getCompiler() != null) { javac.setCompiler(options.getCompiler()); info.append(" compiler=" + options.getCompiler() + "\n"); if (options.getCompilerTargetVM() != null) { javac.setTarget(options.getCompilerTargetVM()); info.append(" compilerTargetVM=" + options.getCompilerTargetVM() + "\n"); if (options.getCompilerSourceVM() != null) { javac.setSource(options.getCompilerSourceVM()); info.append(" compilerSourceVM=" + options.getCompilerSourceVM() + "\n");
if (now > (lastCompileCheck + (options.getCheckInterval() * 1000L))) { lastCompileCheck = now; } else { ctxt.compile(); } catch (FileNotFoundException ex) { ctxt.incrementRemoved(); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); jsw.getServletContext().log(MESSAGES.backgroundCompilationFailed(), t);
pageInfo = new PageInfo(new BeanRepository(ctxt.getClassLoader(), errDispatcher), ctxt.getJspFile()); JspConfig jspConfig = options.getJspConfig(); JspProperty jspProperty = jspConfig.findJspProperty(ctxt.getJspFile()); pageInfo.setIncludeCoda(jspProperty.getIncludeCoda()); if (options.isDefaultBufferNone() && pageInfo.getBufferValue() == null){ ctxt.getOptions().getJavaEncoding()); writer = new ServletWriter(new PrintWriter(javaWriter)); ctxt.setWriter(writer); if (ctxt.isPrototypeMode()) { Generator.generate(writer, this, pageNodes); writer.close(); writer = null; TagPluginManager tagPluginManager = options.getTagPluginManager(); tagPluginManager.apply(pageNodes, errDispatcher, pageInfo); if (! options.isSmapSuppressed()) { smapUtil.generateSmap(pageNodes);
@Override public boolean isOutDated() { if (jsw != null && (ctxt.getOptions().getModificationTestInterval() > 0)) { + (ctxt.getOptions().getModificationTestInterval() * 1000) > System .currentTimeMillis()) { return false; File targetFile = new File(ctxt.getClassFileName()); if (!targetFile.exists()) { return true; outdated = isOutdated(ctxt.getClassFileName(), is); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Problem accessing resource. Treat as outdated.", e); return true; if (log.isDebugEnabled()) log.debug("Problem accessing resource. Treat as outdated.", e); return true;
String javaFileName = ctxt.getServletJavaFileName(); String classpath = ctxt.getClassPath(); String sep = System.getProperty("path.separator"); String sysClassPath = options.getSystemClassPath(); if (sysClassPath != null) { StringTokenizer tokenizer = new StringTokenizer(sysClassPath, sep); javaCompiler.setDebug(options.getClassDebugInfo()); if (options.getCompilerTargetVM() != null) { javaCompiler.setTargetVM(options.getCompilerTargetVM()); if (options.getCompilerSourceVM() != null) { javaCompiler.setSourceVM(options.getCompilerSourceVM()); javaCompiler.compile(ctxt.getFullClassName(), pageNodes); if (!ctxt.isPrototypeMode() && !options.isSmapSuppressed()) { smapUtil.installSmap(); if (options.getSaveBytecode()) { javaCompiler.saveClassFile(ctxt.getFullClassName(), ctxt.getClassFileName());
String classpath = ctxt.getClassPath(); String sep = System.getProperty("path.separator"); String sysClassPath = options.getSystemClassPath(); if (sysClassPath != null) { StringTokenizer tokenizer = new StringTokenizer(sysClassPath, sep); javaCompiler.setDebug(options.getClassDebugInfo()); if (options.getCompilerTargetVM() != null) { javaCompiler.setTargetVM(options.getCompilerTargetVM()); if (options.getCompilerSourceVM() != null) { javaCompiler.setSourceVM(options.getCompilerSourceVM());
String jsp = ctxt.getJspFile(); && (ctxt.getOptions().getModificationTestInterval() > 0)) { + (ctxt.getOptions().getModificationTestInterval() * 1000) > System .currentTimeMillis()) { return false;
private void createOutputDir() { String path = null; if (isTagFile()) { String tagName = tagInfo.getTagClassName(); path = tagName.replace('.', '/'); path = path.substring(0, path.lastIndexOf('/')); } else { path = getServletPackageName().replace('.', '/'); } try { // Append servlet or tag handler path to scratch dir File f = new File( options.getScratchDir(), path ); makeOutputDir(f.getPath() + File.separator); baseUrl = options.getScratchDir().toURL(); } catch (Exception e) { throw new IllegalStateException("No output directory: " + e.getMessage()); } }
JspConfig jspConfig = ctxt.getOptions().getJspConfig(); JspConfig.JspProperty jspProperty = jspConfig.findJspProperty( absFileName); err); } catch (FileNotFoundException ex) { throw new JasperException(ex);
private ServletWriter setupContextWriter(String javaFileName) throws FileNotFoundException, JasperException { ServletWriter writer; // Setup the ServletWriter String javaEncoding = ctxt.getOptions().getJavaEncoding(); OutputStreamWriter osw = null; try { osw = new OutputStreamWriter( new FileOutputStream(javaFileName), javaEncoding); } catch (UnsupportedEncodingException ex) { errDispatcher.jspError("jsp.error.needAlternateJavaEncoding", javaEncoding); } writer = new ServletWriter(new PrintWriter(osw)); ctxt.setWriter(writer); return writer; }
for (int i = 0; i < textSize; i++) { char ch = text.charAt(i); out.printil("out.write(" + quote(ch) + ");"); if (i > 0) { n.addSmap(lineInc); if (ctxt.getOptions().genStringAsCharArray()) { caOut.print(charArrayName); caOut.print(" = "); caOut.print(quote(text)); caOut.println(".toCharArray();");