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 * @since 1.1.1 29 */ 30 public final class DocbookUtils 31 { 32 /** 33 * Translate a given Docbook table frame attribute value to a valid 34 * Doxia table frame attribute value. 35 * 36 * <p>The input has to be one of <code>"all"</code>, <code>"bottom"</code>, 37 * <code>"none"</code>, <code>"sides"</code>, <code>"top"</code> or <code>"topbot"</code>, 38 * otherwise an IllegalArgumentException is thrown.</p> 39 * 40 * <p>The corresponding output values are <code>"box"</code>, <code>"below"</code>, 41 * <code>"void"</code>, <code>"vsides"</code>, <code>"above"</code> and <code>"hsides"</code>.</p> 42 * 43 * @param frame a valid docbook table frame attribute as specified above, 44 * otherwise an IllegalArgumentException is thrown. 45 * @return a valid Doxia table frame attribute as specified above. 46 */ 47 public static String doxiaTableFrameAttribute( final String frame ) 48 { 49 String fr = frame; 50 51 if ( "all".equals( fr ) ) 52 { 53 fr = "box"; 54 } 55 else if ( "bottom".equals( fr ) ) 56 { 57 fr = "below"; 58 } 59 else if ( "none".equals( fr ) ) 60 { 61 fr = "void"; 62 } 63 else if ( "sides".equals( fr ) ) 64 { 65 fr = "vsides"; 66 } 67 else if ( "top".equals( fr ) ) 68 { 69 fr = "above"; 70 } 71 else if ( "topbot".equals( fr ) ) 72 { 73 fr = "hsides"; 74 } 75 else 76 { 77 throw new IllegalArgumentException( "Not a valid frame attribute: " + fr ); 78 } 79 80 return fr; 81 } 82 83 /** 84 * Convert a docbook ordered-list numbering style to a doxia numbering style. 85 * 86 * <p>The input has to be one of the style constants defined in {@link SimplifiedDocbookMarkup}, 87 * otherwise an IllegalArgumentException is thrown.</p> 88 * 89 * <p>The output is one of the numbering constants defined in {@link Sink}.</p> 90 * @param style a docbook ordered-list numbering style. 91 * @return a doxia numbering style. 92 */ 93 public static int doxiaListNumbering( final String style ) 94 { 95 if ( SimplifiedDocbookMarkup.LOWERALPHA_STYLE.equals( style ) ) 96 { 97 return Sink.NUMBERING_LOWER_ALPHA; 98 } 99 else if ( SimplifiedDocbookMarkup.LOWERROMAN_STYLE.equals( style ) ) 100 { 101 return Sink.NUMBERING_LOWER_ROMAN; 102 } 103 else if ( SimplifiedDocbookMarkup.UPPERALPHA_STYLE.equals( style ) ) 104 { 105 return Sink.NUMBERING_UPPER_ALPHA; 106 } 107 else if ( SimplifiedDocbookMarkup.UPPERROMAN_STYLE.equals( style ) ) 108 { 109 return Sink.NUMBERING_UPPER_ROMAN; 110 } 111 else if ( SimplifiedDocbookMarkup.ARABIC_STYLE.equals( style ) ) 112 { 113 return Sink.NUMBERING_DECIMAL; 114 } 115 else 116 { 117 throw new IllegalArgumentException( "Not a valid numbering style: " + style ); 118 } 119 } 120 121 /** 122 * Convert a doxia numbering style to a docbook ordered-list numbering style. 123 * 124 * <p>The input has to be one of the numbering constants defined in {@link Sink}, 125 * otherwise an IllegalArgumentException is thrown.</p> 126 * 127 * <p>The output is one of the style constants defined in {@link SimplifiedDocbookMarkup}.</p> 128 * 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 switch ( numbering ) 135 { 136 case Sink.NUMBERING_UPPER_ALPHA: 137 return SimplifiedDocbookMarkup.UPPERALPHA_STYLE; 138 case Sink.NUMBERING_LOWER_ALPHA: 139 return SimplifiedDocbookMarkup.LOWERALPHA_STYLE; 140 case Sink.NUMBERING_UPPER_ROMAN: 141 return SimplifiedDocbookMarkup.UPPERROMAN_STYLE; 142 case Sink.NUMBERING_LOWER_ROMAN: 143 return SimplifiedDocbookMarkup.LOWERROMAN_STYLE; 144 case Sink.NUMBERING_DECIMAL: 145 return SimplifiedDocbookMarkup.ARABIC_STYLE; 146 default: 147 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><trademark></code> tag. 161 * @return the corresponding unicode character. 162 */ 163 public static char trademarkFromClass( final String trade ) 164 { 165 if ( "registered".equals( trade ) ) 166 { 167 return '\u00AE'; 168 } 169 else if ( "copyright".equals( trade ) ) 170 { 171 return '\u00A9'; 172 } 173 else if ( "service".equals( trade ) ) 174 { 175 return '\u2120'; 176 } 177 else if ( "trade".equals( trade ) ) 178 { 179 return '\u2122'; 180 } 181 else 182 { 183 throw new IllegalArgumentException( "Not a trademark class: " + trade ); 184 } 185 } 186 187 private DocbookUtils() 188 { 189 // utility class 190 } 191 }