dion 2003/01/11 00:59:46
Modified: jelly/jelly-tags/util/src/test/org/apache/commons/jelly/tags/util
suite.jelly
jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util
UtilTagLibrary.java
Added: jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util
FileTag.java
Log:
- Add a new File tag for easily getting java.io.File objects into the context
Revision Changes Path
1.2 +6 -0
jakarta-commons-sandbox/jelly/jelly-tags/util/src/test/org/apache/commons/jelly/tags/util/suite.jelly
Index: suite.jelly
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/util/src/test/org/apache/commons/jelly/tags/util/suite.jelly,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- suite.jelly 6 Jan 2003 16:15:48 -0000 1.1
+++ suite.jelly 11 Jan 2003 08:59:45 -0000 1.2
@@ -118,5 +118,11 @@
<log:info>Loaded properties value ${props}</log:info>
</test:case>
+
+ <test:case name="testFileTag">
+ <util:file
name="${basedir}/src/test/org/apache/commons/jelly/tags/util/suite.jelly"
+ var="suite" />
+ <test:assert test="${suite != null}" >The suite should exist</test:assert>
+ </test:case>
</test:suite>
1.2 +6 -5
jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/UtilTagLibrary.java
Index: UtilTagLibrary.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/UtilTagLibrary.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UtilTagLibrary.java 6 Jan 2003 16:15:46 -0000 1.1
+++ UtilTagLibrary.java 11 Jan 2003 08:59:46 -0000 1.2
@@ -72,6 +72,7 @@
public UtilTagLibrary() {
registerTag("available", AvailableTag.class);
+ registerTag("file", FileTag.class);
registerTag("loadText", LoadTextTag.class);
registerTag("properties", PropertiesTag.class);
registerTag("replace", ReplaceTag.class);
1.1
jakarta-commons-sandbox/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/FileTag.java
Index: FileTag.java
===================================================================
/*
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.jelly.tags.util;
import java.io.File;
import org.apache.commons.jelly.MissingAttributeException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
/**
* A tag which creates a {@link File} from a given name.
*
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
* @version $Revision: 1.1 $
*/
public class FileTag extends TagSupport {
/** The file to place into the context */
private String name;
/** The variable name to place the file into */
private String var;
// Tag interface
//-------------------------------------------------------------------------
public void doTag(final XMLOutput output) throws Exception {
boolean available = false;
if (name == null) {
throw new MissingAttributeException("name must be specified");
}
if (var == null) {
throw new MissingAttributeException("var must be specified");
}
File newFile = new File(name);
available = newFile.exists() && newFile.canRead();
if (available) {
getContext().setVariable(var, newFile);
} else {
throw new IllegalArgumentException("file '"+ name
+ "' is not readable");
}
}
/**
* Name of the file to be placed into the context
* @param name The fileName to set
*/
public void setName(String name) {
this.name = name;
}
/**
* Name of the variable to contain the file
* @param var The var to set
*/
public void setVar(String var) {
this.var = var;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>