KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf;
17
18 import org.apache.cocoon.components.elementprocessor.CannotCreateElementProcessorException;
19 import org.apache.cocoon.components.elementprocessor.ElementProcessor;
20 import org.apache.cocoon.components.elementprocessor.LocaleAware;
21 import org.apache.cocoon.components.elementprocessor.impl.AbstractElementProcessorFactory;
22 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPAttribute;
23 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPAttributes;
24 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPBottom;
25 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPButton;
26 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPCell;
27 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPCellComment;
28 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPCells;
29 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPCheckbox;
30 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPColInfo;
31 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPCols;
32 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPConstr;
33 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPContent;
34 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPDiagonal;
35 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPFont;
36 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPFooter;
37 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPFrame;
38 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPGeometry;
39 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPHeader;
40 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPItem;
41 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPLabel;
42 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPLeft;
43 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPMargins;
44 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPMaxCol;
45 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPMaxRow;
46 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPMerge;
47 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPMergedRegions;
48 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPName;
49 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPNames;
50 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPObjects;
51 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPPrintInformation;
52 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPRev_Diagonal;
53 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPRight;
54 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPRowInfo;
55 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPRows;
56 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPSelection;
57 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPSelections;
58 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPSheet;
59 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPSheetName;
60 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPSheetNameIndex;
61 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPSheetObjectBonobo;
62 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPSheetObjectFilled;
63 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPSheets;
64 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPSolver;
65 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPStyle;
66 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPStyleBorder;
67 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPStyleRegion;
68 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPStyles;
69 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPSummary;
70 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPTop;
71 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPUIData;
72 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPWorkbook;
73 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EPZoom;
74 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Bottom;
75 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Default_;
76 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Draft;
77 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_EvenIfOnlyStyles;
78 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Footer;
79 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Grid;
80 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_HCenter;
81 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Header;
82 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Left;
83 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Monochrome;
84 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Name;
85 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Order;
86 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Orientation;
87 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Paper;
88 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_RepeatLeft;
89 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_RepeatTop;
90 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Right;
91 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Titles;
92 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Top;
93 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Type;
94 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_VCenter;
95 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_ValString;
96 import org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements.EP_Value;
97
98 /**
99  * a simple extension of ElementProcessorFactory that maps the HSSF
100  * XML element names to HSSF-specific ElementProcessor progenitor
101  * objects.
102  *
103  * @author Marc Johnson (marc_johnson27591@hotmail.com)
104  * @version CVS $Id: HSSFElementProcessorFactory.java 30932 2004-07-29 17:35:38Z vgritsenko $
105  */

106 public class HSSFElementProcessorFactory
107     extends AbstractElementProcessorFactory
108 {
109     //holds the locale configuration
110
String JavaDoc locale;
111     /**
112      * default constructor
113      */

114
115     public HSSFElementProcessorFactory(String JavaDoc locale)
116     {
117         super();
118         this.locale=locale;
119         addElementProcessorProgenitor("Attribute", EPAttribute.class);
120         addElementProcessorProgenitor("Attributes", EPAttributes.class);
121         addElementProcessorProgenitor("Bottom", EPBottom.class);
122         addElementProcessorProgenitor("bottom", EP_Bottom.class);
123         addElementProcessorProgenitor("Button", EPButton.class);
124         addElementProcessorProgenitor("Cell", EPCell.class);
125         addElementProcessorProgenitor("CellComment", EPCellComment.class);
126         addElementProcessorProgenitor("Cells", EPCells.class);
127         addElementProcessorProgenitor("Checkbox", EPCheckbox.class);
128         addElementProcessorProgenitor("ColInfo", EPColInfo.class);
129         addElementProcessorProgenitor("Cols", EPCols.class);
130         addElementProcessorProgenitor("Constr", EPConstr.class);
131         addElementProcessorProgenitor("Content", EPContent.class);
132         addElementProcessorProgenitor("Diagonal", EPDiagonal.class);
133         addElementProcessorProgenitor("draft", EP_Draft.class);
134         addElementProcessorProgenitor("even_if_only_styles",
135                                       EP_EvenIfOnlyStyles.class);
136         addElementProcessorProgenitor("Font", EPFont.class);
137         addElementProcessorProgenitor("Footer", EPFooter.class);
138         addElementProcessorProgenitor("footer", EP_Footer.class);
139         addElementProcessorProgenitor("Frame", EPFrame.class);
140         addElementProcessorProgenitor("Geometry", EPGeometry.class);
141         addElementProcessorProgenitor("grid", EP_Grid.class);
142         addElementProcessorProgenitor("hcenter", EP_HCenter.class);
143         addElementProcessorProgenitor("Header", EPHeader.class);
144         addElementProcessorProgenitor("header", EP_Header.class);
145         addElementProcessorProgenitor("Item", EPItem.class);
146         addElementProcessorProgenitor("Label", EPLabel.class);
147         addElementProcessorProgenitor("Left", EPLeft.class);
148         addElementProcessorProgenitor("left", EP_Left.class);
149         addElementProcessorProgenitor("Margins", EPMargins.class);
150         addElementProcessorProgenitor("MaxCol", EPMaxCol.class);
151         addElementProcessorProgenitor("MaxRow", EPMaxRow.class);
152         addElementProcessorProgenitor("Merge", EPMerge.class);
153         addElementProcessorProgenitor("MergedRegions", EPMergedRegions.class);
154         addElementProcessorProgenitor("monochrome", EP_Monochrome.class);
155         addElementProcessorProgenitor("Name", EPName.class);
156         addElementProcessorProgenitor("name", EP_Name.class);
157         addElementProcessorProgenitor("Names", EPNames.class);
158         addElementProcessorProgenitor("Objects", EPObjects.class);
159         addElementProcessorProgenitor("order", EP_Order.class);
160         addElementProcessorProgenitor("orientation", EP_Orientation.class);
161         addElementProcessorProgenitor("paper", EP_Paper.class);
162         addElementProcessorProgenitor("PrintInformation",
163                                       EPPrintInformation.class);
164         addElementProcessorProgenitor("repeat_left", EP_RepeatLeft.class);
165         addElementProcessorProgenitor("repeat_top", EP_RepeatTop.class);
166         addElementProcessorProgenitor("Rev-Diagonal", EPRev_Diagonal.class);
167         addElementProcessorProgenitor("Right", EPRight.class);
168         addElementProcessorProgenitor("right", EP_Right.class);
169         addElementProcessorProgenitor("RowInfo", EPRowInfo.class);
170         addElementProcessorProgenitor("Rows", EPRows.class);
171         addElementProcessorProgenitor("Selection", EPSelection.class);
172         addElementProcessorProgenitor("Sheet", EPSheet.class);
173         addElementProcessorProgenitor("SheetName", EPSheetName.class);
174         addElementProcessorProgenitor("SheetNameIndex",
175                                       EPSheetNameIndex.class);
176         addElementProcessorProgenitor("SheetObjectBonobo",
177                                       EPSheetObjectBonobo.class);
178         addElementProcessorProgenitor("SheetObjectFilled",
179                                       EPSheetObjectFilled.class);
180         addElementProcessorProgenitor("Sheets", EPSheets.class);
181         addElementProcessorProgenitor("Selections", EPSelections.class);
182         addElementProcessorProgenitor("Solver", EPSolver.class);
183         addElementProcessorProgenitor("Style", EPStyle.class);
184         addElementProcessorProgenitor("StyleBorder", EPStyleBorder.class);
185         addElementProcessorProgenitor("StyleRegion", EPStyleRegion.class);
186         addElementProcessorProgenitor("Styles", EPStyles.class);
187         addElementProcessorProgenitor("Summary", EPSummary.class);
188         addElementProcessorProgenitor("titles", EP_Titles.class);
189         addElementProcessorProgenitor("Top", EPTop.class);
190         addElementProcessorProgenitor("top", EP_Top.class);
191         addElementProcessorProgenitor("type", EP_Type.class);
192         addElementProcessorProgenitor("UIData", EPUIData.class);
193         addElementProcessorProgenitor("val-string", EP_ValString.class);
194         addElementProcessorProgenitor("value", EP_Value.class);
195         addElementProcessorProgenitor("vcenter", EP_VCenter.class);
196         addElementProcessorProgenitor("Workbook", EPWorkbook.class);
197         addElementProcessorProgenitor("Zoom", EPZoom.class);
198         addElementProcessorProgenitor("*", EP_Default_.class);
199     }
200
201     /**
202      * create an ElementProcessor
203      *
204      * @param progenitor the Object from which the ElementProcessor
205      * will be created
206      *
207      * @return the new ElementProcessor
208      *
209      * @exception CannotCreateElementProcessorException
210      */

211
212     protected ElementProcessor doCreateElementProcessor(
213             final Object JavaDoc progenitor)
214             throws CannotCreateElementProcessorException {
215         ElementProcessor rval = null;
216
217         try {
218             rval = createNewElementProcessorInstance((Class JavaDoc)progenitor);
219
220             //every locale aware element processor is passed the locale string
221
if (rval instanceof LocaleAware) {
222                    ((LocaleAware)rval).setLocale(locale);
223             }
224         } catch (ClassCastException JavaDoc e) {
225             e.printStackTrace();
226             throw new CannotCreateElementProcessorException(
227                 "Progenitor is not an instance of Class");
228         }
229         return rval;
230     }
231 } // end public class HSSFElementProcessorFactory
232
Popular Tags