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; 25 26 import org.openoffice.xmerge.util.registry.ConverterInfo; 27 import java.io.InputStream; 28 import java.io.IOException; 29 30 /** 31 * <p>A <code>PluginFactory</code> encapsulates the 32 * conversions from one <code>Document</code> format to another. 33 * It provides conversions in both directions. Refer to the 34 * <a href="package-summary.html#package_description"> 35 * package description</a> for its usage.</p> 36 * 37 * <p>Conversion from the "Office" <code>Document</code> 38 * format to a "Device" <code>Document</code> format may 39 * be lossy, i.e. some information may be lost. If a plug-in 40 * implements the <code>DocumentMergerFactory</code> interface, 41 * then there is the possibility for merging the changes done on the 42 * "Device" <code>Document</code> back to the original 43 * "Office" <code>Document</code> via the 44 * <code>DocumentMerger</code> interface.</p> 45 * 46 * <p>Plug-ins that convert from the "Device" 47 * <code>Document</code> format to the "Office" 48 * <code>Document</code> format must implement the 49 * <code>DocumentDeserializerFactory</code> interface. Plug-ins 50 * that convert from the "Office" <code>Document</code> 51 * format to the "Device" format must implement the 52 * <code>DocumentSerializerFactory</code> interface. 53 * 54 * <p>All plug-ins should have an associated Plugin Configuration XML 55 * File which describes the capabilities of the plug-in. If the 56 * plug-in is bundled in a jarfile, then this XML file is also bundled 57 * with the jarfile. The data in the XML file is managed by the 58 * <code>ConverterInfo</code> object. The <code>ConverterInfoMgr</code> 59 * manages a registry of all <code>ConverterInfo</code> objects. For 60 * more information about this XML file, refer to 61 * <a href="converter/xml/sxc/package-summary.html"> 62 * org.openoffice.xmerge.util.registry</a>.</p> 63 * 64 * @author Herbie Ong 65 * @see Document 66 * @see DocumentSerializer 67 * @see DocumentSerializerFactory 68 * @see DocumentDeserializer 69 * @see DocumentDeserializerFactory 70 * @see DocumentMerger 71 * @see DocumentMergerFactory 72 * @see ConverterInfo 73 * @see org.openoffice.xmerge.util.registry.ConverterInfoMgr 74 */ 75 76 public abstract class PluginFactory { 77 78 /** 79 * Cached <code>ConvertInfo</code> object. 80 */ 81 private ConverterInfo ciCache; 82 83 84 /** 85 * Constructor that caches the <code>ConvertInfo</code> that 86 * corresponds to the registry information for this plug-in. 87 * 88 * @param ci <code>ConvertInfo</code> object. 89 */ PluginFactory(ConverterInfo ci)90 public PluginFactory(ConverterInfo ci) { 91 ciCache=ci; 92 } 93 94 95 /** 96 * Returns the <code>ConvertInfo</code> that corresponds to this 97 * plug-in. 98 * 99 * @return The <code>ConvertInfo</code> that corresponds to this 100 * plug-in. 101 */ getConverterInfo()102 public ConverterInfo getConverterInfo () { 103 return ciCache; 104 } 105 106 107 /** 108 * <p>Create a <code>Document</code> object that corresponds to 109 * the Office data passed in via the <code>InputStream</code> 110 * object. This abstract method must be implemented for each 111 * plug-in.</p> 112 * 113 * <p>This method will read from the given <code>InputStream</code> 114 * object. The returned <code>Document</code> object will contain 115 * the necessary data for the other objects created by the 116 * <code>PluginFactory</code> to process, like a 117 * <code>DocumentSerializer</code> object and a 118 * <code>DocumentMerger</code> object.</p> 119 * 120 * @param name The <code>Document</code> name. 121 * @param is <code>InputStream</code> object corresponding 122 * to the <code>Document</code>. 123 * 124 * @return A <code>Document</code> object representing the 125 * particular <code>Document</code> format for the 126 * <code>PluginFactory</code>. 127 * 128 * @throws IOException If any I/O error occurs. 129 */ createOfficeDocument(String name, InputStream is)130 public abstract Document createOfficeDocument(String name, InputStream is) 131 throws IOException; 132 133 134 /** 135 * <p>Create a <code>Document</code> object that corresponds to 136 * the Office data passed in via the <code>InputStream</code> 137 * object. This abstract method must be implemented for each 138 * plug-in.</p> 139 * 140 * <p>This method will read from the given <code>InputStream</code> 141 * object. The returned <code>Document</code> object will contain 142 * the necessary data for the other objects created by the 143 * <code>PluginFactory</code> to process, like a 144 * <code>DocumentSerializer</code> object and a 145 * <code>DocumentMerger</code> object.</p> 146 * 147 * @param name The <code>Document</code> name. 148 * @param is <code>InputStream</code> object corresponding 149 * to the <code>Document</code>. 150 * @param isZip <code>boolean</code> to show that the created office 151 * document is to be zipped. 152 * 153 * @return A <code>Document</code> object representing the 154 * particular <code>Document</code> format for the 155 * <code>PluginFactory</code>. 156 * 157 * @throws IOException If any I/O error occurs. 158 */ createOfficeDocument(String name, InputStream is,boolean isZip)159 public abstract Document createOfficeDocument(String name, InputStream is,boolean isZip) 160 throws IOException; 161 162 163 /** 164 * <p>Create a <code>Document</code> object that corresponds to 165 * the device data passed in via the <code>InputStream</code> 166 * object. This abstract method must be implemented for each 167 * plug-in.</p> 168 * 169 * <p>This method will read from the given <code>InputStream</code> 170 * object. The returned <code>Document</code> object will contain 171 * the necessary data for the other objects created by the 172 * <code>PluginFactory</code> to process, like a 173 * <code>DocumentSerializer</code> object and a 174 * <code>DocumentMerger</code> object.</p> 175 * 176 * @param name The <code>Document</code> name. 177 * @param is <code>InputStream</code> object corresponding 178 * to the <code>Document</code>. 179 * 180 * @return A <code>Document</code> object representing the 181 * particular <code>Document</code> format for the 182 * <code>PluginFactory</code>. 183 * 184 * @throws IOException If any I/O error occurs. 185 */ createDeviceDocument(String name, InputStream is)186 public abstract Document createDeviceDocument(String name, InputStream is) 187 throws IOException; 188 } 189 190