001package org.apache.maven.doxia.module.docbook; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.maven.doxia.sink.Sink; 023 024/** 025 * Utility methods for Doxia Docbook Parser and Sink. 026 * 027 * @author ltheussl 028 * @version $Id$ 029 * @since 1.1.1 030 */ 031public final class DocbookUtils 032{ 033 /** 034 * Translate a given Docbook table frame attribute value to a valid 035 * Doxia table frame attribute value. 036 * 037 * <p>The input has to be one of <code>"all"</code>, <code>"bottom"</code>, 038 * <code>"none"</code>, <code>"sides"</code>, <code>"top"</code> or <code>"topbot"</code>, 039 * otherwise an IllegalArgumentException is thrown.</p> 040 * 041 * <p>The corresponding output values are <code>"box"</code>, <code>"below"</code>, 042 * <code>"void"</code>, <code>"vsides"</code>, <code>"above"</code> and <code>"hsides"</code>.</p> 043 * 044 * @param frame a valid docbook table frame attribute as specified above, 045 * otherwise an IllegalArgumentException is thrown. 046 * @return a valid Doxia table frame attribute as specified above. 047 */ 048 public static String doxiaTableFrameAttribute( final String frame ) 049 { 050 String fr = frame; 051 052 if ( "all".equals( fr ) ) 053 { 054 fr = "box"; 055 } 056 else if ( "bottom".equals( fr ) ) 057 { 058 fr = "below"; 059 } 060 else if ( "none".equals( fr ) ) 061 { 062 fr = "void"; 063 } 064 else if ( "sides".equals( fr ) ) 065 { 066 fr = "vsides"; 067 } 068 else if ( "top".equals( fr ) ) 069 { 070 fr = "above"; 071 } 072 else if ( "topbot".equals( fr ) ) 073 { 074 fr = "hsides"; 075 } 076 else 077 { 078 throw new IllegalArgumentException( "Not a valid frame attribute: " + fr ); 079 } 080 081 return fr; 082 } 083 084 /** 085 * Convert a docbook ordered-list numbering style to a doxia numbering style. 086 * 087 * <p>The input has to be one of the style constants defined in {@link SimplifiedDocbookMarkup}, 088 * otherwise an IllegalArgumentException is thrown.</p> 089 * 090 * <p>The output is one of the numbering constants defined in {@link Sink}.</p> 091 * @param style a docbook ordered-list numbering style. 092 * @return a doxia numbering style. 093 */ 094 public static int doxiaListNumbering( final String style ) 095 { 096 if ( SimplifiedDocbookMarkup.LOWERALPHA_STYLE.equals( style ) ) 097 { 098 return Sink.NUMBERING_LOWER_ALPHA; 099 } 100 else if ( SimplifiedDocbookMarkup.LOWERROMAN_STYLE.equals( style ) ) 101 { 102 return Sink.NUMBERING_LOWER_ROMAN; 103 } 104 else if ( SimplifiedDocbookMarkup.UPPERALPHA_STYLE.equals( style ) ) 105 { 106 return Sink.NUMBERING_UPPER_ALPHA; 107 } 108 else if ( SimplifiedDocbookMarkup.UPPERROMAN_STYLE.equals( style ) ) 109 { 110 return Sink.NUMBERING_UPPER_ROMAN; 111 } 112 else if ( SimplifiedDocbookMarkup.ARABIC_STYLE.equals( style ) ) 113 { 114 return Sink.NUMBERING_DECIMAL; 115 } 116 else 117 { 118 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 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}