[Schmitzm-commits] r1468 - trunk/schmitzm-core/src/main/java/de/schmitzm/io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jan 28 17:30:35 CET 2011


Author: alfonx
Date: 2011-01-28 17:30:35 +0100 (Fri, 28 Jan 2011)
New Revision: 1468

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
Log:


Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2011-01-28 11:32:10 UTC (rev 1467)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2011-01-28 16:30:35 UTC (rev 1468)
@@ -60,6 +60,8 @@
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.filefilter.FileFilterUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
 import org.apache.commons.lang.SystemUtils;
 import org.apache.log4j.Logger;
 
@@ -92,6 +94,43 @@
 			FilterMode.ALL);
 
 	/**
+	 * This {@link IOFileFilter} returns <code>false</code> for files that
+	 * should be omitted during export and when calculating the size of a
+	 * {@link DpEntry} folder.
+	 */
+	public static final IOFileFilter BlacklistesFilesFilter = new IOFileFilter() {
+
+		@Override
+		public boolean accept(File file) {
+			if (file.getName().equals("Thumbs.db"))
+				return false;
+			if (file.getName().endsWith("~"))
+				return false;
+			if (file.getName().toLowerCase().endsWith("bak"))
+				return false;
+			if (file.getName().equals("build.xml"))
+				return false;
+			if (file.getName().equals("pom.xml"))
+				return false;
+			return true;
+		}
+
+		@Override
+		public boolean accept(File dir, String name) {
+			return accept(new File(dir, name));
+		}
+	};
+
+	/**
+	 * This filter omits SVN and CSV sub-folders.<br/>
+	 * This {@link IOFileFilter} returns <code>false</code> for folder that
+	 * should be omitted during export and when calculating the size of a
+	 * {@link DpEntry} folder or chen copying folders in general.
+	 */
+	public static final IOFileFilter BlacklistedFoldersFilter = FileFilterUtils
+			.makeCVSAware(FileFilterUtils.makeSVNAware(null));
+
+	/**
 	 * Modi fuer Filter.
 	 * 
 	 * @see IOUtil#createSimpleFileFilter(String, FilterMode)
@@ -600,103 +639,107 @@
 		};
 	}
 
-    /**
-     * A replacement for File.toURI().toURL().
-     * <p>
-     * The handling of file.toURL() is broken; the handling of file.toURI().toURL() is known
-     * to be broken on a few platforms like mac. We have the urlToFile( URL ) method that
-     * is able to untangle both these problems and we use it in the geotools library.
-     * <p>
-     * However occasionally we need to pick up a file and hand it to a third party library
-     * like EMF; this method performs a couple of sanity checks which we can use to prepare
-     * a good URL reference to a file in these situtations.
-     * 
-     * @param file
-     * @return URL
-     */
-    public static URL fileToURL(File file) {
-        try {
-            URL url = file.toURI().toURL();
-            String string = url.toExternalForm();
-            if( string.contains("+")){
-                // this represents an invalid URL created using either
-                // file.toURL(); or
-                // file.toURI().toURL() on a specific version of Java 5 on Mac
-                string = string.replace("+","%2B");
-            }
-            if( string.contains(" ")){
-                // this represents an invalid URL created using either
-                // file.toURL(); or
-                // file.toURI().toURL() on a specific version of Java 5 on Mac
-                string = string.replace(" ","%20");
-            }
-            return new URL( string );
-        } catch (MalformedURLException e) {
-            return null;
-        }
-    }
-    
-    /**
-     * Takes a URL and converts it to a File. The attempts to deal with 
-     * Windows UNC format specific problems, specifically files located
-     * on network shares and different drives.
-     * 
-     * If the URL.getAuthority() returns null or is empty, then only the
-     * url's path property is used to construct the file. Otherwise, the
-     * authority is prefixed before the path.
-     * 
-     * It is assumed that url.getProtocol returns "file".
-     * 
-     * Authority is the drive or network share the file is located on.
-     * Such as "C:", "E:", "\\fooServer"
-     * 
-     * @param url a URL object that uses protocol "file"
-     * @return a File that corresponds to the URL's location
-     */
-    public static File urlToFile(URL url) {
-        if( !"file".equals(url.getProtocol())){
-            return null; // not a File URL
-        }
-        String string = url.toExternalForm();
-        if( string.contains("+")){
-            // this represents an invalid URL created using either
-            // file.toURL(); or
-            // file.toURI().toURL() on a specific version of Java 5 on Mac
-            string = string.replace("+","%2B");
-        }
-        try {
-            string = URLDecoder.decode(string, "UTF-8");
-        } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException("Could not decode the URL to UTF-8 format", e);
-        }
-        
-        String path3;
+	/**
+	 * A replacement for File.toURI().toURL().
+	 * <p>
+	 * The handling of file.toURL() is broken; the handling of
+	 * file.toURI().toURL() is known to be broken on a few platforms like mac.
+	 * We have the urlToFile( URL ) method that is able to untangle both these
+	 * problems and we use it in the geotools library.
+	 * <p>
+	 * However occasionally we need to pick up a file and hand it to a third
+	 * party library like EMF; this method performs a couple of sanity checks
+	 * which we can use to prepare a good URL reference to a file in these
+	 * situtations.
+	 * 
+	 * @param file
+	 * @return URL
+	 */
+	public static URL fileToURL(File file) {
+		try {
+			URL url = file.toURI().toURL();
+			String string = url.toExternalForm();
+			if (string.contains("+")) {
+				// this represents an invalid URL created using either
+				// file.toURL(); or
+				// file.toURI().toURL() on a specific version of Java 5 on Mac
+				string = string.replace("+", "%2B");
+			}
+			if (string.contains(" ")) {
+				// this represents an invalid URL created using either
+				// file.toURL(); or
+				// file.toURI().toURL() on a specific version of Java 5 on Mac
+				string = string.replace(" ", "%20");
+			}
+			return new URL(string);
+		} catch (MalformedURLException e) {
+			return null;
+		}
+	}
 
-        String simplePrefix = "file:/";
-        String standardPrefix = "file://";
-        String os = System.getProperty("os.name");
-        
-        if (os.toUpperCase().contains("WINDOWS") && string.startsWith(standardPrefix)) {
-        	// win32: host/share reference
-        	path3 = string.substring(standardPrefix.length()-2);
-        }
-        else if( string.startsWith(standardPrefix) ){
-            path3 = string.substring( standardPrefix.length() );
-        } else if( string.startsWith(simplePrefix)){
-            path3 = string.substring( simplePrefix.length()-1 );            
-        } else {
-            String auth = url.getAuthority();
-            String path2 = url.getPath().replace("%20", " ");
-            if (auth != null && !auth.equals("")) {
-                path3 = "//" + auth + path2;
-            } else {
-                path3 = path2;
-            }
-        }
-        
-        return new File(path3);
-    }
+	/**
+	 * Takes a URL and converts it to a File. The attempts to deal with Windows
+	 * UNC format specific problems, specifically files located on network
+	 * shares and different drives.
+	 * 
+	 * If the URL.getAuthority() returns null or is empty, then only the url's
+	 * path property is used to construct the file. Otherwise, the authority is
+	 * prefixed before the path.
+	 * 
+	 * It is assumed that url.getProtocol returns "file".
+	 * 
+	 * Authority is the drive or network share the file is located on. Such as
+	 * "C:", "E:", "\\fooServer"
+	 * 
+	 * @param url
+	 *            a URL object that uses protocol "file"
+	 * @return a File that corresponds to the URL's location
+	 */
+	public static File urlToFile(URL url) {
+		if (!"file".equals(url.getProtocol())) {
+			return null; // not a File URL
+		}
+		String string = url.toExternalForm();
+		if (string.contains("+")) {
+			// this represents an invalid URL created using either
+			// file.toURL(); or
+			// file.toURI().toURL() on a specific version of Java 5 on Mac
+			string = string.replace("+", "%2B");
+		}
+		try {
+			string = URLDecoder.decode(string, "UTF-8");
+		} catch (UnsupportedEncodingException e) {
+			throw new RuntimeException(
+					"Could not decode the URL to UTF-8 format", e);
+		}
 
+		String path3;
+
+		String simplePrefix = "file:/";
+		String standardPrefix = "file://";
+		String os = System.getProperty("os.name");
+
+		if (os.toUpperCase().contains("WINDOWS")
+				&& string.startsWith(standardPrefix)) {
+			// win32: host/share reference
+			path3 = string.substring(standardPrefix.length() - 2);
+		} else if (string.startsWith(standardPrefix)) {
+			path3 = string.substring(standardPrefix.length());
+		} else if (string.startsWith(simplePrefix)) {
+			path3 = string.substring(simplePrefix.length() - 1);
+		} else {
+			String auth = url.getAuthority();
+			String path2 = url.getPath().replace("%20", " ");
+			if (auth != null && !auth.equals("")) {
+				path3 = "//" + auth + path2;
+			} else {
+				path3 = path2;
+			}
+		}
+
+		return new File(path3);
+	}
+
 	/**
 	 * Loescht Dateien oder Verzeichnisse in einem Verzeichnis. Das Verzeichnis
 	 * selbst wird dabei NICHT geloescht, auch wenn es am Ende leer ist!



More information about the Schmitzm-commits mailing list