Author: lindner
Date: Sun Jan 11 21:07:49 2009
New Revision: 733625
URL: http://svn.apache.org/viewvc?rev=733625&view=rev
Log:
SHINDIG-838 | Patch from Vincent Siveton | Improve Exception when file does not
exist
Modified:
incubator/shindig/branches/1.0.x-incubating/ (props changed)
incubator/shindig/branches/1.0.x-incubating/java/common/src/main/java/org/apache/shindig/common/JsonContainerConfig.java
incubator/shindig/branches/1.0.x-incubating/java/common/src/test/java/org/apache/shindig/common/AllTests.java
(props changed)
incubator/shindig/branches/1.0.x-incubating/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsFeatureLoader.java
incubator/shindig/branches/1.0.x-incubating/java/gadgets/src/test/java/org/apache/shindig/gadgets/JsFeatureLoaderTest.java
Propchange: incubator/shindig/branches/1.0.x-incubating/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Jan 11 21:07:49 2009
@@ -1 +1 @@
-/incubator/shindig/trunk:724511-724522,724874,724915,724939,726597,727032-727033,727048,733593,733596-733618
+/incubator/shindig/trunk:724511-724522,724874,724915,724939,726597,727032-727033,727048,733593,733596-733622
Modified:
incubator/shindig/branches/1.0.x-incubating/java/common/src/main/java/org/apache/shindig/common/JsonContainerConfig.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/java/common/src/main/java/org/apache/shindig/common/JsonContainerConfig.java?rev=733625&r1=733624&r2=733625&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/java/common/src/main/java/org/apache/shindig/common/JsonContainerConfig.java
(original)
+++
incubator/shindig/branches/1.0.x-incubating/java/common/src/main/java/org/apache/shindig/common/JsonContainerConfig.java
Sun Jan 11 21:07:49 2009
@@ -37,6 +37,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;
@@ -135,9 +136,14 @@
LOG.info("Reading container config: " + file.getName());
if (file.isDirectory()) {
loadFiles(file.listFiles());
- } else if (file.getName().endsWith(".js") ||
- file.getName().endsWith(".json")) {
+ } else if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".js")
||
+
file.getName().toLowerCase(Locale.ENGLISH).endsWith(".json")) {
+ if (!file.exists()) {
+ throw new ContainerConfigException("The file '" +
file.getAbsolutePath() + "' doesn't exist.");
+ }
loadFromString(ResourceLoader.getContent(file));
+ } else {
+ LOG.finest(file.getAbsolutePath() + " doesn't seem to be a JS or
JSON file.");
}
}
} catch (IOException e) {
Propchange:
incubator/shindig/branches/1.0.x-incubating/java/common/src/test/java/org/apache/shindig/common/AllTests.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Jan 11 21:07:49 2009
@@ -0,0 +1 @@
+/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/AllTests.java:733619-733622
Modified:
incubator/shindig/branches/1.0.x-incubating/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsFeatureLoader.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsFeatureLoader.java?rev=733625&r1=733624&r2=733625&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsFeatureLoader.java
(original)
+++
incubator/shindig/branches/1.0.x-incubating/java/gadgets/src/main/java/org/apache/shindig/gadgets/JsFeatureLoader.java
Sun Jan 11 21:07:49 2009
@@ -33,11 +33,9 @@
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;
@@ -88,7 +86,7 @@
List<String> resources = Lists.newArrayList();
for(String resource :
StringUtils.split(ResourceLoader.getContent(location), "[\r\n]+")) {
// Skip blank/commented lines
- if (StringUtils.trim(resource).length() > 0 && resource.charAt(0)
!= '#') {
+ if (StringUtils.trim(resource).length() > 0 &&
resource.charAt(0) != '#') {
resources.add(StringUtils.trim(resource));
}
}
@@ -140,11 +138,17 @@
for (File file : files) {
if (file.isDirectory()) {
loadFiles(file.listFiles(), features);
- } else if (file.getName().endsWith(".xml")) {
+ } else if (file.getName().toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
+ if (!file.exists()) {
+ throw new GadgetException(GadgetException.Code.INVALID_PATH,
+ "The file '" + file.getAbsolutePath() +
"' doesn't exist.");
+ }
ParsedFeature feature = processFile(file);
if (feature != null) {
features.add(feature);
}
+ } else {
+ logger.finest(file.getAbsolutePath() + " doesn't seem to be an XML
file.");
}
}
}
Modified:
incubator/shindig/branches/1.0.x-incubating/java/gadgets/src/test/java/org/apache/shindig/gadgets/JsFeatureLoaderTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/java/gadgets/src/test/java/org/apache/shindig/gadgets/JsFeatureLoaderTest.java?rev=733625&r1=733624&r2=733625&view=diff
==============================================================================
---
incubator/shindig/branches/1.0.x-incubating/java/gadgets/src/test/java/org/apache/shindig/gadgets/JsFeatureLoaderTest.java
(original)
+++
incubator/shindig/branches/1.0.x-incubating/java/gadgets/src/test/java/org/apache/shindig/gadgets/JsFeatureLoaderTest.java
Sun Jan 11 21:07:49 2009
@@ -162,5 +162,21 @@
JsLibrary lib2 = getJsLib(map.get(ALT_FEATURE_NAME));
assertEquals(ALT_JS_CONTENT, lib2.getContent());
+
+ // Test with comma in the path
+ file1 = makeFeatureFile("test,test", DEF_JS_CONTENT);
+ file2 = makeFeatureFile("test2,test2", ALT_JS_CONTENT);
+
+ try {
+ loader.loadFeatures(file1.getAbsolutePath() +
+ JsFeatureLoader.FILE_SEPARATOR +
+ file2.getAbsolutePath(), registry);
+ } catch (GadgetException e ) {
+ if (!e.getCode().equals(GadgetException.Code.INVALID_PATH)) {
+ throw e;
+ }
+
+ assertTrue("Invalid path catched", true);
+ }
}
}
\ No newline at end of file