KickJava   Java API By Example, From Geeks To Geeks.

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


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.NumericConverter;
20
21 import java.io.IOException JavaDoc;
22
23 /**
24  * Offsets. This particular object is represented in gnumeric's XML as
25  * four doubles, space separated. Presumably, each represents an
26  * offset in a particular direction -- top, bottom, left, right -- but
27  * what the reference is for each offset is not known, nor is it known
28  * which one is top, bottom, left, or right, or even whether that's
29  * the correct interpretation of the numbers. This is an area of the
30  * gnumeric XML that is not terribly well documented even in their
31  * code, and I don't think the features that use offsets are terribly
32  * mature yet.
33  *
34  * @author Marc Johnson (marc_johnson27591@hotmail.com)
35  * @version CVS $Id: Offsets.java 30932 2004-07-29 17:35:38Z vgritsenko $
36  */

37 public class Offsets {
38     private static final int _component_count = 4;
39     private double[] _components = new double[_component_count];
40
41     /**
42      * construct the Offsets object
43      * @param value the string containing the offset values
44      * @exception IOException if the string is badly formed
45      */

46     public Offsets(final String JavaDoc value) throws IOException JavaDoc {
47         if (value == null) {
48             throw new IOException JavaDoc("cannot process a null offsets string");
49         }
50         char[] input = value.trim().toCharArray();
51         int index = 0;
52
53         for (int j = 0; j < _component_count; j++) {
54             while (index < input.length
55                 && Character.isWhitespace(input[index])) {
56                 ++index;
57             }
58             if (index == input.length) {
59                 throw new IOException JavaDoc("insufficient offsets in string");
60             }
61             int tailIndex = index;
62
63             while (tailIndex < input.length
64                 && !Character.isWhitespace(input[tailIndex])) {
65                 ++tailIndex;
66             }
67             _components[j] = NumericConverter
68                     .extractDouble(new String JavaDoc(input, index, tailIndex - index))
69                     .doubleValue();
70             index = tailIndex;
71         }
72         if (new String JavaDoc(input, index, input.length - index).trim().length()
73             != 0) {
74             throw new IOException JavaDoc(
75                 "Too much data in string for " + _component_count + " offsets");
76         }
77     }
78
79     /**
80      * @return components
81      */

82     public double[] getComponents() {
83         return _components;
84     }
85 } // end public class Offsets
86
Popular Tags