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.NumericConverter;
21: import org.apache.cocoon.components.elementprocessor.types.Validator;
22:
23: import java.io.IOException;
24:
25: /**
26: * Style orientation is written as an integer, and each bit in the
27: * integer specifies a particular boolean attribute. This class deals
28: * with all that information in an easily digested form.
29: *
30: * @author Marc Johnson (marc_johnson27591@hotmail.com)
31: * @version CVS $Id: StyleOrientation.java 433543 2006-08-22 06:22:54Z crossley $
32: */
33: public class StyleOrientation {
34: private int _alignment;
35: private static final int _horiz = 1;
36: private static final int _vert_horiz_text = 2;
37: private static final int _vert_vert_text = 4;
38: private static final int _vert_vert_text2 = 8;
39: private static final Validator _validator = new Validator() {
40: public IOException validate(final Number number) {
41: int value = number.intValue();
42:
43: return (value >= 0 && value <= 15) ? null
44: : new IOException("\"" + number
45: + "\" is out of range");
46: }
47: };
48:
49: /**
50: * Create a StyleOrientation object
51: * @param value the string containing the style orientation data
52: * @exception IOException if the data is malformed
53: */
54: public StyleOrientation(final String value) throws IOException {
55: _alignment = NumericConverter.extractInteger(value, _validator)
56: .intValue();
57: }
58:
59: /**
60: * @return true if horiz bit is set
61: */
62: public boolean isHoriz() {
63: return (_alignment & _horiz) == _horiz;
64: }
65:
66: /**
67: * @return true if vert horiz text bit is set
68: */
69: public boolean isVertHorizText() {
70: return (_alignment & _vert_horiz_text) == _vert_horiz_text;
71: }
72:
73: /**
74: * @return true if vert vert text bit is set
75: */
76: public boolean isVertVertText() {
77: return (_alignment & _vert_vert_text) == _vert_vert_text;
78: }
79:
80: /**
81: * @return true if vert vert text2 bit is set
82: */
83: public boolean isVertVertText2() {
84: return (_alignment & _vert_vert_text2) == _vert_vert_text2;
85: }
86: } // end public class StyleOrientation
|