01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements;
19:
20: import org.apache.cocoon.components.elementprocessor.types.NumericResult;
21:
22: import java.io.IOException;
23:
24: /**
25: * Print units -- encapsulation of the strings representing them, and
26: * a simpler way to deal with them.GTK type codes
27: *
28: * @author Marc Johnson (marc_johnson27591@hotmail.com)
29: * @version CVS $Id: PrintUnits.java 433543 2006-08-22 06:22:54Z crossley $
30: */
31: public class PrintUnits {
32: private static final String _cm = "cm";
33: private static final String _in = "in";
34: private static final String _mm = "mm";
35: private static final String _points = "points";
36: public static final int PRINT_UNITS_CM = 0;
37: public static final int PRINT_UNITS_IN = 1;
38: public static final int PRINT_UNITS_MM = 2;
39: public static final int PRINT_UNITS_POINTS = 3;
40: private static final NumericResult _null_result = new NumericResult(
41: new IOException("print units cannot be null"));
42: private static final NumericResult _cm_result = new NumericResult(
43: new Integer(PRINT_UNITS_CM));
44: private static final NumericResult _in_result = new NumericResult(
45: new Integer(PRINT_UNITS_IN));
46: private static final NumericResult _mm_result = new NumericResult(
47: new Integer(PRINT_UNITS_MM));
48: private static final NumericResult _points_result = new NumericResult(
49: new Integer(PRINT_UNITS_POINTS));
50:
51: private PrintUnits() {
52: }
53:
54: /**
55: * convert a string into a NumericResult
56: * @param value the string describing the print units
57: * @return a NumericResult containing either one of the public enumeration
58: * values, or an appropriate IOException
59: */
60: public static NumericResult extractPrintUnits(final String value) {
61: NumericResult rval = null;
62: String input = (value == null) ? null : value.trim();
63:
64: if (input == null) {
65: rval = _null_result;
66: } else if (input.equalsIgnoreCase(_cm)) {
67: rval = _cm_result;
68: } else if (input.equalsIgnoreCase(_in)) {
69: rval = _in_result;
70: } else if (input.equalsIgnoreCase(_mm)) {
71: rval = _mm_result;
72: } else if (input.equalsIgnoreCase(_points)) {
73: rval = _points_result;
74: } else {
75: rval = new NumericResult(new IOException("\"" + input
76: + "\" is not a valid print unit"));
77: }
78: return rval;
79: }
80: } // end public class PrintUnits
|