use of org.apache.sling.scripting.jsp.jasper.JspCompilationContext in project sling by apache.
the class JspcMojo method processFile.
private void processFile(final String file) throws JasperException {
try {
final String jspUri = file.replace('\\', '/');
final JspCompilationContext clctxt = new JspCompilationContext(jspUri, false, this, context, rctxt, false);
JasperException error = clctxt.compile();
if (error != null) {
throw error;
}
if (showSuccess) {
getLog().info("Built File: " + file);
}
} catch (final JasperException je) {
Throwable rootCause = je;
while (rootCause instanceof JasperException && ((JasperException) rootCause).getRootCause() != null) {
rootCause = ((JasperException) rootCause).getRootCause();
}
if (rootCause != je) {
getLog().error("General problem compiling " + file, rootCause);
}
// Bugzilla 35114.
if (failOnError) {
throw je;
}
// just log otherwise
getLog().error(je.getMessage());
} catch (Exception e) {
throw new JasperException(e);
}
}
use of org.apache.sling.scripting.jsp.jasper.JspCompilationContext in project sling by apache.
the class TagFileProcessor method loadTagFile.
/**
* Compiles and loads a tagfile.
*/
private void loadTagFile(Compiler compiler, String tagFilePath, Node.CustomTag n, PageInfo parentPageInfo) throws JasperException {
JspCompilationContext ctxt = compiler.getCompilationContext();
JspRuntimeContext rctxt = ctxt.getRuntimeContext();
rctxt.lockTagFileLoading(tagFilePath);
try {
JspServletWrapper wrapper = rctxt.getWrapper(tagFilePath);
if (wrapper == null) {
wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt.getOptions(), tagFilePath, n.getTagInfo(), ctxt.getRuntimeContext(), compiler.getDefaultIsSession(), ctxt.getTagFileJarUrl(tagFilePath));
wrapper = rctxt.addWrapper(tagFilePath, wrapper);
// Use same classloader and classpath for compiling tag files
//wrapper.getJspEngineContext().setClassLoader(ctxt.getClassLoader());
//wrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
} else {
// Make sure that JspCompilationContext gets the latest TagInfo
// for the tag file. TagInfo instance was created the last
// time the tag file was scanned for directives, and the tag
// file may have been modified since then.
wrapper.getJspEngineContext().setTagInfo(n.getTagInfo());
}
Class tagClazz;
int tripCount = wrapper.incTripCount();
try {
if (tripCount > 0) {
final String postfix = "_" + String.valueOf(tripCount);
// When tripCount is greater than zero, a circular
// dependency exists. The circularily dependant tag
// file is compiled in prototype mode, to avoid infinite
// recursion.
final String tempTagFilePath = tagFilePath + postfix;
final TagInfo tempTagInfo = new JasperTagInfo(n.getTagInfo().getTagName(), n.getTagInfo().getTagClassName() + postfix, n.getTagInfo().getBodyContent(), n.getTagInfo().getInfoString(), n.getTagInfo().getTagLibrary(), n.getTagInfo().getTagExtraInfo(), n.getTagInfo().getAttributes(), n.getTagInfo().getDisplayName(), n.getTagInfo().getSmallIcon(), n.getTagInfo().getLargeIcon(), n.getTagInfo().getTagVariableInfos(), ((JasperTagInfo) n.getTagInfo()).getDynamicAttributesMapName());
JspServletWrapper tempWrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt.getOptions(), tagFilePath, tempTagInfo, ctxt.getRuntimeContext(), compiler.getDefaultIsSession(), ctxt.getTagFileJarUrl(tempTagFilePath));
tagClazz = tempWrapper.loadTagFilePrototype();
tempVector.add(tempWrapper.getJspEngineContext().getCompiler());
String name = JspUtil.getCanonicalName(tagClazz);
final int underscorePos = name.lastIndexOf(postfix);
if (underscorePos > -1) {
n.setTagHandlerClassName(name.substring(0, underscorePos));
}
} else {
tagClazz = wrapper.loadTagFile();
}
} finally {
wrapper.decTripCount();
}
// can only be obtained from the tag instance.
try {
Object tagIns = tagClazz.newInstance();
if (tagIns instanceof JspSourceDependent) {
Iterator iter = ((List) ((JspSourceDependent) tagIns).getDependants()).iterator();
while (iter.hasNext()) {
parentPageInfo.addDependant((String) iter.next());
}
}
} catch (Exception e) {
// ignore errors
}
n.setTagHandlerClass(tagClazz);
} finally {
rctxt.unlockTagFileLoading(tagFilePath);
}
}
Aggregations