001: /*
002:
003: * Copyright (c) 2006 The Visigoth Software Society. All rights
004:
005: * reserved.
006:
007: *
008:
009: * Redistribution and use in source and binary forms, with or without
010:
011: * modification, are permitted provided that the following conditions
012:
013: * are met:
014:
015: *
016:
017: * 1. Redistributions of source code must retain the above copyright
018:
019: * notice, this list of conditions and the following disclaimer.
020:
021: *
022:
023: * 2. Redistributions in binary form must reproduce the above copyright
024:
025: * notice, this list of conditions and the following disclaimer in
026:
027: * the documentation and/or other materials provided with the
028:
029: * distribution.
030:
031: *
032:
033: * 3. The end-user documentation included with the redistribution, if
034:
035: * any, must include the following acknowledgement:
036:
037: * "This product includes software developed by the
038:
039: * Visigoth Software Society (http://www.visigoths.org/)."
040:
041: * Alternately, this acknowledgement may appear in the software itself,
042:
043: * if and wherever such third-party acknowledgements normally appear.
044:
045: *
046:
047: * 4. Neither the name "FreeMarker", "Visigoth", nor any of the names of the
048:
049: * project contributors may be used to endorse or promote products derived
050:
051: * from this software without prior written permission. For written
052:
053: * permission, please contact visigoths@visigoths.org.
054:
055: *
056:
057: * 5. Products derived from this software may not be called "FreeMarker" or "Visigoth"
058:
059: * nor may "FreeMarker" or "Visigoth" appear in their names
060:
061: * without prior written permission of the Visigoth Software Society.
062:
063: *
064:
065: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
066:
067: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
068:
069: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
070:
071: * DISCLAIMED. IN NO EVENT SHALL THE VISIGOTH SOFTWARE SOCIETY OR
072:
073: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
074:
075: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
076:
077: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
078:
079: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
080:
081: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
082:
083: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
084:
085: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
086:
087: * SUCH DAMAGE.
088:
089: * ====================================================================
090:
091: *
092:
093: * This software consists of voluntary contributions made by many
094:
095: * individuals on behalf of the Visigoth Software Society. For more
096:
097: * information on the Visigoth Software Society, please see
098:
099: * http://www.visigoths.org/
100:
101: */
102:
103: package freemarker.core;
104:
105: import freemarker.template.*;
106:
107: class ExistsExpression extends Expression {
108:
109: private Expression exp;
110:
111: ExistsExpression(Expression exp) {
112:
113: this .exp = exp;
114:
115: }
116:
117: TemplateModel _getAsTemplateModel(Environment env)
118: throws TemplateException {
119:
120: TemplateModel tm = null;
121:
122: try {
123:
124: tm = exp.getAsTemplateModel(env);
125:
126: } catch (InvalidReferenceException ire) {
127:
128: if (!(exp instanceof ParentheticalExpression)) {
129:
130: throw ire;
131:
132: }
133:
134: }
135:
136: return tm == null ? TemplateBooleanModel.FALSE
137: : TemplateBooleanModel.TRUE;
138:
139: }
140:
141: boolean isLiteral() {
142:
143: return false;
144:
145: }
146:
147: Expression _deepClone(String name, Expression subst) {
148:
149: return new ExistsExpression(exp.deepClone(name, subst));
150:
151: }
152:
153: public String getCanonicalForm() {
154:
155: return exp.getCanonicalForm() + "??";
156:
157: }
158:
159: }
|