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 java.io.IOException;
23
24 import org.apache.maven.doxia.UnsupportedFormatException;
25 import org.apache.maven.doxia.parser.Parser;
26 import org.apache.maven.doxia.sink.SinkFactory;
27 import org.codehaus.plexus.PlexusContainer;
28 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
29
30
31
32
33
34
35
36 public class ConverterUtil
37 {
38
39
40
41
42
43
44
45
46
47 public static Parser getParser( PlexusContainer plexus, String format, String[] supportedFormats )
48 throws ComponentLookupException, UnsupportedFormatException
49 {
50 if ( plexus == null )
51 {
52 throw new IllegalArgumentException( "plexus is required" );
53 }
54
55 if ( format == null )
56 {
57 throw new IllegalArgumentException( "format is required" );
58 }
59
60 if ( supportedFormats == null )
61 {
62 throw new IllegalArgumentException( "supportedFormats is required" );
63 }
64
65 Parser parser = null;
66
67 for ( int i = 0; i < supportedFormats.length; i++ )
68 {
69 if ( format.equalsIgnoreCase( supportedFormats[i] ) )
70 {
71 parser = (Parser) plexus.lookup( Parser.ROLE, format );
72 }
73 }
74
75 if ( parser == null )
76 {
77 throw new UnsupportedFormatException( format, supportedFormats );
78 }
79
80 return parser;
81 }
82
83
84
85
86
87
88
89
90
91
92
93 public static SinkFactory getSinkFactory( PlexusContainer plexus, String format, String[] supportedFormats )
94 throws ComponentLookupException, UnsupportedFormatException
95 {
96 if ( plexus == null )
97 {
98 throw new IllegalArgumentException( "plexus is required" );
99 }
100
101 if ( format == null )
102 {
103 throw new IllegalArgumentException( "format is required" );
104 }
105
106 if ( supportedFormats == null )
107 {
108 throw new IllegalArgumentException( "supportedFormats is required" );
109 }
110
111 SinkFactory factory = null;
112
113 for ( int i = 0; i < supportedFormats.length; i++ )
114 {
115 if ( format.equalsIgnoreCase( supportedFormats[i] ) )
116 {
117 factory = (SinkFactory) plexus.lookup( SinkFactory.ROLE, format );
118 }
119 }
120
121 if ( factory == null )
122 {
123 throw new UnsupportedFormatException( format, supportedFormats );
124 }
125
126 return factory;
127 }
128 }