View Javadoc

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          String fr = frame;
51  
52          if ( "all".equals( fr ) )
53          {
54              fr = "box";
55          }
56          else if ( "bottom".equals( fr ) )
57          {
58              fr = "below";
59          }
60          else if ( "none".equals( fr ) )
61          {
62              fr = "void";
63          }
64          else if ( "sides".equals( fr ) )
65          {
66              fr = "vsides";
67          }
68          else if ( "top".equals( fr ) )
69          {
70              fr = "above";
71          }
72          else if ( "topbot".equals( fr ) )
73          {
74              fr = "hsides";
75          }
76          else
77          {
78              throw new IllegalArgumentException( "Not a valid frame attribute: " + fr );
79          }
80  
81          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          if ( SimplifiedDocbookMarkup.LOWERALPHA_STYLE.equals( style ) )
97          {
98              return Sink.NUMBERING_LOWER_ALPHA;
99          }
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>&lt;trademark&gt;</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 }