📄 ognl.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.4.2_05) on Sat Aug 14 08:12:33 GMT-07:00 2004 -->
<TITLE>
Ognl (OGNL)
</TITLE>
<META NAME="keywords" CONTENT="ognl.Ognl class">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
parent.document.title="Ognl (OGNL)";
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="Skip navigation links"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../ognl/ObjectPropertyAccessor.html" title="class in ognl"><B>PREV CLASS</B></A>
<A HREF="../ognl/OgnlContext.html" title="class in ognl"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../index.html" target="_top"><B>FRAMES</B></A>
<A HREF="Ognl.html" target="_top"><B>NO FRAMES</B></A>
<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
ognl</FONT>
<BR>
Class Ognl</H2>
<PRE>
java.lang.Object
<IMG SRC="../resources/inherit.gif" ALT="extended by"><B>ognl.Ognl</B>
</PRE>
<HR>
<DL>
<DT>public abstract class <B>Ognl</B><DT>extends java.lang.Object</DL>
<P>
<P>This class provides static methods for parsing and interpreting OGNL expressions.</P> <P>The simplest use of the Ognl class is to get the value of an expression from an object, without extra context or pre-parsing.</P> <PRE> import ognl.Ognl; import ognl.OgnlException; try { result = Ognl.getValue(expression, root); } catch (OgnlException ex) { // Report error or recover } </PRE> <P>This will parse the expression given and evaluate it against the root object given, returning the result. If there is an error in the expression, such as the property is not found, the exception is encapsulated into an <A HREF="../ognl/OgnlException.html" title="class in ognl"><CODE>OgnlException</CODE></A>.</P> <P>Other more sophisticated uses of Ognl can pre-parse expressions. This provides two advantages: in the case of user-supplied expressions it allows you to catch parse errors before evaluation and it allows you to cache parsed expressions into an AST for better speed during repeated use. The pre-parsed expression is always returned as an <CODE>Object</CODE> to simplify use for programs that just wish to store the value for repeated use and do not care that it is an AST. If it does care it can always safely cast the value to an <CODE>AST</CODE> type.</P> <P>The Ognl class also takes a <I>context map</I> as one of the parameters to the set and get methods. This allows you to put your own variables into the available namespace for OGNL expressions. The default context contains only the <CODE>#root</CODE> and <CODE>#context</CODE> keys, which are required to be present. The <CODE>addDefaultContext(Object, Map)</CODE> method will alter an existing <CODE>Map</CODE> to put the defaults in. Here is an example that shows how to extract the <CODE>documentName</CODE> property out of the root object and append a string with the current user name in parens:</P> <PRE> private Map context = new HashMap(); public void setUserName(String value) { context.put("userName", value); } try { // get value using our own custom context map result = Ognl.getValue("documentName + \" (\" + ((#userName == null) ? \"<nobody>\" : #userName) + \")\"", context, root); } catch (OgnlException ex) { // Report error or recover } </PRE>
<P>
<P>
<DL>
<DT><B>Author:</B></DT> <DD>Luke Blanshard (blanshlu@netscape.net), Drew Davidson (drew@ognl.org)</DD></DL>
<HR>
<P>
<!-- ======== NESTED CLASS SUMMARY ======== -->
<!-- =========== FIELD SUMMARY =========== -->
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Method Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.util.Map</CODE></FONT></TD>
<TD><CODE><B><A HREF="../ognl/Ognl.html#addDefaultContext(java.lang.Object, ognl.ClassResolver, java.util.Map)">addDefaultContext</A></B>(java.lang.Object root, <A HREF="../ognl/ClassResolver.html" title="interface in ognl">ClassResolver</A> classResolver, java.util.Map context)</CODE>
<BR>
Appends the standard naming context for evaluating an OGNL expression into the context given so that cached maps can be used as a context.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.util.Map</CODE></FONT></TD>
<TD><CODE><B><A HREF="../ognl/Ognl.html#addDefaultContext(java.lang.Object, ognl.ClassResolver, ognl.TypeConverter, java.util.Map)">addDefaultContext</A></B>(java.lang.Object root, <A HREF="../ognl/ClassResolver.html" title="interface in ognl">ClassResolver</A> classResolver, <A HREF="../ognl/TypeConverter.html" title="interface in ognl">TypeConverter</A> converter, java.util.Map context)</CODE>
<BR>
Appends the standard naming context for evaluating an OGNL expression into the context given so that cached maps can be used as a context.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.util.Map</CODE></FONT></TD>
<TD><CODE><B><A HREF="../ognl/Ognl.html#addDefaultContext(java.lang.Object, ognl.ClassResolver, ognl.TypeConverter, ognl.MemberAccess, java.util.Map)">addDefaultContext</A></B>(java.lang.Object root, <A HREF="../ognl/ClassResolver.html" title="interface in ognl">ClassResolver</A> classResolver, <A HREF="../ognl/TypeConverter.html" title="interface in ognl">TypeConverter</A> converter, <A HREF="../ognl/MemberAccess.html" title="interface in ognl">MemberAccess</A> memberAccess, java.util.Map context)</CODE>
<BR>
Appends the standard naming context for evaluating an OGNL expression into the context given so that cached maps can be used as a context.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.util.Map</CODE></FONT></TD>
<TD><CODE><B><A HREF="../ognl/Ognl.html#addDefaultContext(java.lang.Object, java.util.Map)">addDefaultContext</A></B>(java.lang.Object root, java.util.Map context)</CODE>
<BR>
Appends the standard naming context for evaluating an OGNL expression into the context given so that cached maps can be used as a context.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.util.Map</CODE></FONT></TD>
<TD><CODE><B><A HREF="../ognl/Ognl.html#createDefaultContext(java.lang.Object)">createDefaultContext</A></B>(java.lang.Object root)</CODE>
<BR>
Creates and returns a new standard naming context for evaluating an OGNL expression.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.util.Map</CODE></FONT></TD>
<TD><CODE><B><A HREF="../ognl/Ognl.html#createDefaultContext(java.lang.Object, ognl.ClassResolver)">createDefaultContext</A></B>(java.lang.Object root, <A HREF="../ognl/ClassResolver.html" title="interface in ognl">ClassResolver</A> classResolver)</CODE>
<BR>
Creates and returns a new standard naming context for evaluating an OGNL expression.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.util.Map</CODE></FONT></TD>
<TD><CODE><B><A HREF="../ognl/Ognl.html#createDefaultContext(java.lang.Object, ognl.ClassResolver, ognl.TypeConverter)">createDefaultContext</A></B>(java.lang.Object root, <A HREF="../ognl/ClassResolver.html" title="interface in ognl">ClassResolver</A> classResolver, <A HREF="../ognl/TypeConverter.html" title="interface in ognl">TypeConverter</A> converter)</CODE>
<BR>
Creates and returns a new standard naming context for evaluating an OGNL expression.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static java.util.Map</CODE></FONT></TD>
<TD><CODE><B><A HREF="../ognl/Ognl.html#createDefaultContext(java.lang.Object, ognl.ClassResolver, ognl.TypeConverter, ognl.MemberAccess)">createDefaultContext</A></B>(java.lang.Object root, <A HREF="../ognl/ClassResolver.html" title="interface in ognl">ClassResolver</A> classResolver,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -