001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.doxia;
020
021import javax.inject.Inject;
022import javax.inject.Named;
023import javax.inject.Singleton;
024
025import java.io.Reader;
026
027import org.apache.maven.doxia.parser.ParseException;
028import org.apache.maven.doxia.parser.Parser;
029import org.apache.maven.doxia.parser.manager.ParserManager;
030import org.apache.maven.doxia.parser.manager.ParserNotFoundException;
031import org.apache.maven.doxia.sink.Sink;
032
033/**
034 * Simple implementation of the Doxia interface:
035 * uses a ParserManager to lookup a parser.
036 *
037 * @author Jason van Zyl
038 * @since 1.0
039 */
040@Singleton
041@Named
042public class DefaultDoxia implements Doxia {
043    @Inject
044    private ParserManager parserManager;
045
046    // ----------------------------------------------------------------------
047    // This remains because the sinks are not threadsafe which they probably
048    // should be. In some places a constructor is used to initialize a sink
049    // which can probably be done away with.
050    // ----------------------------------------------------------------------
051
052    /** {@inheritDoc} */
053    public void parse(Reader source, String parserId, Sink sink) throws ParserNotFoundException, ParseException {
054        this.parse(source, parserId, sink, null);
055    }
056
057    /** {@inheritDoc} */
058    @Override
059    public void parse(Reader source, String parserId, Sink sink, String reference)
060            throws ParserNotFoundException, ParseException {
061        Parser parser = parserManager.getParser(parserId);
062
063        parser.parse(source, sink, reference);
064    }
065
066    /** {@inheritDoc} */
067    public Parser getParser(String parserId) throws ParserNotFoundException {
068        return parserManager.getParser(parserId);
069    }
070}