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.io.InputStream; 28 29 import org.openoffice.xmerge.ConvertData; 30 import org.openoffice.xmerge.Document; 31 import org.openoffice.xmerge.DocumentSerializer; 32 import org.openoffice.xmerge.DocumentSerializerFactory; 33 import org.openoffice.xmerge.DocumentDeserializer; 34 import org.openoffice.xmerge.DocumentDeserializerFactory; 35 import org.openoffice.xmerge.DocumentMerger; 36 import org.openoffice.xmerge.ConverterCapabilities; 37 import org.openoffice.xmerge.converter.xml.sxc.DocumentMergerImpl; 38 import org.openoffice.xmerge.converter.xml.sxc.SxcPluginFactory; 39 import org.openoffice.xmerge.converter.xml.sxc.pexcel.records.Workbook; 40 import org.openoffice.xmerge.util.registry.ConverterInfo; 41 42 /** 43 * <p>Pocket Excel implementation of the <code>PluginFactory</code>. 44 * This encapsulates conversion of StarCalc XML format to and from 45 * Pocket Excel format.</p> 46 * 47 * <p>The superclass produces a particular 48 * {@link org.openoffice.xmerge.Document Document} 49 * object, i.e. {@link 50 * org.openoffice.xmerge.converter.xml.sxc.SxcDocument 51 * SxcDocument} that the converters in this class works with. Thus, 52 * this class only implements the methods that produces the converters, 53 * i.e. {@link 54 * org.openoffice.xmerge.DocumentSerializer 55 * DocumentSerializer} and {@link 56 * org.openoffice.xmerge.DocumentDeserializer 57 * DocumentDeserializer}; 58 * as well as the {@link 59 * org.openoffice.xmerge.ConverterCapabilities 60 * ConverterCapabilities} object that is specific to this format 61 * conversion. That superclass also produces a {@link 62 * org.openoffice.xmerge.DocumentMerger DocumentMerger} 63 * object, i.e. {@link 64 * org.openoffice.xmerge.converter.xml.sxc.DocumentMergerImpl 65 * DocumentMergerImpl} which this class derives the functionality.</p> 66 */ 67 public final class PluginFactoryImpl extends SxcPluginFactory 68 implements DocumentDeserializerFactory, DocumentSerializerFactory { 69 70 /** ConverterCapabilities object for this type of conversion. */ 71 private final static ConverterCapabilities converterCap = 72 new ConverterCapabilitiesImpl(); 73 74 PluginFactoryImpl(ConverterInfo ci)75 public PluginFactoryImpl(ConverterInfo ci) { 76 super(ci); 77 } 78 79 80 /** 81 * Returns an instance of <code>DocumentSerializerImpl</code>, 82 * which is an implementation of <code>DocumentSerializer</code> 83 * interface. 84 * 85 * @param doc <code>Document</code> object to be 86 * converted/serialized. 87 * 88 * @return A <code>DocumentSerializerImpl</code> object. 89 */ createDocumentSerializer(Document doc)90 public DocumentSerializer createDocumentSerializer(Document doc) { 91 92 return new SxcDocumentSerializerImpl(doc); 93 } 94 95 96 /** 97 * Returns an instance of <code>DocumentDeserializerImpl</code>, 98 * which is an implementation of <code>DocumentDeserializer</code> 99 * interface. 100 * 101 * @param cd <code>ConvertData</code> object for reading data 102 * which will be converted back to a 103 * <code>Document</code> object. 104 * 105 * @return A <code>DocumentDeserializerImpl</code> object. 106 */ createDocumentDeserializer(ConvertData cd)107 public DocumentDeserializer createDocumentDeserializer(ConvertData cd) { 108 109 return new SxcDocumentDeserializerImpl(cd); 110 } 111 112 createDeviceDocument(String name, InputStream is)113 public Document createDeviceDocument(String name, InputStream is) 114 throws IOException { 115 116 Workbook wb = new Workbook(name, is); 117 return wb; 118 } 119 createDocumentMerger(Document doc)120 public DocumentMerger createDocumentMerger(Document doc) { 121 122 DocumentMergerImpl merger = new DocumentMergerImpl(doc, converterCap); 123 return merger; 124 } 125 } 126 127