1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.xmerge.converter.xml.sxc.pexcel;
25 
26 import java.io.IOException;
27 import java.util.Enumeration;
28 import java.util.Vector;
29 
30 import org.openoffice.xmerge.util.Debug;
31 import org.openoffice.xmerge.ConvertData;
32 import org.openoffice.xmerge.converter.xml.sxc.SpreadsheetDecoder;
33 import org.openoffice.xmerge.converter.xml.sxc.SxcDocumentDeserializer;
34 import org.openoffice.xmerge.converter.xml.sxc.pexcel.PocketExcelDecoder;
35 import org.openoffice.xmerge.converter.xml.sxc.pexcel.records.Workbook;
36 
37 
38 /**
39  *  <p>Pocket Excel implementation of <code>DocumentDeserializer</code>
40  *  for the {@link
41  *  org.openoffice.xmerge.converter.xml.sxc.pexcel.PluginFactoryImpl
42  *  PluginFactoryImpl}.</p>
43  *
44  *  <p>This converts a set of files in Pocket Excel PXL format to a StarOffice DOM.</p>
45  *
46  *  @author  Mark Murnane
47  */
48 public final class SxcDocumentDeserializerImpl extends SxcDocumentDeserializer {
49 
50     /**
51      *  Creates new <code>SxcDocumentDeserializerImpl</code>.
52      *
53      *  @param  cd  <code>ConvertData</code>  Input data to convert.
54      */
SxcDocumentDeserializerImpl(ConvertData cd)55     public SxcDocumentDeserializerImpl(ConvertData cd) {
56         super(cd);
57     }
58 
59 
60     /**
61      *  This method will be implemented by concrete subclasses and will
62      *  return an application-specific decoder.
63      *
64      *  @param  workbook        The WorkBook name.
65      *  @param  worksheetNames  An array of WorkSheet names.
66      *  @param  password        The password.
67      *
68      *  @return  An application-specific <code>SpreadsheetDecoder</code>.
69      */
createDecoder(String workbook, String[] worksheetNames, String password)70     public SpreadsheetDecoder createDecoder(String workbook,
71         String[] worksheetNames, String password) throws IOException {
72 
73         return new PocketExcelDecoder(workbook, worksheetNames, password);
74     }
75 
76 
77     /**
78      *  This method will return the name of the WorkBook from the
79      *  <code>ConvertData</code>.  Allows for situations where the
80      *  WorkBook name differs from the PDB name.
81      *
82      *  Implemented in the Deserializer as the Decoder's constructor
83      *  requires a name.
84      *
85      *  @param  cd  The <code>ConvertData</code>.
86      *
87      *  @return  The name of the WorkBook.
88      */
getWorkbookName(ConvertData cd)89     protected String getWorkbookName(ConvertData cd)
90         throws IOException {
91 
92         Enumeration e = cd.getDocumentEnumeration();
93 		Workbook wb = (Workbook) e.nextElement();
94 
95 		String workbookName = wb.getName();
96         return workbookName;
97     }
98 
99 
100     /**
101      *  This method will return an array of WorkSheet names from the
102      *  <code>ConvertData</code>.
103      *
104      *  @param  cd  The <code>ConvertData</code>.
105      *
106      *  @return  The name of the WorkSheet.
107      */
getWorksheetNames(ConvertData cd)108     protected String[] getWorksheetNames(ConvertData cd)
109         throws IOException {
110 
111         Enumeration e = cd.getDocumentEnumeration();
112 		Workbook wb = (Workbook) e.nextElement();
113 		Vector v = wb.getWorksheetNames();
114 		e = v.elements();
115 		String worksheetNames[] = new String[v.size()];
116 		int i = 0;
117 		while(e.hasMoreElements()) {
118 			worksheetNames[i] = (String) e.nextElement();
119 			Debug.log(Debug.TRACE,"Worksheet Name : " + worksheetNames[i]);
120 			i++;
121 		}
122 		return worksheetNames;
123     }
124 }
125 
126