You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2004/09/08 06:51:55 UTC
cvs commit: jakarta-commons/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util LoadTextTag.java AvailableTag.java
dion 2004/09/07 21:51:55
Modified: jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util
LoadTextTag.java AvailableTag.java
Log:
detab
Revision Changes Path
1.6 +43 -43 jakarta-commons/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/LoadTextTag.java
Index: LoadTextTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/LoadTextTag.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LoadTextTag.java 25 Feb 2004 01:31:53 -0000 1.5
+++ LoadTextTag.java 8 Sep 2004 04:51:54 -0000 1.6
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,8 +34,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-/**
- * A tag which loads text from a file or URI into a Jelly variable.
+/**
+ * A tag which loads text from a file or URI into a Jelly variable.
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision$
@@ -54,7 +54,7 @@
}
// Tag interface
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
if (var == null) {
throw new MissingAttributeException("var");
@@ -67,7 +67,7 @@
if (! file.exists()) {
throw new JellyTagException( "The file: " + file + " does not exist" );
}
-
+
try {
if ( encoding == null )
reader = new FileReader(file);
@@ -78,7 +78,7 @@
} catch (UnsupportedEncodingException e) {
throw new JellyTagException("Could not use the encoding \"" + encoding + "\".",e);
}
- }
+ }
else {
InputStream in = context.getResourceAsStream(uri);
if (in == null) {
@@ -87,22 +87,22 @@
// @todo should we allow an encoding to be specified?
reader = new InputStreamReader(in);
}
-
+
String text = null;
-
+
try {
text = loadText(reader);
- }
+ }
catch (IOException e) {
throw new JellyTagException(e);
}
-
+
context.setVariable(var, text);
}
// Properties
- //-------------------------------------------------------------------------
-
+ //-------------------------------------------------------------------------
+
/**
* Sets the name of the variable which will be exported with the text value of the
* given file.
@@ -142,20 +142,20 @@
}
/**
- * Sets the uri to be parsed as text.
- * This can be an absolute URL or a relative or absolute URI
+ * Sets the uri to be parsed as text.
+ * This can be an absolute URL or a relative or absolute URI
* from this Jelly script or the root context.
*/
public void setUri(String uri) {
this.uri = uri;
}
-
+
/** Sets the encoding to be used to read the file, defaults to the platform-encoding.
*/
public void setEncoding(String encName) {
this.encoding = encName;
}
-
+
/** Returns the encoding set.
* @return the encoding set with {@link #setEncoding(String)}
*/
@@ -165,36 +165,36 @@
// Implementation methods
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
/**
* Loads all the text from the given Reader
*/
protected String loadText(Reader reader) throws IOException {
StringBuffer buffer = new StringBuffer();
-
+
// @todo its probably more efficient to use a fixed char[] buffer instead
- try {
- BufferedReader bufferedReader = new BufferedReader(reader);
- while (true) {
- String line = bufferedReader.readLine();
- if (line == null) {
- break;
- }
- else {
- buffer.append(line);
- buffer.append('\n');
- }
- }
- return buffer.toString();
- }
- finally {
- try {
- reader.close();
- }
- catch (Exception e) {
- log.error( "Caught exception closing Reader: " + e, e);
- }
- }
+ try {
+ BufferedReader bufferedReader = new BufferedReader(reader);
+ while (true) {
+ String line = bufferedReader.readLine();
+ if (line == null) {
+ break;
+ }
+ else {
+ buffer.append(line);
+ buffer.append('\n');
+ }
+ }
+ return buffer.toString();
+ }
+ finally {
+ try {
+ reader.close();
+ }
+ catch (Exception e) {
+ log.error( "Caught exception closing Reader: " + e, e);
+ }
+ }
}
}
1.5 +57 -57 jakarta-commons/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/AvailableTag.java
Index: AvailableTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/AvailableTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AvailableTag.java 25 Feb 2004 01:31:53 -0000 1.4
+++ AvailableTag.java 8 Sep 2004 04:51:54 -0000 1.5
@@ -1,12 +1,12 @@
/*
* Copyright 2002,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,30 +30,30 @@
* A tag which evaluates its body if the given file is available.
* The file can be specified via a File object or via a relative or absolute
* URI from the current Jelly script.
- *
+ *
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision$
*/
public class AvailableTag extends TagSupport {
-
- private File file;
- private String uri;
+
+ private File file;
+ private String uri;
public AvailableTag() {
}
// Tag interface
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
public void doTag(final XMLOutput output) throws JellyTagException {
- boolean available = false;
-
- if (file != null) {
- available = file.exists();
- }
- else if (uri != null) {
+ boolean available = false;
+
+ if (file != null) {
+ available = file.exists();
+ }
+ else if (uri != null) {
try {
URL url = context.getResource(uri);
- String fileName = url.getFile();
+ String fileName = url.getFile();
InputStream is = url.openStream();
available = (is != null);
is.close();
@@ -61,51 +61,51 @@
throw new JellyTagException(e);
} catch (IOException ioe) {
available = false;
- }
- }
-
- if (available) {
- invokeBody(output);
- }
+ }
+ }
+
+ if (available) {
+ invokeBody(output);
+ }
}
// Properties
- //-------------------------------------------------------------------------
+ //-------------------------------------------------------------------------
+
+
+ /**
+ * Returns the file.
+ * @return File
+ */
+ public File getFile() {
+ return file;
+ }
+ /**
+ * Returns the uri.
+ * @return String
+ */
+ public String getUri() {
+ return uri;
+ }
- /**
- * Returns the file.
- * @return File
- */
- public File getFile() {
- return file;
- }
-
- /**
- * Returns the uri.
- * @return String
- */
- public String getUri() {
- return uri;
- }
-
- /**
- * Sets the file to use to test whether it exists or not.
- * @param file the file to test for
- */
- public void setFile(File file) {
- this.file = file;
- }
-
- /**
- * Sets the URI to use to test for availability.
- * The URI can be a full file based URL or a relative URI
- * or an absolute URI from the root context.
- *
- * @param uri the URI of the file to test
- */
- public void setUri(String uri) {
- this.uri = uri;
- }
+ /**
+ * Sets the file to use to test whether it exists or not.
+ * @param file the file to test for
+ */
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+ /**
+ * Sets the URI to use to test for availability.
+ * The URI can be a full file based URL or a relative URI
+ * or an absolute URI from the root context.
+ *
+ * @param uri the URI of the file to test
+ */
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org