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.minicalc; 25 26 import org.openoffice.xmerge.converter.xml.sxc.SxcDocumentDeserializer; 27 import org.openoffice.xmerge.converter.xml.sxc.SpreadsheetDecoder; 28 import org.openoffice.xmerge.converter.palm.PalmDB; 29 import org.openoffice.xmerge.ConvertData; 30 import org.openoffice.xmerge.converter.palm.PalmDocument; 31 32 import java.io.IOException; 33 import java.util.Enumeration; 34 35 /** 36 * <p>MiniCalc implementation of <code>DocumentDeserializer</code> 37 * for the {@link 38 * org.openoffice.xmerge.converter.xml.sxc.minicalc.PluginFactoryImpl 39 * PluginFactoryImpl}.</p> 40 * 41 * <p>This converts a set of files in MiniCalc PDB format to a StarOffice DOM.</p> 42 * 43 * @author Mark Murnane 44 */ 45 public final class SxcDocumentDeserializerImpl extends SxcDocumentDeserializer { 46 47 /** 48 * Creates new <code>SxcDocumentDeserializerImpl</code>. 49 * 50 * @param cd <code>ConvertData</code> Input data to convert. 51 */ SxcDocumentDeserializerImpl(ConvertData cd)52 public SxcDocumentDeserializerImpl(ConvertData cd) { 53 super(cd); 54 } 55 56 57 /** 58 * This method will be implemented by concrete subclasses and will 59 * return an application-specific decoder. 60 * 61 * @param workbook The WorkBook name. 62 * @param worksheetNames An array of WorkSheet names. 63 * @param password The password. 64 * 65 * @return An application-specific <code>SpreadsheetDecoder</code>. 66 */ createDecoder(String workbook, String[] worksheetNames, String password)67 public SpreadsheetDecoder createDecoder(String workbook, 68 String[] worksheetNames, String password) throws IOException { 69 70 return new MinicalcDecoder(workbook, worksheetNames, password); 71 } 72 73 74 /** 75 * This method will return the name of the WorkBook from the 76 * <code>ConvertData</code>. Allows for situations where the 77 * WorkBook name differs from the PDB name. 78 * 79 * Implemented in the Deserializer as the Decoder's constructor 80 * requires a name. 81 * 82 * @param cd The <code>ConvertData</code>. 83 * 84 * @return The name of the WorkBook. 85 */ getWorkbookName(ConvertData cd)86 protected String getWorkbookName(ConvertData cd) 87 throws IOException { 88 89 Enumeration e = cd.getDocumentEnumeration(); 90 PalmDocument palmDoc = (PalmDocument) e.nextElement(); 91 String workbookName = palmDoc.getName(); 92 93 // Search for "-", which separates workbook from worksheet 94 int end = workbookName.indexOf("-"); 95 96 if (end > 0) { 97 workbookName = workbookName.substring(0, end); 98 } 99 100 return workbookName; 101 } 102 103 104 /** 105 * This method will return an array of WorkSheet names from the 106 * <code>ConvertData</code>. 107 * 108 * @param cd The <code>ConvertData</code>. 109 * 110 * @return The name of the WorkSheet. 111 */ getWorksheetNames(ConvertData cd)112 protected String[] getWorksheetNames(ConvertData cd) 113 throws IOException { 114 int numberOfPDBs = cd.getNumDocuments(); 115 String worksheetName[] = new String[numberOfPDBs]; 116 int i=0; 117 Enumeration e = cd.getDocumentEnumeration(); 118 while (e.hasMoreElements()) { 119 PalmDocument palmDoc = (PalmDocument) e.nextElement(); 120 worksheetName[i] = palmDoc.getName(); 121 122 // Search for the "-", which seperates workbook from worksheet 123 int start = worksheetName[i].indexOf("-"); 124 125 if (start != -1) { 126 worksheetName[i] = worksheetName[i].substring(start + 1); 127 } 128 i++; 129 } 130 131 return worksheetName; 132 } 133 } 134 135