Author: hboutemy
Date: Sat Dec 25 23:04:31 2010
New Revision: 1052816
URL: http://svn.apache.org/viewvc?rev=1052816&view=rev
Log:
o closed streams
o avoided platform encoding when reading XML file
Modified:
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java
Modified:
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java?rev=1052816&r1=1052815&r2=1052816&view=diff
==============================================================================
---
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java
(original)
+++
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/changes/schema/DefaultChangesSchemaValidator.java
Sat Dec 25 23:04:31 2010
@@ -20,9 +20,9 @@ package org.apache.maven.plugin.changes.
*/
import java.io.File;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.Reader;
import java.util.Map;
import javax.xml.transform.stream.StreamSource;
@@ -31,6 +31,8 @@ import javax.xml.validation.SchemaFactor
import javax.xml.validation.Validator;
import org.codehaus.plexus.util.FastMap;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
import org.xml.sax.SAXException;
/**
@@ -55,6 +57,7 @@ public class DefaultChangesSchemaValidat
public XmlValidationHandler validateXmlWithSchema( File file, String
schemaVersion, boolean failOnValidationError )
throws SchemaValidatorException
{
+ Reader reader = null;
try
{
String schemaPath = CHANGES_SCHEMA_PATH + "changes-" +
schemaVersion + ".xsd";
@@ -67,7 +70,9 @@ public class DefaultChangesSchemaValidat
validator.setErrorHandler( baseHandler );
- validator.validate( new StreamSource( new FileReader( file ) ) );
+ reader = new XmlStreamReader( file );
+
+ validator.validate( new StreamSource( reader ) );
return baseHandler;
}
@@ -83,6 +88,10 @@ public class DefaultChangesSchemaValidat
{
throw new SchemaValidatorException( "Exception : " +
e.getMessage(), e );
}
+ finally
+ {
+ IOUtil.close( reader );
+ }
}
public Schema getSchema( String schemaPath )
@@ -115,9 +124,15 @@ public class DefaultChangesSchemaValidat
throw new NullPointerException( " impossible to load schema with
path " + uriSchema );
}
- //newInstance de SchemaFactory not ThreadSafe
- return SchemaFactory.newInstance( W3C_XML_SCHEMA ).newSchema( new
StreamSource( is ) );
-
+ try
+ {
+ //newInstance de SchemaFactory not ThreadSafe
+ return SchemaFactory.newInstance( W3C_XML_SCHEMA ).newSchema( new
StreamSource( is ) );
+ }
+ finally
+ {
+ IOUtil.close( is );
+ }
}
/**
@@ -136,6 +151,4 @@ public class DefaultChangesSchemaValidat
}
}
-
-
}