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.module.fml;
020
021import org.apache.maven.doxia.macro.MacroExecutionException;
022import org.apache.maven.doxia.parser.Xhtml5BaseParser;
023import org.apache.maven.doxia.sink.Sink;
024import org.apache.maven.doxia.sink.SinkEventAttributeSet;
025import org.codehaus.plexus.util.xml.pull.XmlPullParser;
026import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
027import org.slf4j.Logger;
028import org.slf4j.LoggerFactory;
029
030/**
031 * Parse Fml questions and answers, these may contain arbitrary xdoc elements.
032 *
033 * @author ltheussl
034 * @since 1.0
035 * @deprecated FML is deprecated since 2.2.0 and scheduled for removal in the next major version.
036 *     Convert FAQ pages to Markdown or XDoc, for example with doxia-converter; see
037 *     https://github.com/apache/maven-doxia/issues/1101.
038 */
039@Deprecated
040public class FmlContentParser extends Xhtml5BaseParser implements FmlMarkup {
041    private static final Logger LOGGER = LoggerFactory.getLogger(FmlContentParser.class);
042
043    /** Empty elements don't write a closing tag. */
044    private boolean isEmptyElement;
045
046    protected void handleStartTag(XmlPullParser parser, Sink sink)
047            throws XmlPullParserException, MacroExecutionException {
048        isEmptyElement = parser.isEmptyElementTag();
049
050        if (parser.getName().equals(QUESTION_TAG.toString())
051                || parser.getName().equals(TITLE.toString())
052                || parser.getName().equals(ANSWER_TAG.toString())) {
053            // ignore
054            return;
055        } else if (parser.getName().equals(SOURCE_TAG.toString())) {
056            verbatim();
057
058            sink.verbatim(SinkEventAttributeSet.SOURCE);
059        } else if (!baseStartTag(parser, sink)) {
060            if (isEmptyElement) {
061                handleUnknown(parser, sink, TAG_TYPE_SIMPLE);
062            } else {
063                handleUnknown(parser, sink, TAG_TYPE_START);
064            }
065
066            LOGGER.warn(
067                    "Unrecognized fml tag <{}> at [{}:{}]",
068                    parser.getName(),
069                    parser.getLineNumber(),
070                    parser.getColumnNumber());
071        }
072    }
073
074    protected void handleEndTag(XmlPullParser parser, Sink sink)
075            throws XmlPullParserException, MacroExecutionException {
076        if (parser.getName().equals(QUESTION_TAG.toString())
077                || parser.getName().equals(TITLE.toString())
078                || parser.getName().equals(ANSWER_TAG.toString())) {
079            // ignore
080            return;
081        } else if (parser.getName().equals(SOURCE_TAG.toString())) {
082            verbatim_();
083
084            sink.verbatim_();
085        } else if (!baseEndTag(parser, sink)) {
086            if (!isEmptyElement) {
087                handleUnknown(parser, sink, TAG_TYPE_END);
088            }
089        }
090
091        isEmptyElement = false;
092    }
093
094    /**
095     * {@inheritDoc}
096     */
097    protected void init() {
098        super.init();
099
100        this.isEmptyElement = false;
101    }
102}