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 implements PlexusConfigurationReader {
16  
17      public PlexusConfiguration read(InputStream inputStream) throws IOException, PlexusConfigurationException {
18          return read(new InputStreamReader(inputStream));
19      }
20  
21      public PlexusConfiguration read(Reader reader) throws IOException, PlexusConfigurationException {
22          try {
23              Xpp3Dom dom = Xpp3DomBuilder.build(reader);
24  
25              return new XmlPlexusConfiguration(dom);
26          } catch (XmlPullParserException e) {
27              throw new PlexusConfigurationException(
28                      "Failed to parse configuration resource!\nError was: \'" + e.getLocalizedMessage() + "\'", e);
29          }
30      }
31  }