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 orientation -- encapsulation of the strings representing the
26: * print orientation, and a simpler way to deal with them.
27: *
28: * @author Marc Johnson (marc_johnson27591@hotmail.com)
29: * @version CVS $Id: PrintOrientation.java 433543 2006-08-22 06:22:54Z crossley $
30: */
31: public class PrintOrientation {
32: private static final String _landscape = "landscape";
33: private static final String _portrait = "portrait";
34: public static final int PRINT_ORIENTATION_LANDSCAPE = 0;
35: public static final int PRINT_ORIENTATION_PORTRAIT = 1;
36: private static final NumericResult _null_result = new NumericResult(
37: new IOException("print orientation cannot be null"));
38: private static final NumericResult _landscape_result = new NumericResult(
39: new Integer(PRINT_ORIENTATION_LANDSCAPE));
40: private static final NumericResult _portrait_result = new NumericResult(
41: new Integer(PRINT_ORIENTATION_PORTRAIT));
42:
43: private PrintOrientation() {
44: }
45:
46: /**
47: * convert a string into a NumericResult
48: * @param value the string describing the print orientation
49: * @return a NumericResult containing either one of the public enumeration
50: * values, or an appropriate IOException
51: */
52: public static NumericResult extractPrintOrientation(
53: final String value) {
54: NumericResult rval = null;
55: String input = (value == null) ? null : value.trim();
56:
57: if (input == null) {
58: rval = _null_result;
59: } else if (input.equalsIgnoreCase(_landscape)) {
60: rval = _landscape_result;
61: } else if (input.equalsIgnoreCase(_portrait)) {
62: rval = _portrait_result;
63: } else {
64: rval = new NumericResult(new IOException("\"" + input
65: + "\" is not a valid print orientation"));
66: }
67: return rval;
68: }
69: } // end public class PrintOrientation
|