You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2010/01/02 17:52:12 UTC

svn commit: r895238 - /incubator/wookie/trunk/src/org/apache/wookie/util/WidgetPackageUtils.java

Author: scottbw
Date: Sat Jan  2 16:52:11 2010
New Revision: 895238

URL: http://svn.apache.org/viewvc?rev=895238&view=rev
Log:
Locates all valid files for default icons and start files; before this fix only the first valid file found was added to the list, however for instance level localization we need to include all valid file sets for each supported locale.

Modified:
    incubator/wookie/trunk/src/org/apache/wookie/util/WidgetPackageUtils.java

Modified: incubator/wookie/trunk/src/org/apache/wookie/util/WidgetPackageUtils.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/util/WidgetPackageUtils.java?rev=895238&r1=895237&r2=895238&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/util/WidgetPackageUtils.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/util/WidgetPackageUtils.java Sat Jan  2 16:52:11 2010
@@ -61,6 +61,22 @@
 	 * @throws Exception
 	 */
 	public static String locateFilePath(String path, String[] locales, ZipFile zip) throws Exception{
+		String[] paths = locateFilePaths(path, locales, zip);
+		if (paths != null && paths.length != 0) return paths[0];
+		return null;
+	}
+	
+	/**
+	 * Returns the set of valid file paths for a given resource. All valid paths are returned, starting
+	 * with localized versions for supported locales before the root version (if present).
+	 * @param path
+	 * @param locales
+	 * @param zip
+	 * @return
+	 * @throws Exception
+	 */
+	public static String[] locateFilePaths(String path, String[] locales, ZipFile zip) throws Exception{
+		ArrayList<String> paths = new ArrayList<String>();
 		if (path.startsWith("/")) path = path.substring(1, path.length());
 		String[] pathComponents = path.split("/");
 		if ("locales".equalsIgnoreCase(pathComponents[0])){
@@ -72,13 +88,12 @@
 			String localePath = "locales/"+locale.trim()+"/"+path;
 			if (zip.getEntry(localePath) != null){
 				if (zip.getEntry(localePath).isDirectory()) throw new Exception();
-				return localePath;
+				paths.add(localePath);
 			}
 		}
 		// Look in root folder
-		if (zip.getEntry(path) == null) return null;
-		if (zip.getEntry(path).isDirectory()) throw new Exception();
-		return path;
+		if (zip.getEntry(path) != null && !zip.getEntry(path).isDirectory()) paths.add(path);
+		return (String[]) paths.toArray(new String[paths.size()]);
 	}
 	
 	/**
@@ -108,8 +123,10 @@
 		ArrayList<String> content = new ArrayList<String>();
 		for (String start: defaults){
 			try {
-				start = locateFilePath(start, locales, zip);
-				if (start != null) content.add(start);
+				String[] paths = locateFilePaths(start, locales, zip);
+				if (paths != null){
+					for (String path:paths) content.add(path);
+				}
 			} catch (Exception e) {
 				// ignore and move onto next
 			}