Coverage Report - org.apache.maven.doxia.module.fml.FmlContentParser
 
Classes in this File Line Coverage Branch Coverage Complexity
FmlContentParser
86%
25/29
88%
23/26
6
 
 1  
 package org.apache.maven.doxia.module.fml;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.maven.doxia.macro.MacroExecutionException;
 23  
 import org.apache.maven.doxia.parser.XhtmlBaseParser;
 24  
 import org.apache.maven.doxia.sink.Sink;
 25  
 import org.apache.maven.doxia.sink.SinkEventAttributeSet;
 26  
 
 27  
 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
 28  
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 29  
 
 30  
 /**
 31  
  * Parse Fml questions and answers, these may contain arbitrary xdoc elements.
 32  
  *
 33  
  * @author ltheussl
 34  
  * @version $Id: FmlContentParser.java 807169 2009-08-24 12:05:48Z vsiveton $
 35  
  * @since 1.0
 36  
  */
 37  10
 public class FmlContentParser
 38  
     extends XhtmlBaseParser
 39  
     implements FmlMarkup
 40  
 {
 41  
     /** Empty elements don't write a closing tag. */
 42  
     private boolean isEmptyElement;
 43  
 
 44  
     /** {@inheritDoc} */
 45  
     protected void handleStartTag( XmlPullParser parser, Sink sink )
 46  
         throws XmlPullParserException, MacroExecutionException
 47  
     {
 48  1386
         isEmptyElement = parser.isEmptyElementTag();
 49  
 
 50  1386
         if ( parser.getName().equals( QUESTION_TAG.toString() )
 51  
                 || parser.getName().equals( TITLE.toString() )
 52  
             || parser.getName().equals( ANSWER_TAG.toString() ) )
 53  
         {
 54  
             // ignore
 55  588
             return;
 56  
         }
 57  798
         else if ( parser.getName().equals( SOURCE_TAG.toString() ) )
 58  
         {
 59  52
             verbatim();
 60  
 
 61  52
             sink.verbatim( SinkEventAttributeSet.BOXED );
 62  
         }
 63  746
         else if ( !baseStartTag( parser, sink ) )
 64  
         {
 65  2
             if ( isEmptyElement )
 66  
             {
 67  0
                 handleUnknown( parser, sink, TAG_TYPE_SIMPLE );
 68  
             }
 69  
             else
 70  
             {
 71  2
                 handleUnknown( parser, sink, TAG_TYPE_START );
 72  
             }
 73  
 
 74  2
             if ( getLog().isDebugEnabled() )
 75  
             {
 76  0
                 String position = "[" + parser.getLineNumber() + ":"
 77  
                     + parser.getColumnNumber() + "]";
 78  0
                 String tag = "<" + parser.getName() + ">";
 79  
 
 80  0
                 getLog().debug( "Unrecognized fml tag: " + tag + " at " + position );
 81  
             }
 82  
         }
 83  798
     }
 84  
 
 85  
     /** {@inheritDoc} */
 86  
     protected void handleEndTag( XmlPullParser parser, Sink sink )
 87  
         throws XmlPullParserException, MacroExecutionException
 88  
     {
 89  1386
         if ( parser.getName().equals( QUESTION_TAG.toString() )
 90  
                 || parser.getName().equals( TITLE.toString() )
 91  
             || parser.getName().equals( ANSWER_TAG.toString() ) )
 92  
         {
 93  
             // ignore
 94  588
             return;
 95  
         }
 96  798
         else if ( parser.getName().equals( SOURCE_TAG.toString() ) )
 97  
         {
 98  52
             verbatim_();
 99  
 
 100  52
             sink.verbatim_();
 101  
         }
 102  746
         else if ( !baseEndTag( parser, sink ) )
 103  
         {
 104  2
             if ( !isEmptyElement )
 105  
             {
 106  2
                 handleUnknown( parser, sink, TAG_TYPE_END );
 107  
             }
 108  
         }
 109  
 
 110  798
         isEmptyElement = false;
 111  798
     }
 112  
 
 113  
     /** {@inheritDoc} */
 114  
     protected void init()
 115  
     {
 116  2352
         super.init();
 117  
 
 118  2352
         this.isEmptyElement = false;
 119  2352
     }
 120  
 }