KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > elementprocessor > impl > poi > hssf > elements > PrintUnits


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements;
18
19 import org.apache.cocoon.components.elementprocessor.types.NumericResult;
20
21 import java.io.IOException JavaDoc;
22
23 /**
24  * Print units -- encapsulation of the strings representing them, and
25  * a simpler way to deal with them.GTK type codes
26  *
27  * @author Marc Johnson (marc_johnson27591@hotmail.com)
28  * @version CVS $Id: PrintUnits.java 30932 2004-07-29 17:35:38Z vgritsenko $
29  */

30 public class PrintUnits {
31     private static final String JavaDoc _cm = "cm";
32     private static final String JavaDoc _in = "in";
33     private static final String JavaDoc _mm = "mm";
34     private static final String JavaDoc _points = "points";
35     public static final int PRINT_UNITS_CM = 0;
36     public static final int PRINT_UNITS_IN = 1;
37     public static final int PRINT_UNITS_MM = 2;
38     public static final int PRINT_UNITS_POINTS = 3;
39     private static final NumericResult _null_result =
40         new NumericResult(new IOException JavaDoc("print units cannot be null"));
41     private static final NumericResult _cm_result =
42         new NumericResult(new Integer JavaDoc(PRINT_UNITS_CM));
43     private static final NumericResult _in_result =
44         new NumericResult(new Integer JavaDoc(PRINT_UNITS_IN));
45     private static final NumericResult _mm_result =
46         new NumericResult(new Integer JavaDoc(PRINT_UNITS_MM));
47     private static final NumericResult _points_result =
48         new NumericResult(new Integer JavaDoc(PRINT_UNITS_POINTS));
49
50     private PrintUnits() {}
51
52     /**
53      * convert a string into a NumericResult
54      * @param value the string describing the print units
55      * @return a NumericResult containing either one of the public enumeration
56      * values, or an appropriate IOException
57      */

58     public static NumericResult extractPrintUnits(final String JavaDoc value) {
59         NumericResult rval = null;
60         String JavaDoc input = (value == null) ? null : value.trim();
61
62         if (input == null) {
63             rval = _null_result;
64         } else if (input.equalsIgnoreCase(_cm)) {
65             rval = _cm_result;
66         } else if (input.equalsIgnoreCase(_in)) {
67             rval = _in_result;
68         } else if (input.equalsIgnoreCase(_mm)) {
69             rval = _mm_result;
70         } else if (input.equalsIgnoreCase(_points)) {
71             rval = _points_result;
72         } else {
73             rval = new NumericResult(new IOException JavaDoc(
74                         "\"" + input + "\" is not a valid print unit"));
75         }
76         return rval;
77     }
78 } // end public class PrintUnits
79
Popular Tags