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 org.w3c.dom.NodeList;
27 import org.w3c.dom.Node;
28 
29 import java.io.IOException;
30 
31 import org.openoffice.xmerge.Document;
32 import org.openoffice.xmerge.ConvertData;
33 import org.openoffice.xmerge.ConvertException;
34 import org.openoffice.xmerge.converter.xml.sxc.SxcDocumentSerializer;
35 import org.openoffice.xmerge.converter.xml.sxc.pexcel.records.Workbook;
36 
37 /**
38  *  <p>Pocket Excel implementation of <code>SxcDocumentDeserializer</code>
39  *  for the {@link
40  *  org.openoffice.xmerge.converter.xml.sxc.pexcel.PluginFactoryImpl
41  *  PluginFactoryImpl}.</p>
42  *
43  *  <p>This converts StarOffice XML format to a set of files in
44  *  Pocket Excel PXL format.</p>
45  *
46  *  @author      Paul Rank
47  *  @author      Mark Murnane
48  */
49 public final class SxcDocumentSerializerImpl extends SxcDocumentSerializer {
50 
51 
52     /**
53      *  Constructor.
54      *
55      *  @param  document  The <code>Document</code> to convert.
56      */
SxcDocumentSerializerImpl(Document document)57     public SxcDocumentSerializerImpl(Document document) {
58         super(document);
59     }
60 
61 
serialize()62     public ConvertData serialize() throws ConvertException, IOException {
63 
64         // Get the server side document name.  This value should not
65         // contain a path or the file extension.
66         String docName = sxcDoc.getName();
67 
68         // TODO - get real values for password when implemnted in XML
69         // Passwords are not currently stored in StarCalc XML format.
70         String password = null;
71 
72 		encoder = new PocketExcelEncoder(docName, password);
73 
74         // get dom document
75         org.w3c.dom.Document domDoc = sxcDoc.getContentDOM();
76 
77 		// load the styles
78 		loadStyles(sxcDoc);
79         //  Traverse to the office:body element.
80         //  There should only be one.
81         NodeList list = domDoc.getElementsByTagName(TAG_OFFICE_BODY);
82         int len = list.getLength();
83 
84         if (len > 0) {
85             Node node = list.item(0);
86             traverseBody(node);
87         }
88 
89         // get settings for this document
90 	    org.w3c.dom.Document settingsDoc = sxcDoc.getSettingsDOM();
91 		if(settingsDoc!=null) {
92 			NodeList settingsList = settingsDoc.getElementsByTagName(TAG_OFFICE_SETTINGS);
93 			int slen = settingsList.getLength();
94 
95 	        if (slen > 0) {
96     	        Node settingsNode = settingsList.item(0);
97         	    traverseSettings(settingsNode);
98 	        }
99 		}
100 
101         // Get the number of sheets in the workbook
102         // This will equal the number of PDBs we need
103         ConvertData cd = new ConvertData();
104 		Workbook wb = ((PocketExcelEncoder) encoder).getWorkbook();
105 		cd.addDocument(wb);
106 
107         return cd;
108     }
109 
110 
111     /**
112      *  A cell reference in a StarOffice formula looks like
113      *  [.C2] (for cell C2).  MiniCalc is expecting cell references
114      *  to look like C2.  This method strips out the braces and
115      *  the period.
116      *
117      *  @param  formula  A StarOffice formula <code>String</code>.
118      *
119      *  @return  A MiniCalc formula <code>String</code>.
120      */
parseFormula(String formula)121     protected String parseFormula(String formula) {
122 
123         return null;
124     }
125 }
126 
127