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:
22: import java.io.IOException;
23:
24: /**
25: * Offsets. This particular object is represented in gnumeric's XML as
26: * four doubles, space separated. Presumably, each represents an
27: * offset in a particular direction -- top, bottom, left, right -- but
28: * what the reference is for each offset is not known, nor is it known
29: * which one is top, bottom, left, or right, or even whether that's
30: * the correct interpretation of the numbers. This is an area of the
31: * gnumeric XML that is not terribly well documented even in their
32: * code, and I don't think the features that use offsets are terribly
33: * mature yet.
34: *
35: * @author Marc Johnson (marc_johnson27591@hotmail.com)
36: * @version CVS $Id: Offsets.java 433543 2006-08-22 06:22:54Z crossley $
37: */
38: public class Offsets {
39: private static final int _component_count = 4;
40: private double[] _components = new double[_component_count];
41:
42: /**
43: * construct the Offsets object
44: * @param value the string containing the offset values
45: * @exception IOException if the string is badly formed
46: */
47: public Offsets(final String value) throws IOException {
48: if (value == null) {
49: throw new IOException(
50: "cannot process a null offsets string");
51: }
52: char[] input = value.trim().toCharArray();
53: int index = 0;
54:
55: for (int j = 0; j < _component_count; j++) {
56: while (index < input.length
57: && Character.isWhitespace(input[index])) {
58: ++index;
59: }
60: if (index == input.length) {
61: throw new IOException("insufficient offsets in string");
62: }
63: int tailIndex = index;
64:
65: while (tailIndex < input.length
66: && !Character.isWhitespace(input[tailIndex])) {
67: ++tailIndex;
68: }
69: _components[j] = NumericConverter.extractDouble(
70: new String(input, index, tailIndex - index))
71: .doubleValue();
72: index = tailIndex;
73: }
74: if (new String(input, index, input.length - index).trim()
75: .length() != 0) {
76: throw new IOException("Too much data in string for "
77: + _component_count + " offsets");
78: }
79: }
80:
81: /**
82: * @return components
83: */
84: public double[] getComponents() {
85: return _components;
86: }
87: } // end public class Offsets
|