use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.
the class JspRuntimeLibrary method createTypedArray.
// __end toStringMethod
/**
* Create a typed array.
* This is a special case where params are passed through
* the request and the property is indexed.
*/
public static void createTypedArray(String propertyName, Object bean, Method method, String[] values, Class t, Class propertyEditorClass) throws JasperException {
try {
if (propertyEditorClass != null) {
Object[] tmpval = new Integer[values.length];
for (int i = 0; i < values.length; i++) {
tmpval[i] = getValueFromBeanInfoPropertyEditor(t, propertyName, values[i], propertyEditorClass);
}
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Integer.class)) {
Integer[] tmpval = new Integer[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = new Integer(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Byte.class)) {
Byte[] tmpval = new Byte[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = new Byte(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Boolean.class)) {
Boolean[] tmpval = new Boolean[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = new Boolean(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Short.class)) {
Short[] tmpval = new Short[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = new Short(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Long.class)) {
Long[] tmpval = new Long[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = new Long(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Double.class)) {
Double[] tmpval = new Double[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = new Double(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Float.class)) {
Float[] tmpval = new Float[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = new Float(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Character.class)) {
Character[] tmpval = new Character[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = new Character(values[i].charAt(0));
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(int.class)) {
int[] tmpval = new int[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Integer.parseInt(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(byte.class)) {
byte[] tmpval = new byte[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Byte.parseByte(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(boolean.class)) {
boolean[] tmpval = new boolean[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = (Boolean.valueOf(values[i])).booleanValue();
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(short.class)) {
short[] tmpval = new short[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Short.parseShort(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(long.class)) {
long[] tmpval = new long[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Long.parseLong(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(double.class)) {
double[] tmpval = new double[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Double.valueOf(values[i]).doubleValue();
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(float.class)) {
float[] tmpval = new float[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = Float.valueOf(values[i]).floatValue();
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(char.class)) {
char[] tmpval = new char[values.length];
for (int i = 0; i < values.length; i++) tmpval[i] = values[i].charAt(0);
method.invoke(bean, new Object[] { tmpval });
} else {
Object[] tmpval = new Integer[values.length];
for (int i = 0; i < values.length; i++) {
tmpval[i] = getValueFromPropertyEditorManager(t, propertyName, values[i]);
}
method.invoke(bean, new Object[] { tmpval });
}
} catch (Exception ex) {
throw new JasperException("error in invoking method", ex);
}
}
use of org.apache.sling.scripting.jsp.jasper.JasperException 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);
}
}
use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.
the class TagLibraryInfoImpl method createValidator.
private TagLibraryValidator createValidator(TreeNode elem) throws JasperException {
String validatorClass = null;
Map initParams = new Hashtable();
Iterator list = elem.findChildren();
while (list.hasNext()) {
TreeNode element = (TreeNode) list.next();
String tname = element.getName();
if ("validator-class".equals(tname))
validatorClass = element.getBody();
else if ("init-param".equals(tname)) {
String[] initParam = createInitParam(element);
initParams.put(initParam[0], initParam[1]);
} else if (// Ignored elements
"description".equals(tname) || false) {
} else {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.validator", tname));
}
}
}
TagLibraryValidator tlv = null;
if (validatorClass != null && !validatorClass.equals("")) {
try {
Class tlvClass = ctxt.getClassLoader().loadClass(validatorClass);
tlv = (TagLibraryValidator) tlvClass.newInstance();
} catch (Exception e) {
err.jspError("jsp.error.tlvclass.instantiation", validatorClass, e);
}
}
if (tlv != null) {
tlv.setInitParameters(initParams);
}
return tlv;
}
use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.
the class Parser method parseCustomTag.
/*
* # '<' CustomAction CustomActionBody
*
* CustomAction ::= TagPrefix ':' CustomActionName
*
* TagPrefix ::= Name
*
* CustomActionName ::= Name
*
* CustomActionBody ::= ( Attributes CustomActionEnd ) | <TRANSLATION_ERROR>
*
* Attributes ::= ( S Attribute )* S?
*
* CustomActionEnd ::= CustomActionTagDependent | CustomActionJSPContent |
* CustomActionScriptlessContent
*
* CustomActionTagDependent ::= TagDependentOptionalBody
*
* CustomActionJSPContent ::= OptionalBody
*
* CustomActionScriptlessContent ::= ScriptlessOptionalBody
*/
private boolean parseCustomTag(Node parent) throws JasperException {
if (reader.peekChar() != '<') {
return false;
}
// Parse 'CustomAction' production (tag prefix and custom action name)
// skip '<'
reader.nextChar();
String tagName = reader.parseToken(false);
int i = tagName.indexOf(':');
if (i == -1) {
reader.reset(start);
return false;
}
String prefix = tagName.substring(0, i);
String shortTagName = tagName.substring(i + 1);
// Check if this is a user-defined tag.
String uri = pageInfo.getURI(prefix);
if (uri == null) {
reader.reset(start);
// Remember the prefix for later error checking
pageInfo.putNonCustomTagPrefix(prefix, reader.mark());
return false;
}
TagLibraryInfo tagLibInfo = pageInfo.getTaglib(uri);
TagInfo tagInfo = tagLibInfo.getTag(shortTagName);
TagFileInfo tagFileInfo = tagLibInfo.getTagFile(shortTagName);
if (tagInfo == null && tagFileInfo == null) {
err.jspError(start, "jsp.error.bad_tag", shortTagName, prefix);
}
Class tagHandlerClass = null;
if (tagInfo != null) {
// Must be a classic tag, load it here.
// tag files will be loaded later, in TagFileProcessor
String handlerClassName = tagInfo.getTagClassName();
try {
tagHandlerClass = ctxt.getClassLoader().loadClass(handlerClassName);
} catch (Exception e) {
err.jspError(start, "jsp.error.loadclass.taghandler", handlerClassName, tagName);
}
}
// Parse 'CustomActionBody' production:
// At this point we are committed - if anything fails, we produce
// a translation error.
// Parse 'Attributes' production:
Attributes attrs = parseAttributes();
reader.skipSpaces();
// Parse 'CustomActionEnd' production:
if (reader.matches("/>")) {
if (tagInfo != null) {
new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
} else {
new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
}
return true;
}
// Now we parse one of 'CustomActionTagDependent',
// 'CustomActionJSPContent', or 'CustomActionScriptlessContent'.
// depending on body-content in TLD.
// Looking for a body, it still can be empty; but if there is a
// a tag body, its syntax would be dependent on the type of
// body content declared in the TLD.
String bc;
if (tagInfo != null) {
bc = tagInfo.getBodyContent();
} else {
bc = tagFileInfo.getTagInfo().getBodyContent();
}
Node tagNode = null;
if (tagInfo != null) {
tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagInfo, tagHandlerClass);
} else {
tagNode = new Node.CustomTag(tagName, prefix, shortTagName, uri, attrs, start, parent, tagFileInfo);
}
parseOptionalBody(tagNode, tagName, bc);
return true;
}
use of org.apache.sling.scripting.jsp.jasper.JasperException in project sling by apache.
the class JspcMojo method execute.
/*
* (non-Javadoc)
*
* @see org.apache.maven.plugin.Mojo#execute()
*/
public void execute() throws MojoExecutionException {
try {
uriSourceRoot = sourceDirectory.getCanonicalPath();
} catch (Exception e) {
uriSourceRoot = sourceDirectory.getAbsolutePath();
}
// ensure output directory
File outputDirectoryFile = new File(outputDirectory);
if (!outputDirectoryFile.isDirectory()) {
if (outputDirectoryFile.exists()) {
throw new MojoExecutionException(outputDirectory + " exists but is not a directory");
}
if (!outputDirectoryFile.mkdirs()) {
throw new MojoExecutionException("Cannot create output directory " + outputDirectory);
}
}
// have the files compiled
String oldValue = System.getProperty(LogFactoryImpl.LOG_PROPERTY);
try {
// ensure the JSP Compiler does not try to use Log4J
System.setProperty(LogFactoryImpl.LOG_PROPERTY, SimpleLog.class.getName());
executeInternal();
if (printCompilationReport) {
printCompilationReport();
}
} catch (JasperException je) {
getLog().error("Compilation Failure", je);
throw new MojoExecutionException(je.getMessage(), je);
} finally {
if (oldValue == null) {
System.clearProperty(LogFactoryImpl.LOG_PROPERTY);
} else {
System.setProperty(LogFactoryImpl.LOG_PROPERTY, oldValue);
}
}
project.addCompileSourceRoot(outputDirectory);
}
Aggregations