View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.doxia;
20  
21  import javax.inject.Inject;
22  import javax.inject.Named;
23  import javax.inject.Singleton;
24  
25  import java.io.Reader;
26  
27  import org.apache.maven.doxia.parser.ParseException;
28  import org.apache.maven.doxia.parser.Parser;
29  import org.apache.maven.doxia.parser.manager.ParserManager;
30  import org.apache.maven.doxia.parser.manager.ParserNotFoundException;
31  import org.apache.maven.doxia.sink.Sink;
32  
33  /**
34   * Simple implementation of the Doxia interface:
35   * uses a ParserManager to lookup a parser.
36   *
37   * @author Jason van Zyl
38   * @since 1.0
39   */
40  @Singleton
41  @Named
42  public class DefaultDoxia implements Doxia {
43      @Inject
44      private ParserManager parserManager;
45  
46      // ----------------------------------------------------------------------
47      // This remains because the sinks are not threadsafe which they probably
48      // should be. In some places a constructor is used to initialize a sink
49      // which can probably be done away with.
50      // ----------------------------------------------------------------------
51  
52      /** {@inheritDoc} */
53      public void parse(Reader source, String parserId, Sink sink) throws ParserNotFoundException, ParseException {
54          this.parse(source, parserId, sink, null);
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public void parse(Reader source, String parserId, Sink sink, String reference)
60              throws ParserNotFoundException, ParseException {
61          Parser parser = parserManager.getParser(parserId);
62  
63          parser.parse(source, sink, reference);
64      }
65  
66      /** {@inheritDoc} */
67      public Parser getParser(String parserId) throws ParserNotFoundException {
68          return parserManager.getParser(parserId);
69      }
70  }