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/04/10 16:58:06 UTC

svn commit: r932740 - in /incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c: W3CWidgetFactory.java util/WidgetPackageUtils.java

Author: scottbw
Date: Sat Apr 10 14:58:06 2010
New Revision: 932740

URL: http://svn.apache.org/viewvc?rev=932740&view=rev
Log:
Conduct additional input validation on the W3CWidgetFactory, throwing exceptions for missing or read-only output directories, and invoke methods on WidgetPackageUtils using a File rather than a path String for the widget output folder. Also added more comments.

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

Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidgetFactory.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidgetFactory.java?rev=932740&r1=932739&r2=932740&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidgetFactory.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/W3CWidgetFactory.java Sat Apr 10 14:58:06 2010
@@ -14,6 +14,8 @@
 package org.apache.wookie.w3c;
 
 import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
 
 import org.apache.wookie.w3c.exceptions.BadManifestException;
 import org.apache.wookie.w3c.exceptions.BadWidgetZipFileException;
@@ -50,16 +52,16 @@ import org.apache.wookie.w3c.util.Widget
  */
 public class W3CWidgetFactory {
 	
-	private String outputDirectory;
+	private File outputDirectory;
 	private IStartPageProcessor startPageProcessor;
 	private String[] locales;
 	private String localPath;
 	private String[] features;
 
-	public String[] getFeatures() {
-		return features;
-	}
-
+	/**
+	 * Set the features to be included when parsing widgets
+	 * @param features
+	 */
 	public void setFeatures(String[] features) {
 		this.features = features;
 	}
@@ -77,36 +79,45 @@ public class W3CWidgetFactory {
 			
 		};
 	}
-
-	public String getOutputDirectory() {
-		return outputDirectory;
-	}
-
-	public void setOutputDirectory(String outputDirectory) {
-		this.outputDirectory = outputDirectory;
-	}
-
-	public IStartPageProcessor getStartPageProcessor() {
-		return startPageProcessor;
+	
+	/**
+	 * Set the directory to use to save widgets.
+	 * @param outputDirectory
+	 * @throws IOException if the directory does not exist
+	 */
+	public void setOutputDirectory(final String outputDirectory) throws IOException {
+		if (outputDirectory == null) throw new NullPointerException();
+		File file = new File(outputDirectory);
+		if (!file.exists()) throw new FileNotFoundException("the output directory does not exist");
+		if (!file.canWrite()) throw new IOException("the output directory cannot be written to");
+		if (!file.isDirectory()) throw new IOException("the output directory is not a folder");
+		this.outputDirectory = file;
 	}
 
-	public void setStartPageProcessor(IStartPageProcessor startPageProcessor) {
+	/**
+	 * Set the start page processor to use when parsing widgets
+	 * @param startPageProcessor
+	 */
+	public void setStartPageProcessor(final IStartPageProcessor startPageProcessor) {
 		this.startPageProcessor = startPageProcessor;
 	}
 
-	public String[] getLocales() {
-		return locales;
-	}
-
-	public void setLocales(String[] locales) {
+	/**
+	 * Set the supported locales to be used when parsing widgets
+	 * @param locales
+	 */
+	public void setLocales(final String[] locales) {
+		if (locales == null) throw new NullPointerException("locales cannot be specified as Null");
 		this.locales = locales;
 	}
 
-	public String getLocalPath() {
-		return localPath;
-	}
-
-	public void setLocalPath(String localPath) {
+	/**
+	 * Set the base URL to use
+	 * @param localPath
+	 * @throws Exception 
+	 */
+	public void setLocalPath(final String localPath){
+		if (localPath == null) throw new NullPointerException("local path cannot be set to Null");
 		this.localPath = localPath;
 	};
 	
@@ -119,7 +130,8 @@ public class W3CWidgetFactory {
 	 * @throws BadWidgetZipFileException if there is a problem with the zip package
 	 * @throws BadManifestException if there is a problem with the config.xml manifest file in the package
 	 */
-	public W3CWidget parse(File zipFile) throws BadWidgetZipFileException, BadManifestException{
+	public W3CWidget parse(final File zipFile) throws Exception, BadWidgetZipFileException, BadManifestException{
+		if (outputDirectory == null) throw new Exception("No output directory has been set; use setOutputDirectory(File) to set the location to output widget files");
 		return WidgetPackageUtils.processWidgetPackage(zipFile, localPath, outputDirectory, locales, startPageProcessor, features);
 	}
 }

Modified: incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/util/WidgetPackageUtils.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/util/WidgetPackageUtils.java?rev=932740&r1=932739&r2=932740&view=diff
==============================================================================
--- incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/util/WidgetPackageUtils.java (original)
+++ incubator/wookie/trunk/parser/java/src/org/apache/wookie/w3c/util/WidgetPackageUtils.java Sat Apr 10 14:58:06 2010
@@ -136,9 +136,9 @@ public class WidgetPackageUtils {
 		return (String[]) content.toArray(new String[content.size()]);	
 	}
 	
-	public static File createUnpackedWidgetFolder(String widgetFolder, String folder) throws IOException{
+	public static File createUnpackedWidgetFolder(File widgetFolder, String folder) throws IOException{
 		folder = convertIdToFolderName(folder);
-		String serverPath = widgetFolder + File.separator + folder;
+		String serverPath = widgetFolder.getPath() + File.separator + folder;
 		File file = new File(convertPathToPlatform(serverPath));
 		return file;
 	}
@@ -228,7 +228,7 @@ public class WidgetPackageUtils {
 		return true;
 	}
 	
-	public static W3CWidget processWidgetPackage(File zipFile, String localWidgetPath, String WIDGETFOLDER, String[] locales, IStartPageProcessor processor, String[] features) throws BadWidgetZipFileException, BadManifestException{
+	public static W3CWidget processWidgetPackage(File zipFile, String localWidgetPath, File WIDGETFOLDER, String[] locales, IStartPageProcessor processor, String[] features) throws BadWidgetZipFileException, BadManifestException{
 		ZipFile zip;
 		try {
 			zip = new ZipFile(zipFile);
@@ -253,7 +253,7 @@ public class WidgetPackageUtils {
 					File startFile = new File(newWidgetFolder.getCanonicalPath() + File.separator + content.getSrc());
 					String relativestartUrl = (WidgetPackageUtils.getURLForWidget(localWidgetPath, manifestIdentifier, content.getSrc())); 					
 					content.setSrc(relativestartUrl);
-					if(startFile.exists()){		
+					if(startFile.exists() && processor != null){		
 						processor.processStartFile(startFile, widgetModel);
 					}	
 				}
@@ -273,7 +273,7 @@ public class WidgetPackageUtils {
 			} catch (BadManifestException e) {
 				throw e;
 			} catch (Exception e){
-				throw new BadManifestException();
+				throw new BadManifestException(e);
 			}
 		}
 		else{