@Override protected JspCompilationContext createJspCompilationContext(String name, Options opt, ServletContext sctx, JspRuntimeContext jrctx, ClassLoader classLoader) { JspCompilationContext jcctx = new JspCompilationContext(name, opt, sctx, null, jrctx); jcctx.setClassLoader(classLoader); return jcctx; }
@Override public String getServletFileNameForJsp(Context context, String jspName) { String servletName = null; ServletConfig servletConfig = (ServletConfig) context.findChild("jsp"); if (servletConfig != null) { ServletContext sctx = context.getServletContext(); Options opt = new EmbeddedServletOptions(servletConfig, sctx); JspRuntimeContext jrctx = new JspRuntimeContext(sctx, opt); JspCompilationContext jcctx = createJspCompilationContext(jspName, opt, sctx, jrctx, null); servletName = jcctx.getServletJavaFileName(); } else { logger.error(NO_JSP_SERVLET, context.getName()); } return servletName; }
/** * @return Full path name of the Java file into which the servlet is being * generated. */ public String getServletJavaFileName() { if (servletJavaFileName == null) { servletJavaFileName = getOutputDir() + getServletClassName() + ".java"; } return servletJavaFileName; }
JspServletWrapper(ServletConfig config, Options options, String jspUri, boolean isErrorPage, JspRuntimeContext rctxt) throws JasperException { this.isTagFile = false; this.config = config; this.options = options; this.jspUri = jspUri; this.jspProbeEmitter = (JspProbeEmitter) config.getServletContext().getAttribute( "org.glassfish.jsp.monitor.probeEmitter"); ctxt = new JspCompilationContext(jspUri, isErrorPage, options, config.getServletContext(), this, rctxt); // START PWC 6468930 String jspFilePath = ctxt.getRealPath(jspUri); if (jspFilePath != null) { jspFile = new File(jspFilePath); } // END PWC 6468930 }
if (tagFilePath.startsWith("/META-INF/")) { try { String[] location = compiler.getCompilationContext().getTldLocation(tagInfo.getTagLibrary().getURI()); URL jarUrl = compiler.getCompilationContext().getServletContext().getResource(location[0]); tagFileJarUrl = new URL("jar:" + jarUrl + "!/"); } catch (MalformedURLException e) { JspRuntimeContext rctxt = ctxt.getRuntimeContext(); wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt .getOptions(), tagFilePath, tagInfo, ctxt .getRuntimeContext(), tagFileJarUrl); rctxt.addWrapper(tagFileJarPath + tagFilePath, wrapper); wrapper.getJspEngineContext().setClassLoader(ctxt.getClassLoader()); wrapper.getJspEngineContext().setClassPath(ctxt.getClassPath()); } else { wrapper.getJspEngineContext().setTagInfo(tagInfo); .getServletContext(), ctxt.getOptions(), tagFilePath, tagInfo, ctxt.getRuntimeContext(), ctxt.getTagFileJarUrl(tagFilePath)); tempWrapper.getJspEngineContext().setClassLoader(ctxt.getClassLoader()); tempWrapper.getJspEngineContext().setClassPath(ctxt.getClassPath()); tagClazz = tempWrapper.loadTagFilePrototype(); tempVector.add(tempWrapper.getJspEngineContext() .getCompiler());
if (tagFilePath.startsWith("/META-INF/")) { try { tagJar = compiler.getCompilationContext().getTldResourcePath( tagInfo.getTagLibrary().getURI()).getJar(); } catch (IOException ioe) { throw new JasperException(ioe); JspRuntimeContext rctxt = ctxt.getRuntimeContext(); wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt .getOptions(), tagFilePath, tagInfo, ctxt .getRuntimeContext(), tagJar); rctxt.addWrapper(wrapperUri, wrapper); wrapper.getJspEngineContext().setClassLoader( ctxt.getClassLoader()); wrapper.getJspEngineContext().setClassPath(ctxt.getClassPath()); } else { wrapper.getJspEngineContext().setTagInfo(tagInfo); .getServletContext(), ctxt.getOptions(), tagFilePath, tagInfo, ctxt.getRuntimeContext(), tagJar); tempWrapper.getJspEngineContext().setClassLoader( ctxt.getClassLoader()); tempWrapper.getJspEngineContext().setClassPath(ctxt.getClassPath()); tagClazz = tempWrapper.loadTagFilePrototype();
URL uri = ctxt.getResource(path); if (uri == null) { boolean blockExternal = Boolean.parseBoolean(ctxt.getServletContext() .getInitParameter(Constants.XML_BLOCK_EXTERNAL_INIT_PARAM)); tld = new ParserUtils(blockExternal).parseXMLDocument( IMPLICIT_TLD, is, ctxt.getOptions().isValidationEnabled()); throw new JasperException(ex); } finally { if (is != null) {
String servletPackageName = ctxt.getServletPackageName(); String servletClassName = ctxt.getServletClassName(); String serviceMethodName = Constants.SERVICE_METHOD_NAME; genPreamblePackage(servletPackageName); genPreambleImports(); generateDeclarations(page); out.println(");"); if (ctxt.getOptions().isXpoweredBy()) { out.printil("response.addHeader(\"X-Powered-By\", \"JSP/2.2\");");
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();
pageInfo = new PageInfo(new BeanRepository(ctxt.getClassLoader(), errDispatcher), ctxt.getJspFile(), ctxt.isTagFile()); JspConfig jspConfig = options.getJspConfig(); JspConfig.JspProperty jspProperty = jspConfig.findJspProperty(ctxt .getJspFile()); if (ctxt.isTagFile()) { try { double libraryVersion = Double.parseDouble(ctxt.getTagInfo() .getTagLibrary().getRequiredVersion()); if (libraryVersion < 2.0) { pageInfo.setIsELIgnored("true", null, errDispatcher, true); ctxt.checkOutputDir(); String javaFileName = ctxt.getServletJavaFileName(); parserCtl.parseDirectives(ctxt.getJspFile()); Validator.validateDirectives(this, directives); pageNodes = parserCtl.parse(ctxt.getJspFile()); if (ctxt.isPrototypeMode()) { ctxt.setWriter(null); ctxt.getRuntimeContext().getSmaps().putAll(smaps); tfp.removeProtoTypeFiles(ctxt.getClassFileName());
/** * Full class name */ public String getFullClassName() { if (isTagFile()) { return tagInfo.getTagClassName(); } return getServletPackageName() + '.' + getServletClassName(); }
public Class load() throws JasperException { try { String name = getFullClassName(); if (options.getUsePrecompiled()) { servletClass = getClassLoader().loadClass(name); } else { servletClass = getJspLoader().loadClass(name); } } catch (ClassNotFoundException cex) { throw new JasperException( Localizer.getMessage("jsp.error.unable.load"), cex); } catch (Exception ex) { throw new JasperException( Localizer.getMessage("jsp.error.unable.compile"), ex); } removed = 0; return servletClass; }
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; }
JspCompilationContext clctxt = new JspCompilationContext ( jspUri, this, context, null, rctxt ); clctxt.setServletClassName(targetClassName); targetClassName = null; clctxt.setBasePackageName(targetPackage); Thread.currentThread().setContextClassLoader(loader); clctxt.setClassLoader(loader); clctxt.setClassPath(classPath); Compiler clc = clctxt.createCompiler(); Throwable rootCause = je; while (rootCause instanceof JasperException && ((JasperException) rootCause).getRootCause() != null) { rootCause = ((JasperException) rootCause).getRootCause(); e.getMessage())); throw new JasperException(e); } finally { if(originalClassLoader != null) {
public Class<?> load() throws JasperException { try { getJspLoader(); String name = getFQCN(); servletClass = jspLoader.loadClass(name); } catch (ClassNotFoundException cex) { throw new JasperException(Localizer.getMessage("jsp.error.unable.load"), cex); } catch (Exception ex) { throw new JasperException(Localizer.getMessage("jsp.error.unable.compile"), ex); } removed = 0; return servletClass; }
private JspCompilationContext createJspCompilationContext(JspCompilationInfo info, ServletContext servletContext, Options options, JspRuntimeContext jspRuntimeContext, JspServletWrapper jspServletWrapper, StringWriter stringWriter) { boolean isErrorPage = false; JspCompilationContext cContext = new JspCompilationContext(info.getJspPath(), isErrorPage, options, servletContext, jspServletWrapper, jspRuntimeContext); cContext.getOutputDir(); // forces creation of the directory tree cContext.setServletJavaFileName(info.getJavaSource()); cContext.setServletPackageName(getJspPackageName()); cContext.setWriter(new ServletWriter(new PrintWriter(stringWriter))); createPathToGeneratedJavaSource(info); return cContext; }
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); if (options.getDevelopment() && options.getRecompileOnFail()) { // Force a recompilation attempt on next access jsw.setLastModificationTest(-1); } throw ex; } catch (Exception ex) { JasperException je = new JasperException(MESSAGES.failedClassCompilation(), ex); // Cache compilation exception jsw.setCompilationException(je); throw je; } } }
/** * Are we keeping generated code around? */ public boolean keepGenerated() { return getOptions().getKeepGenerated(); }
public void compile() throws JasperException, FileNotFoundException { createCompiler(false); if (jspCompiler.isOutDated()) { try { jspCompiler.compile(true); jsw.setReload(true); jsw.setCompilationException(null); } catch (JasperException ex) { // Cache compilation exception jsw.setCompilationException(ex); throw ex; } catch (Exception ex) { ex.printStackTrace(); JasperException je = new JasperException( Localizer.getMessage("jsp.error.unable.compile"), ex); // Cache compilation exception jsw.setCompilationException(je); throw je; } } }
public SmapStratum getSmap(String className) { Map<String,SmapStratum> smaps = ctxt.getRuntimeContext().getSmaps(); SmapStratum smap = smaps.get(className); if (smap == null && !options.isSmapSuppressed()) { // Tomcat was restarted so cached SMAP has been lost. However, it // was written to the class file so it can be recovered. smap = SmapUtil.loadSmap(className, ctxt.getJspLoader()); if (smap != null) { smaps.put(className, smap); } } return smap; }