Java源码示例:org.apache.jasper.JasperException
示例1
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
}
示例2
public void visit(Node.TemplateText n) throws JasperException {
if ((trim) && ! prePass && n.isAllSpace()) {
n.setText(emptyText);
return;
}
if (textNodeCount++ == 0) {
firstTextNode = n;
textBuffer = new StringBuilder(n.getText());
} else {
// Append text to text buffer
textBuffer.append(n.getText());
n.setText(emptyText);
}
}
示例3
/**
* Name ::= (Letter | '_' | ':') (Letter | Digit | '.' | '_' | '-' | ':')*
*/
private String parseName() throws JasperException {
char ch = (char) reader.peekChar();
if (Character.isLetter(ch) || ch == '_' || ch == ':') {
StringBuilder buf = new StringBuilder();
buf.append(ch);
reader.nextChar();
ch = (char) reader.peekChar();
while (Character.isLetter(ch) || Character.isDigit(ch) || ch == '.'
|| ch == '_' || ch == '-' || ch == ':') {
buf.append(ch);
reader.nextChar();
ch = (char) reader.peekChar();
}
return buf.toString();
}
return null;
}
示例4
@Override
public void visit(Node.InvokeAction n) throws JasperException {
JspUtil.checkAttributes("Invoke", n, invokeAttrs, err);
String scope = n.getTextAttribute("scope");
JspUtil.checkScope(scope, n, err);
String var = n.getTextAttribute("var");
String varReader = n.getTextAttribute("varReader");
if (scope != null && var == null && varReader == null) {
err.jspError(n, "jsp.error.missing_var_or_varReader");
}
if (var != null && varReader != null) {
err.jspError(n, "jsp.error.var_and_varReader");
}
}
示例5
public void setIsELIgnored(String value, Node n, ErrorDispatcher err,
boolean pagedir)
throws JasperException {
if ("true".equalsIgnoreCase(value))
isELIgnored = true;
else if ("false".equalsIgnoreCase(value))
isELIgnored = false;
else {
if (pagedir)
err.jspError(n, "jsp.error.page.invalid.iselignored");
else
err.jspError(n, "jsp.error.tag.invalid.iselignored");
}
isELIgnoredValue = value;
}
示例6
@Override
public void visit(Node.InvokeAction n) throws JasperException {
JspUtil.checkAttributes("Invoke", n, invokeAttrs, err);
String scope = n.getTextAttribute("scope");
JspUtil.checkScope(scope, n, err);
String var = n.getTextAttribute("var");
String varReader = n.getTextAttribute("varReader");
if (scope != null && var == null && varReader == null) {
err.jspError(n, "jsp.error.missing_var_or_varReader");
}
if (var != null && varReader != null) {
err.jspError(n, "jsp.error.var_and_varReader");
}
}
示例7
public static Object getValueFromBeanInfoPropertyEditor(
Class<?> attrClass, String attrName, String attrValue,
Class<?> propertyEditorClass)
throws JasperException
{
try {
PropertyEditor pe =
(PropertyEditor)propertyEditorClass.newInstance();
pe.setAsText(attrValue);
return pe.getValue();
} catch (Exception ex) {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.property.conversion",
attrValue, attrClass.getName(), attrName,
ex.getMessage()));
}
}
示例8
public static void introspect(Object bean, ServletRequest request)
throws JasperException
{
Enumeration<String> e = request.getParameterNames();
while ( e.hasMoreElements() ) {
String name = e.nextElement();
String value = request.getParameter(name);
introspecthelper(bean, name, value, request, name, true);
}
}
示例9
private void evaluateNodes(
Node.Nodes nodes,
SmapStratum s,
boolean breakAtLF) {
try {
nodes.visit(new SmapGenVisitor(s, breakAtLF, classInfos));
} catch (JasperException ex) {
}
}
示例10
/**
* Autodetects the encoding of the XML document supplied by the given
* input stream.
*
* Encoding autodetection is done according to the XML 1.0 specification,
* Appendix F.1: Detection Without External Encoding Information.
*
* @return Two-element array, where the first element (of type
* java.lang.String) contains the name of the (auto)detected encoding, and
* the second element (of type java.lang.Boolean) specifies whether the
* encoding was specified using the 'encoding' attribute of an XML prolog
* (TRUE) or autodetected (FALSE).
*/
public static Object[] getEncoding(String fname, JarFile jarFile,
JspCompilationContext ctxt,
ErrorDispatcher err)
throws IOException, JasperException
{
InputStream inStream = JspUtil.getInputStream(fname, jarFile, ctxt,
err);
XMLEncodingDetector detector = new XMLEncodingDetector();
Object[] ret = detector.getEncoding(inStream, err);
inStream.close();
return ret;
}
示例11
@Override
public void visit(Node.PlugIn n) throws JasperException {
JspUtil.checkAttributes("Plugin", n, plugInAttrs, err);
throwErrorIfExpression(n, "type", "jsp:plugin");
throwErrorIfExpression(n, "code", "jsp:plugin");
throwErrorIfExpression(n, "codebase", "jsp:plugin");
throwErrorIfExpression(n, "align", "jsp:plugin");
throwErrorIfExpression(n, "archive", "jsp:plugin");
throwErrorIfExpression(n, "hspace", "jsp:plugin");
throwErrorIfExpression(n, "jreversion", "jsp:plugin");
throwErrorIfExpression(n, "name", "jsp:plugin");
throwErrorIfExpression(n, "vspace", "jsp:plugin");
throwErrorIfExpression(n, "nspluginurl", "jsp:plugin");
throwErrorIfExpression(n, "iepluginurl", "jsp:plugin");
String type = n.getTextAttribute("type");
if (type == null)
err.jspError(n, "jsp.error.plugin.notype");
if (!type.equals("bean") && !type.equals("applet"))
err.jspError(n, "jsp.error.plugin.badtype");
if (n.getTextAttribute("code") == null)
err.jspError(n, "jsp.error.plugin.nocode");
Node.JspAttribute width = getJspAttribute(null, "width", null,
null, n.getAttributeValue("width"), n, null, false);
n.setWidth(width);
Node.JspAttribute height = getJspAttribute(null, "height", null,
null, n.getAttributeValue("height"), n, null, false);
n.setHeight(height);
visitBody(n);
}
示例12
public Class<?> getBeanType(String bean)
throws JasperException {
Class<?> clazz = null;
try {
clazz = loader.loadClass(beanTypes.get(bean));
} catch (ClassNotFoundException ex) {
throw new JasperException (ex);
}
return clazz;
}
示例13
public static void handleSetProperty(Object bean, String prop,
char value)
throws JasperException
{
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { Character.valueOf(value) });
} catch (Exception ex) {
Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
ExceptionUtils.handleThrowable(thr);
throw new JasperException(ex);
}
}
示例14
@Override
public void doVisit(Node n) throws JasperException {
if ((lineNum >= n.getBeginJavaLine())
&& (lineNum < n.getEndJavaLine())) {
found = n;
}
}
示例15
public static void handleSetProperty(Object bean, String prop,
Object value)
throws JasperException
{
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { value });
} catch (Exception ex) {
Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
ExceptionUtils.handleThrowable(thr);
throw new JasperException(ex);
}
}
示例16
private String getJspConfigPageEncoding(String absFileName)
throws JasperException {
JspConfig jspConfig = ctxt.getOptions().getJspConfig();
JspConfig.JspProperty jspProperty
= jspConfig.findJspProperty(absFileName);
return jspProperty.getPageEncoding();
}
示例17
@Override
public void visit(Node.ParamAction n) throws JasperException {
if (n.getValue().isExpression()) {
scriptingElementSeen = true;
}
paramActionSeen = true;
}
示例18
private void parseUseBean(Node parent) throws JasperException {
Attributes attrs = parseAttributes();
reader.skipSpaces();
Node useBeanNode = new Node.UseBean(attrs, start, parent);
parseOptionalBody(useBeanNode, "jsp:useBean", TagInfo.BODY_CONTENT_JSP);
}
示例19
@Override
public void visit(Node.PlugIn n) throws JasperException {
if (n.getHeight() != null && n.getHeight().isExpression()) {
scriptingElementSeen = true;
}
if (n.getWidth() != null && n.getWidth().isExpression()) {
scriptingElementSeen = true;
}
visitBody(n);
}
示例20
boolean matchesETag(String tagName) throws JasperException {
Mark mark = mark();
if (!matches("</" + tagName))
return false;
skipSpaces();
if (nextChar() == '>')
return true;
setCurrent(mark);
return false;
}
示例21
private void parseScriptlet(Node parent) throws JasperException {
start = reader.mark();
Mark stop = reader.skipUntil("%>");
if (stop == null) {
err.jspError(start, "jsp.error.unterminated", "<%");
}
new Node.Scriptlet(parseScriptText(reader.getText(start, stop)), start,
parent);
}
示例22
@Override
public void visit(Node.TemplateText n) throws JasperException {
/*
* If the template text came from a JSP page written in JSP syntax,
* create a jsp:text element for it (JSP 5.3.2).
*/
appendText(n.getText(), !n.getRoot().isXmlSyntax());
}
示例23
/**
* Generate code to create a map for the alias variables
* @return the name of the map
*/
private String generateAliasMap(Node.CustomTag n, String tagHandlerVar)
throws JasperException {
TagVariableInfo[] tagVars = n.getTagVariableInfos();
String aliasMapVar = null;
boolean aliasSeen = false;
for (int i = 0; i < tagVars.length; i++) {
String nameFrom = tagVars[i].getNameFromAttribute();
if (nameFrom != null) {
String aliasedName = n.getAttributeValue(nameFrom);
if (aliasedName == null)
continue;
if (!aliasSeen) {
out.printin("java.util.HashMap ");
aliasMapVar = tagHandlerVar + "_aliasMap";
out.print(aliasMapVar);
out.println(" = new java.util.HashMap();");
aliasSeen = true;
}
out.printin(aliasMapVar);
out.print(".put(");
out.print(quote(tagVars[i].getNameGiven()));
out.print(", ");
out.print(quote(aliasedName));
out.println(");");
}
}
return aliasMapVar;
}
示例24
public static void handleSetProperty(Object bean, String prop,
byte value)
throws JasperException
{
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { Byte.valueOf(value) });
} catch (Exception ex) {
Throwable thr = ExceptionUtils.unwrapInvocationTargetException(ex);
ExceptionUtils.handleThrowable(thr);
throw new JasperException(ex);
}
}
示例25
public void visit(Node.TaglibDirective n) throws JasperException {
JspUtil.checkAttributes("Taglib directive", n,
taglibDirectiveAttrs, err);
// Either 'uri' or 'tagdir' attribute must be specified
String uri = n.getAttributeValue("uri");
String tagdir = n.getAttributeValue("tagdir");
if (uri == null && tagdir == null) {
err.jspError(n, "jsp.error.taglibDirective.missing.location");
}
if (uri != null && tagdir != null) {
err.jspError(n, "jsp.error.taglibDirective.both_uri_and_tagdir");
}
}
示例26
@Override
public void visit(Node.ELExpression n) throws JasperException {
doMap(n.getEL());
}
示例27
@Override
public void visit(Node.ForwardAction n) throws JasperException {
printAttributes("<jsp:forward", n.getAttributes(), ">");
dumpBody(n);
printString("</jsp:forward>");
}
示例28
@Override
public void accept(Visitor v) throws JasperException {
v.visit(this);
}
示例29
public void visit(Node.ELExpression n) throws JasperException {
printString( n.getText());
}
示例30
public void visit(Node.ParamAction n) throws JasperException {
appendTag(n);
}