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.poi.hssf.util.RangeAddress;
21: import org.apache.poi.hssf.util.Region;
22:
23: import java.io.IOException;
24:
25: /**
26: * No-op implementation of ElementProcessor to handle the "Merge" tag.
27: * This element is a container of other elements and has several attributes.
28: *
29: * @author Danny Mui (danny@muibros.com)
30: * @version CVS $Id: EPMerge.java 433543 2006-08-22 06:22:54Z crossley $
31: */
32: public class EPMerge extends BaseElementProcessor {
33:
34: private String _cellRange;
35:
36: /**
37: * constructor
38: */
39: public EPMerge() {
40: super (null);
41: _cellRange = null;
42: }
43:
44: public String getCellRange() {
45: if (this ._cellRange == null) {
46: //pulls in the content
47: _cellRange = this .getData();
48: }
49: return this ._cellRange;
50: }
51:
52: /**
53: * Setup the merged regions
54: * @exception IOException
55: */
56: public void endProcessing() throws IOException {
57: RangeAddress rangeAddress = new RangeAddress(getCellRange());
58: Sheet sheet = this .getSheet();
59:
60: //subtracting one since rangeaddress starts at 1,1 where rows/cols
61: // start at 0,0
62: short fromCol = (short) (rangeAddress.getXPosition(rangeAddress
63: .getFromCell()) - 1);
64: int fromRow = rangeAddress.getYPosition(rangeAddress
65: .getFromCell()) - 1;
66: short toCol = (short) (rangeAddress.getXPosition(rangeAddress
67: .getToCell()) - 1);
68: int toRow = rangeAddress.getYPosition(rangeAddress.getToCell()) - 1;
69:
70: if (getLogger().isDebugEnabled()) {
71: getLogger().debug(
72: "Merging Range: Row (" + fromRow + ") Col ("
73: + fromCol + ")" + " to Row (" + toRow
74: + ") Col (" + toCol + ")");
75: }
76: Region region = new Region(fromRow, fromCol, toRow, toCol);
77: sheet.addMergedRegion(region);
78: }
79:
80: } // end public class EPMerge
|