ofbiz-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adri...@apache.org
Subject svn commit: r743436 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/UelFunctions.java
Date Wed, 11 Feb 2009 18:19:11 GMT
Author: adrianc
Date: Wed Feb 11 18:19:11 2009
New Revision: 743436

URL: http://svn.apache.org/viewvc?rev=743436&view=rev
Log:
Added util:urlExists(String url) function to the UEL functions. This should be helpful for
testing if a file exists before trying using it.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/UelFunctions.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/UelFunctions.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/UelFunctions.java?rev=743436&r1=743435&r2=743436&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/UelFunctions.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/UelFunctions.java Wed Feb 11
18:19:11 2009
@@ -18,7 +18,9 @@
  *******************************************************************************/
 package org.ofbiz.base.util.string;
 
+import java.io.InputStream;
 import java.lang.reflect.Method;
+import java.net.URL;
 import java.text.DateFormat;
 import java.util.Collection;
 import java.util.Locale;
@@ -29,6 +31,7 @@
 
 import javolution.util.FastMap;
 
+import org.ofbiz.base.location.FlexibleLocation;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilDateTime;
 
@@ -124,6 +127,7 @@
  * <tr><td><code>util:defaultTimeZone()</code></td><td>Returns
the default <code>TimeZone</code>.</td></tr>
  * <tr><td><code>util:size(Object)</code></td><td>Returns
the size of <code>Maps</code>,
  * <code>Collections</code>, and <code>Strings</code>. Invalid <code>Object</code>
types return -1.</td></tr>
+ * <tr><td><code>util:urlExists(String)</code></td><td>Returns
<code>true</code> if the specified URL exists.</td></tr>
  * </table>
  */
 public class UelFunctions {
@@ -224,6 +228,7 @@
                 this.functionMap.put("util:size", UelFunctions.class.getMethod("getSize",
Object.class));
                 this.functionMap.put("util:defaultLocale", Locale.class.getMethod("getDefault"));
                 this.functionMap.put("util:defaultTimeZone", TimeZone.class.getMethod("getDefault"));
+                this.functionMap.put("util:urlExists", UelFunctions.class.getMethod("urlExists",
String.class));
             } catch (Exception e) {
                 Debug.logWarning("Error while initializing UelFunctions.Functions instance:
" + e, module);
             }
@@ -368,4 +373,18 @@
         } catch (Exception e) {}
         return null;
     }
+
+    public static boolean urlExists(String str) {
+        boolean result = false;
+        try {
+            URL url = FlexibleLocation.resolveLocation(str);
+            if (url == null) {
+                return false;
+            }
+            InputStream is = url.openStream();
+            result = true;
+            is.close();
+        } catch (Exception e) {}
+        return result;
+    }
 }



Mime
View raw message