Coverage Report - org.apache.maven.doxia.module.docbook.DocbookUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
DocbookUtils
95%
42/44
100%
36/36
8,6
 
 1  
 package org.apache.maven.doxia.module.docbook;
 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.sink.Sink;
 23  
 
 24  
 /**
 25  
  * Utility methods for Doxia Docbook Parser and Sink.
 26  
  *
 27  
  * @author ltheussl
 28  
  * @version $Id: DocbookUtils.java 784698 2009-06-15 09:19:18Z ltheussl $
 29  
  * @since 1.1.1
 30  
  */
 31  
 public final class DocbookUtils
 32  
 {
 33  
     /**
 34  
      * Translate a given Docbook table frame attribute value to a valid
 35  
      * Doxia table frame attribute value.
 36  
      *
 37  
      * <p>The input has to be one of <code>"all"</code>, <code>"bottom"</code>,
 38  
      * <code>"none"</code>, <code>"sides"</code>, <code>"top"</code> or <code>"topbot"</code>,
 39  
      * otherwise an IllegalArgumentException is thrown.</p>
 40  
      *
 41  
      * <p>The corresponding output values are <code>"box"</code>, <code>"below"</code>,
 42  
      * <code>"void"</code>, <code>"vsides"</code>, <code>"above"</code> and <code>"hsides"</code>.</p>
 43  
      *
 44  
      * @param frame a valid docbook table frame attribute as specified above,
 45  
      * otherwise an IllegalArgumentException is thrown.
 46  
      * @return a valid Doxia table frame attribute as specified above.
 47  
      */
 48  
     public static String doxiaTableFrameAttribute( final String frame )
 49  
     {
 50  34
         String fr = frame;
 51  
 
 52  34
         if ( "all".equals( fr ) )
 53  
         {
 54  16
             fr = "box";
 55  
         }
 56  18
         else if ( "bottom".equals( fr ) )
 57  
         {
 58  2
             fr = "below";
 59  
         }
 60  16
         else if ( "none".equals( fr ) )
 61  
         {
 62  8
             fr = "void";
 63  
         }
 64  8
         else if ( "sides".equals( fr ) )
 65  
         {
 66  2
             fr = "vsides";
 67  
         }
 68  6
         else if ( "top".equals( fr ) )
 69  
         {
 70  2
             fr = "above";
 71  
         }
 72  4
         else if ( "topbot".equals( fr ) )
 73  
         {
 74  2
             fr = "hsides";
 75  
         }
 76  
         else
 77  
         {
 78  2
             throw new IllegalArgumentException( "Not a valid frame attribute: " + fr );
 79  
         }
 80  
 
 81  32
         return fr;
 82  
     }
 83  
 
 84  
     /**
 85  
      * Convert a docbook ordered-list numbering style to a doxia numbering style.
 86  
      *
 87  
      * <p>The input has to be one of the style constants defined in {@link SimplifiedDocbookMarkup},
 88  
      * otherwise an IllegalArgumentException is thrown.</p>
 89  
      *
 90  
      * <p>The output is one of the numbering constants defined in {@link Sink}.</p>
 91  
      * @param style a docbook ordered-list numbering style.
 92  
      * @return a doxia numbering style.
 93  
      */
 94  
     public static int doxiaListNumbering( final String style )
 95  
     {
 96  22
         if ( SimplifiedDocbookMarkup.LOWERALPHA_STYLE.equals( style ) )
 97  
         {
 98  2
             return Sink.NUMBERING_LOWER_ALPHA;
 99  
         }
 100  20
         else if ( SimplifiedDocbookMarkup.LOWERROMAN_STYLE.equals( style ) )
 101  
         {
 102  2
             return Sink.NUMBERING_LOWER_ROMAN;
 103  
         }
 104  18
         else if ( SimplifiedDocbookMarkup.UPPERALPHA_STYLE.equals( style ) )
 105  
         {
 106  8
             return Sink.NUMBERING_UPPER_ALPHA;
 107  
         }
 108  10
         else if ( SimplifiedDocbookMarkup.UPPERROMAN_STYLE.equals( style ) )
 109  
         {
 110  2
             return Sink.NUMBERING_UPPER_ROMAN;
 111  
         }
 112  8
         else if ( SimplifiedDocbookMarkup.ARABIC_STYLE.equals( style ) )
 113  
         {
 114  6
             return Sink.NUMBERING_DECIMAL;
 115  
         }
 116  
         else
 117  
         {
 118  2
             throw new IllegalArgumentException( "Not a valid numbering style: " + style );
 119  
         }
 120  
     }
 121  
 
 122  
     /**
 123  
      * Convert a doxia numbering style to a docbook ordered-list numbering style.
 124  
      *
 125  
      * <p>The input has to be one of the numbering constants defined in {@link Sink},
 126  
      * otherwise an IllegalArgumentException is thrown.</p>
 127  
      *
 128  
      * <p>The output is one of the style constants defined in {@link SimplifiedDocbookMarkup}.</p>
 129  
      * @param numbering a doxia numbering style.
 130  
      * @return a docbook ordered-list numbering style.
 131  
      */
 132  
     public static String docbookListNumbering( final int numbering )
 133  
     {
 134  26
         switch ( numbering )
 135  
         {
 136  
             case Sink.NUMBERING_UPPER_ALPHA:
 137  8
                 return SimplifiedDocbookMarkup.UPPERALPHA_STYLE;
 138  
             case Sink.NUMBERING_LOWER_ALPHA:
 139  2
                 return SimplifiedDocbookMarkup.LOWERALPHA_STYLE;
 140  
             case Sink.NUMBERING_UPPER_ROMAN:
 141  2
                 return SimplifiedDocbookMarkup.UPPERROMAN_STYLE;
 142  
             case Sink.NUMBERING_LOWER_ROMAN:
 143  4
                 return SimplifiedDocbookMarkup.LOWERROMAN_STYLE;
 144  
             case Sink.NUMBERING_DECIMAL:
 145  8
                 return SimplifiedDocbookMarkup.ARABIC_STYLE;
 146  
             default:
 147  2
                 throw new IllegalArgumentException( "Not a valid numbering: " + numbering );
 148  
         }
 149  
     }
 150  
 
 151  
     /**
 152  
      * Get a trademark character from a class attribute.
 153  
      *
 154  
      * <p>The input String has to be one of <code>"registered"</code>, <code>"copyright"</code>,
 155  
      * <code>"service"</code> or <code>"trade"</code> otherwise an IllegalArgumentException is thrown.</p>
 156  
      *
 157  
      * <p>The corresponding output is <code>'\u00AE'</code>, <code>'\u00A9'</code>,
 158  
      * <code>'\u2120'</code> or <code>'\u2122'</code>.</p>
 159  
      *
 160  
      * @param trade a valid class atribute for the docbook <code>&lt;trademark&gt;</code> tag.
 161  
      * @return the corresponding unicode character.
 162  
      */
 163  
     public static char trademarkFromClass( final String trade )
 164  
     {
 165  18
         if ( "registered".equals( trade ) )
 166  
         {
 167  4
             return '\u00AE';
 168  
         }
 169  14
         else if ( "copyright".equals( trade ) )
 170  
         {
 171  4
             return '\u00A9';
 172  
         }
 173  10
         else if ( "service".equals( trade ) )
 174  
         {
 175  4
             return '\u2120';
 176  
         }
 177  6
         else if ( "trade".equals( trade ) )
 178  
         {
 179  4
             return '\u2122';
 180  
         }
 181  
         else
 182  
         {
 183  2
             throw new IllegalArgumentException( "Not a trademark class: " + trade );
 184  
         }
 185  
     }
 186  
 
 187  
     private DocbookUtils()
 188  0
     {
 189  
         // utility class
 190  0
     }
 191  
 }