commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@gmail.com>
Subject Re: Validator MalformedURLException
Date Mon, 26 Feb 2007 15:18:52 GMT
Is your InputStream null? I think you need to change the following line:

    getClass().getResourceAsStream(validationDefinition);

to

    in = getClass().getResourceAsStream(validationDefinition);

Niall

On 2/26/07, Lian Ort <lianril@googlemail.com> wrote:
> Hello,
> i try to use Commons Validator outside of Struts (in an simple java
> application context). Therefore i wrote a simply xml:
>
> <!DOCTYPE form-validation PUBLIC
>      "-//Apache Software Foundation//DTD Commons Validator Rules
> Configuration 1.1//EN"
>      "http://jakarta.apache.org/commons/dtds/validator_1_1.dtd">
>
>
> <form-validation>
>
> </form-validation>
>
> The code for is simple and is mostly copied from the example
> ValidateExample.java (i put that code in an init method):
>     private boolean init() {
>         InputStream in = null;
>         boolean initOk = true;
>
>         apps = null;
>         try {
>             apps = ResourceBundle.getBundle(resourceName);
>         } catch (Exception lEx) {
>             log.error("Error during open of properties file " + resourceName
> + ": ", lEx);
>         }
>
>         try {
>
>             getClass().getResourceAsStream(validationDefinition);
>             resources = new ValidatorResources(in);
>
>         } catch (Exception ex) {
>             log.error("Error during reading the validation definition file
> "+validationDefinition+":\n"+ex.toString()+"\n");
>             ex.printStackTrace(System.err);
>             initOk = false;
>         } finally {
>             // Make sure we close the input stream.
>             if (in != null) {
>                  try {
>                      in.close();
>                  } catch (Exception ignore) {}
>             }
>         }
>         return initOk;
>     }
>
> This compiles in Eclipse.
>
> At runtime there is an MalformedURLException thrown at the line "resources =
> new ValidatorResources(in);"
>
> java.net.MalformedURLException
>         at java.net.URL.<init>(Unknown Source)
>         at java.net.URL.<init>(Unknown Source)
>         at java.net.URL.<init>(Unknown Source)
>         at
> com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown
> Source)
>         at
> com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown
> Source)
>         at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
> Source)
>         at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
> Source)
>         at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
> Source)
>         at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
> Source)
>         at org.apache.commons.digester.Digester.parse(Digester.java:1765)
>         at org.apache.commons.validator.ValidatorResources.<init>(
> ValidatorResources.java:156)
>         at org.apache.commons.validator.ValidatorResources.<init>(
> ValidatorResources.java:133)
>         at de.bgnet.dmig.pdm.imp.validation.ImportValidationTest.init(
> ImportValidationTest.java:75)
>         at de.bgnet.dmig.pdm.imp.validation.ImportValidationTest.getInstance
> (ImportValidationTest.java:41)
>         at de.bgnet.dmig.pdm.imp.processing.PdmImport.init(PdmImport.java
> :119)
>         at de.bgnet.dmig.pdm.PdmBatch.init(PdmBatch.java:81)
>         at de.bgnet.dmig.pdm.PdmBatch.main(PdmBatch.java:38)
>
> I have no clue what goes wrong here. When i compile and run the example from
> the Validator package, everything goes fine.
>
> I would appreciate any help.
> Many thanks,
> Lian
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message