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.poi.hssf.record;
19:
20: import org.apache.poi.hssf.record.formula.Ptg;
21: import org.apache.poi.util.LittleEndian;
22:
23: import java.util.Stack;
24: import java.util.Iterator;
25:
26: /**
27: * Not implemented yet. May commit it anyway just so people can see
28: * where I'm heading.
29: *
30: * @author Glen Stampoultzis (glens at apache.org)
31: */
32: public class LinkedDataFormulaField implements CustomField {
33: Stack formulaTokens = new Stack();
34:
35: public int getSize() {
36: int size = 0;
37: for (Iterator iterator = formulaTokens.iterator(); iterator
38: .hasNext();) {
39: Ptg token = (Ptg) iterator.next();
40: size += token.getSize();
41: }
42: return size + 2;
43: }
44:
45: public int fillField(RecordInputStream in) {
46: short tokenSize = in.readShort();
47: formulaTokens = Ptg.createParsedExpressionTokens(tokenSize, in);
48:
49: return tokenSize + 2;
50: }
51:
52: public void toString(StringBuffer buffer) {
53: for (int k = 0; k < formulaTokens.size(); k++) {
54: buffer.append("Formula ").append(k).append("=").append(
55: formulaTokens.get(k).toString()).append("\n")
56: .append(
57: ((Ptg) formulaTokens.get(k))
58: .toDebugString()).append("\n");
59: }
60: }
61:
62: public String toString() {
63: StringBuffer b = new StringBuffer();
64: toString(b);
65: return b.toString();
66: }
67:
68: public int serializeField(int offset, byte[] data) {
69: int size = getSize();
70: LittleEndian.putShort(data, offset, (short) (size - 2));
71: int pos = offset + 2;
72: pos += Ptg.serializePtgStack(formulaTokens, data, pos);
73: return size;
74: }
75:
76: public Object clone() {
77: try {
78: // todo: clone tokens? or are they immutable?
79: return super .clone();
80: } catch (CloneNotSupportedException e) {
81: // should not happen
82: return null;
83: }
84: }
85:
86: public void setFormulaTokens(Stack formulaTokens) {
87: this .formulaTokens = (Stack) formulaTokens.clone();
88: }
89:
90: public Stack getFormulaTokens() {
91: return (Stack) this.formulaTokens.clone();
92: }
93:
94: }
|