KickJava   Java API By Example, From Geeks To Geeks.

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


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 orientation -- encapsulation of the strings representing the
25  * print orientation, and a simpler way to deal with them.
26  *
27  * @author Marc Johnson (marc_johnson27591@hotmail.com)
28  * @version CVS $Id: PrintOrientation.java 30932 2004-07-29 17:35:38Z vgritsenko $
29  */

30 public class PrintOrientation {
31     private static final String JavaDoc _landscape = "landscape";
32     private static final String JavaDoc _portrait = "portrait";
33     public static final int PRINT_ORIENTATION_LANDSCAPE = 0;
34     public static final int PRINT_ORIENTATION_PORTRAIT = 1;
35     private static final NumericResult _null_result =
36         new NumericResult(new IOException JavaDoc("print orientation cannot be null"));
37     private static final NumericResult _landscape_result =
38         new NumericResult(new Integer JavaDoc(PRINT_ORIENTATION_LANDSCAPE));
39     private static final NumericResult _portrait_result =
40         new NumericResult(new Integer JavaDoc(PRINT_ORIENTATION_PORTRAIT));
41
42     private PrintOrientation() {}
43
44     /**
45      * convert a string into a NumericResult
46      * @param value the string describing the print orientation
47      * @return a NumericResult containing either one of the public enumeration
48      * values, or an appropriate IOException
49      */

50     public static NumericResult extractPrintOrientation(final String JavaDoc value) {
51         NumericResult rval = null;
52         String JavaDoc input = (value == null) ? null : value.trim();
53
54         if (input == null) {
55             rval = _null_result;
56         } else if (input.equalsIgnoreCase(_landscape)) {
57             rval = _landscape_result;
58         } else if (input.equalsIgnoreCase(_portrait)) {
59             rval = _portrait_result;
60         } else {
61             rval = new NumericResult( new IOException JavaDoc(
62                         "\"" + input + "\" is not a valid print orientation"));
63         }
64         return rval;
65     }
66 } // end public class PrintOrientation
67
Popular Tags