You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2010/03/15 23:54:16 UTC

svn commit: r923489 - /maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/source/CatalogArchetypeDataSource.java

Author: hboutemy
Date: Mon Mar 15 22:54:16 2010
New Revision: 923489

URL: http://svn.apache.org/viewvc?rev=923489&view=rev
Log:
preserve encoding when reading or writing XML descriptors

Modified:
    maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/source/CatalogArchetypeDataSource.java

Modified: maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/source/CatalogArchetypeDataSource.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/source/CatalogArchetypeDataSource.java?rev=923489&r1=923488&r2=923489&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/source/CatalogArchetypeDataSource.java (original)
+++ maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/source/CatalogArchetypeDataSource.java Mon Mar 15 22:54:16 2010
@@ -25,15 +25,16 @@ import org.apache.maven.archetype.catalo
 import org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Writer;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.WriterFactory;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Reader;
+import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -77,7 +78,7 @@ public class CatalogArchetypeDataSource
 
             try
             {
-                ArchetypeCatalog catalog = readCatalog( new FileReader( catalogFile ) );
+                ArchetypeCatalog catalog = readCatalog( ReaderFactory.newXmlReader( catalogFile ) );
 
                 return createArchetypeMap( catalog );
             }
@@ -85,6 +86,10 @@ public class CatalogArchetypeDataSource
             {
                 throw new ArchetypeDataSourceException( "The specific archetype catalog does not exist.", e );
             }
+            catch ( IOException e )
+            {
+                throw new ArchetypeDataSourceException( "Error reading archetype catalog.", e );
+            }
         }
         else
         {
@@ -110,13 +115,17 @@ public class CatalogArchetypeDataSource
             try
             {
                 getLogger().debug( "Reading the catalog " + catalogFile );
-                catalog = readCatalog( new FileReader( catalogFile ) );
+                catalog = readCatalog( ReaderFactory.newXmlReader( catalogFile ) );
             }
             catch ( FileNotFoundException ex )
             {
                 getLogger().debug( "Catalog file don't exist" );
                 catalog = new ArchetypeCatalog();
             }
+            catch ( IOException e )
+            {
+                throw new ArchetypeDataSourceException( "Error reading archetype catalog.", e );
+            }
         }
         else
         {
@@ -155,10 +164,10 @@ public class CatalogArchetypeDataSource
                                       File catalogFile )
         throws ArchetypeDataSourceException
     {
-        FileWriter writer = null;
+        Writer writer = null;
         try
         {
-            writer = new FileWriter( catalogFile );
+            writer = WriterFactory.newXmlWriter( catalogFile );
             catalogWriter.write( writer, catalog );
         }
         catch ( IOException e )
@@ -226,7 +235,7 @@ public class CatalogArchetypeDataSource
 
             try
             {
-                return readCatalog( new FileReader( catalogFile ) );
+                return readCatalog( ReaderFactory.newXmlReader( catalogFile ) );
 
             }
             catch ( FileNotFoundException e )
@@ -234,6 +243,10 @@ public class CatalogArchetypeDataSource
                 throw new ArchetypeDataSourceException( "The specific archetype catalog does not exist.",
                     e );
             }
+            catch ( IOException e )
+            {
+                throw new ArchetypeDataSourceException( "Error reading archetype catalog.", e );
+            }
         }
         else
         {