Re: Problems with setting up css-validator

On Tue, Jan 20, 2009 at 10:40:34AM +0100, Miklos Vajna <vmiklos@dsd.sztaki.hu> wrote:
> And now I get:
> 
> $ java -cp css-validator.jar:lib/jigsaw.jar org.w3c.css.css.CssValidator http://www.w3.org/
> class org.w3c.css.properties.PropertiesLoader: Error while loading default config
> java.lang.NullPointerException
>         at org.w3c.css.properties.PropertiesLoader.<clinit>(PropertiesLoader.java:148)
>         at org.w3c.css.css.CssValidator.<init>(CssValidator.java:61)
>         at org.w3c.css.css.CssValidator.main(CssValidator.java:73)
> Exception in thread "main" java.lang.NullPointerException
>         at java.util.Hashtable.put(Hashtable.java:394)
>         at org.w3c.css.css.CssValidator.<init>(CssValidator.java:61)
>         at org.w3c.css.css.CssValidator.main(CssValidator.java:73)

I managed to get a bit further.

The problem was that the recent "enhanced target war" commit excluded
the properties from the jar file.

This fixed the problem for me:

diff --git a/build.xml b/build.xml
index c2cc277..70968f0 100644
--- a/build.xml
+++ b/build.xml
@@ -86,8 +86,17 @@
 		</javac>
 		<copy todir="./build">
 		    <fileset dir="./">
-		      <exclude name="*"/>
-		      <exclude name="**"/>
+			    <exclude name="**/*.java"/>
+			    <exclude name="*.html*"/>
+			    <exclude name="*.css"/>
+			    <exclude name="*.bat"/>
+			    <exclude name="*.bat"/>
+			    <exclude name="*.xml"/>
+			    <exclude name="*.ico"/>
+			    <exclude name="*.cvs"/>
+			    <exclude name="**/style/*"/>
+			    <exclude name="**/images/*"/>
+			    <exclude name="build/**"/>
 		    </fileset>
 		</copy>
 	</target>

Then I got again those resource loading problem error messages:

org.w3c.css.util.Messages: couldn't load properties de
  java.io.FileNotFoundException:
/file:/home/vmiklos/w3c/css-validator/css-validator.jar!/org/w3c/css/util/Messages.properties.de
(No such file or directory)

I searched the list archive, and the trick to use getResourceAsStream()
instead of getResource() works.

Here is the patch I used:

diff --git a/org/w3c/css/css/StyleSheetGenerator.java b/org/w3c/css/css/StyleSheetGenerator.java
index 54bdd4c..408cbd5 100644
--- a/org/w3c/css/css/StyleSheetGenerator.java
+++ b/org/w3c/css/css/StyleSheetGenerator.java
@@ -55,11 +55,9 @@ public class StyleSheetGenerator extends StyleReport {
     private static Utf8Properties availablePropertiesURL;
 
     static {
-	URL url;
 	availableFormat = new Utf8Properties();
 	try {
-	    url = Messages.adjustURL(StyleSheetGenerator.class.getResource("format.properties"));
-	    java.io.InputStream f = url.openStream();
+	    java.io.InputStream f = StyleSheetGenerator.class.getResourceAsStream("format.properties");
 	    availableFormat.load(f);
 	    f.close();
 	} catch (Exception e) {
@@ -69,8 +67,7 @@ public class StyleSheetGenerator extends StyleReport {
 
 	availablePropertiesURL = new Utf8Properties();
 	try {
-	    url = Messages.adjustURL(StyleSheetGenerator.class.getResource("urls.properties"));
-	    java.io.InputStream f = url.openStream();
+	    java.io.InputStream f = StyleSheetGenerator.class.getResourceAsStream("urls.properties");
 	    availablePropertiesURL.load(f);
 	    f.close();
 	} catch (Exception e) {
diff --git a/org/w3c/css/util/Messages.java b/org/w3c/css/util/Messages.java
index 1b535f6..8a783e2 100644
--- a/org/w3c/css/util/Messages.java
+++ b/org/w3c/css/util/Messages.java
@@ -163,8 +163,7 @@ public class Messages {
 	static {
 		Utf8Properties tmp;
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.de"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.de");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -184,8 +183,7 @@ public class Messages {
 		// ------------------------------------------------
 
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.en"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.en");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -202,8 +200,7 @@ public class Messages {
 		// ------------------------------------------------
 
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.es"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.es");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -221,8 +218,7 @@ public class Messages {
 		// -----------------------
 
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.fr"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.fr");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -240,8 +236,7 @@ public class Messages {
 		// -----------------------
 
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.ko"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.ko");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -258,8 +253,7 @@ public class Messages {
 		// -----------------------
 		
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.it"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.it");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -276,8 +270,7 @@ public class Messages {
 		// -----------------------
 
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.nl"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.nl");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -294,8 +287,7 @@ public class Messages {
 		// -----------------------
 
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.ja"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.ja");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -312,8 +304,7 @@ public class Messages {
 		// -----------------------
 		
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.pl-PL"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.pl-PL");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -332,8 +323,7 @@ public class Messages {
 		// -----------------------
 		
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.pt-BR"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.pt-BR");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -351,8 +341,7 @@ public class Messages {
 		}
 		// -----------------------
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.ru"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.ru");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -368,8 +357,7 @@ public class Messages {
 
 		// -----------------------
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.sv"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.sv");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);
@@ -386,8 +374,7 @@ public class Messages {
 		// -----------------------
 
 		try {
-			URL url = adjustURL(Messages.class.getResource("Messages.properties.zh-cn"));
-			java.io.InputStream f = url.openStream();
+			java.io.InputStream f = Messages.class.getResourceAsStream("Messages.properties.zh-cn");
 			try {
 				tmp = new Utf8Properties();
 				tmp.load(f);

And now I get:

$ java -cp css-validator.jar:lib/commons-collections-3.2.1.jar:lib/commons-lang-2.4.jar:lib/jigsaw.jar:lib/tagsoup-1.2.jar:lib/velocity-1.6.1.jar:lib/xercesImpl.jar:lib/xml-apis.jar org.w3c.css.css.CssValidator http://www.w3.org/
{output=text, medium=all, warning=2, profile=css21, lang=en}
Jan 20, 2009 11:28:23 AM org.apache.velocity.runtime.log.JdkLogChute log
SEVERE: ResourceManager : unable to find resource 'text.properties' in any resource loader.
Unable to find resource 'text.properties'
org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'text.properties'
        at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:483)
        at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:354)
        at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1400)
        at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1380)
        at org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.java:305)
        at org.apache.velocity.app.Velocity.getTemplate(Velocity.java:383)
        at org.w3c.css.css.StyleSheetGenerator.<init>(StyleSheetGenerator.java:159)
        at org.w3c.css.css.StyleReportFactory.getStyleReport(StyleReportFactory.java:19)
        at org.w3c.css.css.CssValidator.handleRequest(CssValidator.java:178)
        at org.w3c.css.css.CssValidator.main(CssValidator.java:151)
java.lang.NullPointerException
        at org.w3c.css.css.StyleSheetGenerator.print(StyleSheetGenerator.java:417)
        at org.w3c.css.css.CssValidator.handleRequest(CssValidator.java:187)
        at org.w3c.css.css.CssValidator.main(CssValidator.java:151)

Now that one seems to be in the velocity code.

Any suggestion? :)

Thanks.

Received on Tuesday, 20 January 2009 10:43:11 UTC