1 package org.apache.maven.artifact.repository.metadata.io;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.Reader;
26 import java.util.Map;
27
28 import org.apache.commons.lang3.Validate;
29 import org.apache.maven.artifact.repository.metadata.Metadata;
30 import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
31 import org.codehaus.plexus.component.annotations.Component;
32 import org.codehaus.plexus.util.IOUtil;
33 import org.codehaus.plexus.util.ReaderFactory;
34 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
35
36
37
38
39
40
41 @Component( role = MetadataReader.class )
42 public class DefaultMetadataReader
43 implements MetadataReader
44 {
45
46 public Metadata read( File input, Map<String, ?> options )
47 throws IOException
48 {
49 Validate.notNull( input, "input cannot be null" );
50
51 Metadata metadata = read( ReaderFactory.newXmlReader( input ), options );
52
53 return metadata;
54 }
55
56 public Metadata read( Reader input, Map<String, ?> options )
57 throws IOException
58 {
59 Validate.notNull( input, "input cannot be null" );
60
61 try
62 {
63 MetadataXpp3Reader r = new MetadataXpp3Reader();
64 return r.read( input, isStrict( options ) );
65 }
66 catch ( XmlPullParserException e )
67 {
68 throw new MetadataParseException( e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e );
69 }
70 finally
71 {
72 IOUtil.close( input );
73 }
74 }
75
76 public Metadata read( InputStream input, Map<String, ?> options )
77 throws IOException
78 {
79 Validate.notNull( input, "input cannot be null" );
80
81 try
82 {
83 MetadataXpp3Reader r = new MetadataXpp3Reader();
84 return r.read( input, isStrict( options ) );
85 }
86 catch ( XmlPullParserException e )
87 {
88 throw new MetadataParseException( e.getMessage(), e.getLineNumber(), e.getColumnNumber(), e );
89 }
90 finally
91 {
92 IOUtil.close( input );
93 }
94 }
95
96 private boolean isStrict( Map<String, ?> options )
97 {
98 Object value = ( options != null ) ? options.get( IS_STRICT ) : null;
99 return value == null || Boolean.parseBoolean( value.toString() );
100 }
101
102 }