1 package org.apache.maven.doxia.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.doxia.UnsupportedFormatException;
23 import org.apache.maven.doxia.parser.Parser;
24 import org.apache.maven.doxia.sink.SinkFactory;
25 import org.codehaus.plexus.PlexusContainer;
26 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
27
28 import java.util.Objects;
29
30
31
32
33
34
35 public class ConverterUtil
36 {
37
38
39
40
41
42
43
44
45
46 public static Parser getParser( PlexusContainer plexus, String format, String[] supportedFormats )
47 throws ComponentLookupException, UnsupportedFormatException
48 {
49 Objects.requireNonNull( plexus, "plexus is required" );
50 Objects.requireNonNull( format, "format is required" );
51 Objects.requireNonNull( supportedFormats, "supportedFormats is required" );
52
53 Parser parser = null;
54
55 for ( String supportedFormat : supportedFormats )
56 {
57 if ( format.equalsIgnoreCase( supportedFormat ) )
58 {
59 parser = (Parser) plexus.lookup( Parser.ROLE, format );
60 }
61 }
62
63 if ( parser == null )
64 {
65 throw new UnsupportedFormatException( format, supportedFormats );
66 }
67
68 return parser;
69 }
70
71
72
73
74
75
76
77
78
79
80 public static SinkFactory getSinkFactory( PlexusContainer plexus, String format, String[] supportedFormats )
81 throws ComponentLookupException, UnsupportedFormatException
82 {
83 Objects.requireNonNull( plexus, "plexus is required" );
84 Objects.requireNonNull( format, "format is required" );
85 Objects.requireNonNull( supportedFormats, "supportedFormats is required" );
86
87 SinkFactory factory = null;
88
89 for ( String supportedFormat : supportedFormats )
90 {
91 if ( format.equalsIgnoreCase( supportedFormat ) )
92 {
93 factory = (SinkFactory) plexus.lookup( SinkFactory.ROLE, format );
94 }
95 }
96
97 if ( factory == null )
98 {
99 throw new UnsupportedFormatException( format, supportedFormats );
100 }
101
102 return factory;
103 }
104 }