View Javadoc
1   package org.codehaus.plexus.configuration.io;
2   
3   import java.io.IOException;
4   import java.io.InputStream;
5   import java.io.InputStreamReader;
6   import java.io.Reader;
7   
8   import org.codehaus.plexus.configuration.PlexusConfiguration;
9   import org.codehaus.plexus.configuration.PlexusConfigurationException;
10  import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
11  import org.codehaus.plexus.util.xml.Xpp3Dom;
12  import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
13  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
14  
15  public class XmlPlexusConfigurationReader
16      implements PlexusConfigurationReader
17  {
18  
19      public PlexusConfiguration read( InputStream inputStream )
20          throws IOException,
21              PlexusConfigurationException
22      {
23          return read( new InputStreamReader( inputStream ) );
24      }
25  
26      public PlexusConfiguration read( Reader reader )
27          throws IOException,
28              PlexusConfigurationException
29      {
30          try
31          {
32              Xpp3Dom dom = Xpp3DomBuilder.build( reader );
33  
34              return new XmlPlexusConfiguration( dom );
35          }
36          catch ( XmlPullParserException e )
37          {
38              throw new PlexusConfigurationException( "Failed to parse configuration resource!\nError was: \'"
39                  + e.getLocalizedMessage() + "\'", e );
40          }
41      }
42  }