Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2008-04-14 16:40:55 -0400
committerpelder2008-04-14 16:40:55 -0400
commit595d9bfab79c8c62de57c49e56dca66de7795d6d (patch)
tree63fc0f6fb87deadf10530c22eae481cca38074a8
parent400cacbae1e11f77db2c9193d93e72a18a12d8c8 (diff)
downloadorg.eclipse.jet-595d9bfab79c8c62de57c49e56dca66de7795d6d.tar.gz
org.eclipse.jet-595d9bfab79c8c62de57c49e56dca66de7795d6d.tar.xz
org.eclipse.jet-595d9bfab79c8c62de57c49e56dca66de7795d6d.zip
[190650] [JET2] Checking if a variable is defined
-rw-r--r--doc/org.eclipse.jet.doc/references/xpathFunctions/isVariableDefined.html76
-rw-r--r--doc/org.eclipse.jet.doc/references/xpathFunctions/overview.html8
-rw-r--r--doc/org.eclipse.jet.doc/toc.xml2
-rw-r--r--plugins/org.eclipse.jet/plugin.xml6
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/extras/IsVariableDefinedFunction.java51
5 files changed, 143 insertions, 0 deletions
diff --git a/doc/org.eclipse.jet.doc/references/xpathFunctions/isVariableDefined.html b/doc/org.eclipse.jet.doc/references/xpathFunctions/isVariableDefined.html
new file mode 100644
index 0000000..78d3cbd
--- /dev/null
+++ b/doc/org.eclipse.jet.doc/references/xpathFunctions/isVariableDefined.html
@@ -0,0 +1,76 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<HTML>
+<HEAD>
+<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<META name="GENERATOR" content="IBM Software Development Platform">
+<link rel="STYLESHEET" href="../../book.css" charset="ISO-8859-1" type="text/css"/>
+<TITLE>isVariableDefined XPath function</TITLE>
+</HEAD>
+<BODY>
+<TABLE border="0" cellpadding="0" cellspacing="1" width="100%">
+ <TBODY>
+ <TR>
+ <TH align="left"><P>isVariableDefined()</P></TH>
+ <TH align="right"><A href="overview.html">Additional XPath Functions</A></TH>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<H2>isVariableDefined</H2>
+<P>Test whether the named variable is defined.</P>
+<HR>
+<TABLE border="0" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">Function Summary<BR>&nbsp;</TH></TR>
+ <TR>
+ <TD width="20%" valign="top">minimal arguments</TD>
+ <TD><SPAN style="font-family: monospace" valign="top">
+ Boolean isVariableDefined (String variableName)<BR>&nbsp;<BR>
+ </SPAN></TD>
+ </TR>
+ <TR>
+ <TD width="20%" valign="top">all arguments</TD>
+ <TD><SPAN style="font-family: monospace" valign="top">
+ Boolean isVariableDefined (String variableName)<BR>&nbsp;<BR>
+ </SPAN></TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<TABLE border="0" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">Required Arguments<BR>&nbsp;</TH>
+ </TR>
+ <TR>
+ <TD width="20%" valign="top"><B>String variable</B></TD>
+ <TD>a String expression containing a variable name without the leading dollar sign ($)</TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<HR>
+<TABLE border="0" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">There are no optional arguments<BR>&nbsp;</TD>
+ </TBODY>
+</TABLE>
+<HR>
+<TABLE border="0" width="100%">
+ <TBODY>
+ <TR>
+ <TH colspan="2" align="left">Example<BR>&nbsp;</TH></TR>
+ <TR>
+ <TD colspan="2"><SPAN style="font-family: monospace">
+<!-- Begin isVariableDefined example -->
+ <B>isVariableDefined</B>("someVar")<br>
+ <P>returns true only if <code>someVar</code> is defined</P>
+<!-- End isVariableDefined example -->
+</SPAN></TD>
+ </TR>
+ </TBODY>
+</TABLE>
+<P><BR>
+<FONT color="navy" size="-2">&copy; Copyright IBM Corporation 2008. All Rights Reserved.</FONT></P></P></BODY>
+</HTML>
diff --git a/doc/org.eclipse.jet.doc/references/xpathFunctions/overview.html b/doc/org.eclipse.jet.doc/references/xpathFunctions/overview.html
index 3ff7fc3..d43c31e 100644
--- a/doc/org.eclipse.jet.doc/references/xpathFunctions/overview.html
+++ b/doc/org.eclipse.jet.doc/references/xpathFunctions/overview.html
@@ -47,6 +47,14 @@ The following functions are included in JET, in addition to the XPath functions
<!-- End escapeJavaWhitespace description -->
</TD>
</TR>
+ <TR>
+ <TD width="10%"><A href="isVariableDefined.html">isVariableDefined</A></TD>
+ <TD>
+ <!-- Begin escapeJavaWhitespace description -->
+ Test whether the named variable is defined.
+ <!-- End escapeJavaWhitespace description -->
+ </TD>
+ </TR>
<TR>
<TD width="10%"><A href="lower_caseFunction.html">lower-case</A></TD>
<TD>
diff --git a/doc/org.eclipse.jet.doc/toc.xml b/doc/org.eclipse.jet.doc/toc.xml
index a6ece84..6c2a5a7 100644
--- a/doc/org.eclipse.jet.doc/toc.xml
+++ b/doc/org.eclipse.jet.doc/toc.xml
@@ -45,6 +45,8 @@
<topic label="cardinality" href="references/xpathFunctions/cardinalityFunction.html"/>
<topic label="className" href="references/xpathFunctions/classNameFunction.html"/>
<topic label="escapeJavaWhitespace" href="references/xpathFunctions/escapeJavaWhitespaceFunction.html"/>
+ <topic href="references/xpathFunctions/isVariableDefined.html" label="isVariableDefined">
+ </topic>
<topic label="lower-case" href="references/xpathFunctions/lower_caseFunction.html"/>
<topic label="lowercaseFirst" href="references/xpathFunctions/lowercaseFirstFunction.html"/>
<topic label="packageName" href="references/xpathFunctions/packageNameFunction.html"/>
diff --git a/plugins/org.eclipse.jet/plugin.xml b/plugins/org.eclipse.jet/plugin.xml
index 4a724e0..7fcee42 100644
--- a/plugins/org.eclipse.jet/plugin.xml
+++ b/plugins/org.eclipse.jet/plugin.xml
@@ -1161,6 +1161,12 @@ if 'length' is specified, convert only the specified number of characters, other
maxArgs="1"
minArgs="1"
name="uppercaseFirst"/>
+ <function
+ implementation="org.eclipse.jet.internal.xpath.functions.extras.IsVariableDefinedFunction"
+ maxArgs="1"
+ minArgs="1"
+ name="isVariableDefined">
+ </function>
</extension>
<extension
point="org.eclipse.ant.core.antTasks">
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/extras/IsVariableDefinedFunction.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/extras/IsVariableDefinedFunction.java
new file mode 100644
index 0000000..8cbe00b
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/xpath/functions/extras/IsVariableDefinedFunction.java
@@ -0,0 +1,51 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id: IsVariableDefinedFunction.java,v 1.1 2008/04/14 20:40:55 pelder Exp $
+ */
+package org.eclipse.jet.internal.xpath.functions.extras;
+
+import java.util.List;
+
+import org.eclipse.jet.xpath.Context;
+import org.eclipse.jet.xpath.XPathFunction;
+import org.eclipse.jet.xpath.XPathFunctionWithContext;
+import org.eclipse.jet.xpath.XPathUtil;
+
+/**
+ * Implement XPath function <code>boolean isVariableDefined(string name)</code>.
+ */
+public class IsVariableDefinedFunction implements XPathFunction, XPathFunctionWithContext
+{
+
+ private Context context;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.XPathFunction#evaluate(java.util.List)
+ */
+ public Object evaluate(List args)
+ {
+ final String variableName = XPathUtil.xpathString(args.get(0));
+ return Boolean.valueOf(context.getVariableResolver().resolveVariable(variableName) != null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.xpath.XPathFunctionWithContext#setContext(org.eclipse.jet.xpath.Context)
+ */
+ public void setContext(Context context)
+ {
+ this.context = context;
+ }
+
+}

Back to the top