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.pocketword; 25 26 27 import java.io.InputStream; 28 import java.io.IOException; 29 30 import org.openoffice.xmerge.ConvertData; 31 import org.openoffice.xmerge.Document; 32 import org.openoffice.xmerge.DocumentDeserializer; 33 import org.openoffice.xmerge.DocumentSerializer; 34 import org.openoffice.xmerge.DocumentDeserializerFactory; 35 import org.openoffice.xmerge.DocumentSerializerFactory; 36 import org.openoffice.xmerge.DocumentMerger; 37 import org.openoffice.xmerge.DocumentMergerFactory; 38 import org.openoffice.xmerge.ConverterCapabilities; 39 40 import org.openoffice.xmerge.util.registry.ConverterInfo; 41 42 import org.openoffice.xmerge.converter.xml.sxw.SxwPluginFactory; 43 44 45 /** 46 * Factory class used to create converters to/from the Pocket Word format. 47 * 48 * @author Mark Murnane 49 * @version 1.1 50 */ 51 public final class PluginFactoryImpl extends SxwPluginFactory 52 implements DocumentDeserializerFactory, DocumentSerializerFactory, 53 DocumentMergerFactory{ 54 55 /** 56 * <p>Constructor that caches the <code>ConvertInfo</code> that 57 * corresponds to the registry information for this plug-in.</p> 58 * 59 * @param ci <code>ConvertInfo</code> object. 60 */ PluginFactoryImpl(ConverterInfo ci)61 public PluginFactoryImpl (ConverterInfo ci) { 62 super(ci); 63 } 64 65 /** ConverterCapabilities object for this type of conversion. */ 66 private final static ConverterCapabilities converterCap = 67 new ConverterCapabilitiesImpl(); 68 69 70 /** 71 * <p>The <code>DocumentSerializer</code> is used to convert 72 * from the OpenOffice.org XML Writer <code>Document</code> format 73 * to the Pocket Word <code>Document</code> format.</p> 74 * 75 * <p>The <code>ConvertData</code> object is passed along to the 76 * created <code>DocumentSerializer</code> via its constructor. 77 * The <code>ConvertData</code> is read and converted when the 78 * the <code>DocumentSerializer</code> object's 79 * <code>serialize</code> method is called.</p> 80 * 81 * @param doc <code>Document</code> object that the created 82 * <code>DocumentSerializer</code> object uses 83 * as input. 84 * 85 * @return A <code>DocumentSerializer</code> object. 86 */ createDocumentSerializer(Document doc)87 public DocumentSerializer createDocumentSerializer(Document doc) { 88 return new DocumentSerializerImpl(doc); 89 } 90 91 92 /** 93 * <p>The <code>DocumentDeserializer</code> is used to convert 94 * from the Pocket Word <code>Document</code> format to 95 * the OpenOffice.org XML Writer <code>Document</code> format.</p> 96 * 97 * <p>The <code>ConvertData</code> object is passed along to the 98 * created <code>DocumentDeserializer</code> via its constructor. 99 * The <code>ConvertData</code> is read and converted when the 100 * the <code>DocumentDeserializer</code> object's 101 * <code>deserialize</code> method is called. 102 * </p> 103 * 104 * @param cd <code>ConvertData</code> object that the created 105 * <code>DocumentDeserializer</code> object uses as 106 * input. 107 * 108 * @return A <code>DocumentDeserializer</code> object. 109 */ createDocumentDeserializer(ConvertData cd)110 public DocumentDeserializer createDocumentDeserializer(ConvertData cd) { 111 return new DocumentDeserializerImpl(cd); 112 } 113 114 115 /** 116 * <p>Create a <code>Document</code> object that corresponds to 117 * the Pocket Word data passed in via the <code>InputStream</code> 118 * object. 119 * 120 * <p>This method will read from the given <code>InputStream</code> 121 * object. The returned <code>Document</code> object will contain 122 * the necessary data for the other objects created by the 123 * <code>PluginFactoryImpl</code> to process, like the 124 * <code>DocumentSerializerImpl</code> object and a 125 * <code>DocumentMerger</code> object.</p> 126 * 127 * @param name The <code>Document</code> name. 128 * @param is <code>InputStream</code> object corresponding 129 * to the <code>Document</code>. 130 * 131 * @return A <code>Document</code> object representing the 132 * Pocket Word format. 133 * 134 * @throws IOException If any I/O error occurs. 135 */ 136 createDeviceDocument(String name, InputStream is)137 public Document createDeviceDocument(String name, InputStream is) 138 throws IOException { 139 PocketWordDocument pwd = new PocketWordDocument(name); 140 pwd.read(is); 141 return pwd; 142 } 143 144 /** 145 * Returns an instance of <code>DocumentMergerImpl</code>, 146 * which is an implementation of the <code>DocumentMerger</code> 147 * interface. 148 * 149 * @param doc <code>Document</code> to merge. 150 * 151 * @return A DocumentMergerImpl object. 152 */ createDocumentMerger(Document doc)153 public DocumentMerger createDocumentMerger(Document doc) { 154 ConverterCapabilities cc = converterCap; 155 DocumentMergerImpl merger = new DocumentMergerImpl(doc, cc); 156 return merger; 157 158 } 159 160 } 161