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