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 java.awt.Color; 27 28 import org.w3c.dom.NodeList; 29 import org.w3c.dom.Node; 30 import org.w3c.dom.NamedNodeMap; 31 import org.w3c.dom.Element; 32 33 import java.io.IOException; 34 35 import org.openoffice.xmerge.Document; 36 import org.openoffice.xmerge.ConvertData; 37 import org.openoffice.xmerge.ConvertException; 38 import org.openoffice.xmerge.converter.palm.PalmDB; 39 import org.openoffice.xmerge.converter.palm.Record; 40 import org.openoffice.xmerge.converter.palm.PalmDocument; 41 42 import jmc.JMCconstants; 43 44 import org.openoffice.xmerge.converter.xml.sxc.Format; 45 import org.openoffice.xmerge.converter.xml.sxc.SxcDocumentSerializer; 46 47 /** 48 * <p>MiniCalc implementation of <code>SxcDocumentDeserializer</code> 49 * for the {@link 50 * org.openoffice.xmerge.converter.xml.sxc.minicalc.PluginFactoryImpl 51 * PluginFactoryImpl}.</p> 52 * 53 * <p>This converts StarOffice XML format to a set of files in 54 * MiniCalc PDB format.</p> 55 * 56 * @author Paul Rank 57 * @author Mark Murnane 58 */ 59 public final class SxcDocumentSerializerImpl extends SxcDocumentSerializer { 60 61 62 /** 63 * Constructor. 64 * 65 * @param document The <code>Document</code> to convert. 66 */ SxcDocumentSerializerImpl(Document document)67 public SxcDocumentSerializerImpl(Document document) { 68 super(document); 69 } 70 71 serialize()72 public ConvertData serialize() throws ConvertException, IOException { 73 74 75 // Get the server side document name. This value should not 76 // contain a path or the file extension. 77 String docName = sxcDoc.getName(); 78 79 // TODO - get real values for password when implemnted in XML 80 // Passwords are not currently stored in StarCalc XML format. 81 String password = null; 82 83 encoder = new MinicalcEncoder(docName, password); 84 85 // get dom document 86 org.w3c.dom.Document domDoc = sxcDoc.getContentDOM(); 87 88 // Traverse to the office:body element. 89 // There should only be one. 90 NodeList list = domDoc.getElementsByTagName(TAG_OFFICE_BODY); 91 int len = list.getLength(); 92 93 if (len > 0) { 94 Node node = list.item(0); 95 traverseBody(node); 96 } 97 98 // Get the number of sheets in the workbook 99 // This will equal the number of PDBs we need 100 ConvertData cd = new ConvertData(); 101 int numSheets = encoder.getNumberOfSheets(); 102 103 for (int i = 0; i < numSheets; i++) { 104 105 // Get records for sheet i 106 Record records[] = ((MinicalcEncoder) encoder).getRecords(i); 107 108 // Get the sheet name for sheet i 109 String fullSheetName = new String(docName 110 + "-" 111 + encoder.getSheetName(i)); 112 113 // Create a PalmDB object 114 PalmDocument palmDoc = new PalmDocument(fullSheetName, 115 MinicalcConstants.CREATOR_ID, 116 MinicalcConstants.TYPE_ID, JMCconstants.AppVersion, 117 PalmDB.PDB_HEADER_ATTR_BACKUP, records); 118 119 cd.addDocument(palmDoc); 120 } 121 122 123 // OutputStream os = new FileOutputStream(docName); 124 125 //pdbSet.write(os); 126 //os.flush(); 127 128 //ConvertDataEntry cde = new ConvertDataOutputStream(os, docName); 129 //cd.addCDE(cde); 130 131 return cd; 132 } 133 134 135 136 } 137 138