LibreOffice Module xmerge (master) 1
Convert.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19package org.openoffice.xmerge;
20
21import java.io.IOException;
22import java.io.InputStream;
23import java.util.Iterator;
24
26
38public class Convert implements Cloneable {
39
41 private final ConverterInfo ci;
42
47 private final boolean toOffice;
48
50 private final ConvertData inputCD = new ConvertData();
51
61 public Convert(ConverterInfo ci, boolean toOffice) {
62 this.ci = ci;
63 this.toOffice = toOffice;
64 }
65
80 public void addInputStream(String name, InputStream is)
81 throws IOException {
82
83 Document inputDoc;
84
85 if (toOffice) {
87 } else {
89 }
90 inputCD.addDocument(inputDoc);
91 }
92
108 public void addInputStream(String name, InputStream is,boolean isZip)
109 throws IOException {
110
111 Document inputDoc;
112
113 if (toOffice) {
115 } else {
116 inputDoc = ci.getPluginFactory().createOfficeDocument(name, is, isZip);
117 }
118 inputCD.addDocument(inputDoc);
119 }
120
121
131 public DocumentMerger getDocumentMerger(Document origDoc) throws IOException {
132 DocumentMergerFactory myDocMergerFactory = ci.getDocMergerFactory();
133 DocumentMerger merger = myDocMergerFactory.createDocumentMerger(origDoc);
134 return merger;
135 }
136
144 private void reset() {
145 inputCD.reset();
146 }
147
157 @Override
158 public Object clone() {
159
160 Convert aClone = null;
161
162 try {
163 aClone = (Convert) super.clone();
164 aClone.reset();
165 }
166 catch (CloneNotSupportedException e) {
167 System.out.println("Convert clone could not be created");
168 }
169 return aClone;
170 }
171
181 public ConvertData convert() throws ConvertException, IOException {
182
183 ConvertData dataOut = new ConvertData();
184
185 if (toOffice) {
186
187 // From device format to Office format
188
189 DocumentDeserializerFactory myDocDeserializerFactory =
192 myDocDeserializerFactory.createDocumentDeserializer(inputCD);
193 Document deviceDoc = deser.deserialize();
194
195
196 dataOut.addDocument(deviceDoc);
197 return dataOut;
198
199 } else {
200
201 // From Office format to device format
202
203 DocumentSerializerFactory myDocSerializerFactory =
205
206 Iterator<Object> e = inputCD.getDocumentEnumeration();
207
208 Document doc = (Document) e.next();
209 DocumentSerializer ser = myDocSerializerFactory.createDocumentSerializer(doc);
210 dataOut = ser.serialize();
211
212 return dataOut;
213 }
214 }
215
229 public Document getOfficeDocument(String name, InputStream is)
230 throws IOException {
232 }
233}
ConvertData is used as a container for passing Document objects in and out of the Convert class.
void addDocument(Document doc)
Adds a Document to the vector.
void reset()
Resets ConvertData.
Iterator< Object > getDocumentEnumeration()
Gets an Enumeration to access the Vector of Document objects.
This Exception is thrown by convert algorithms.
The Convert class manages a conversion from one mime-type to another.
Definition: Convert.java:38
final boolean toOffice
true if converting to the Office format, false if converting to the device format.
Definition: Convert.java:47
Convert(ConverterInfo ci, boolean toOffice)
Construct a Convert class with specified ConvertInfo registry information.
Definition: Convert.java:61
void reset()
Resets the input queue, so that the user can use this class to perform another conversion.
Definition: Convert.java:144
Object clone()
Clones a Convert object so another Convert object can do the same conversion.
Definition: Convert.java:158
void addInputStream(String name, InputStream is, boolean isZip)
Adds an InputStream to be used as input by the Convert class.
Definition: Convert.java:108
void addInputStream(String name, InputStream is)
Adds an InputStream to be used as input by the Convert class.
Definition: Convert.java:80
Document getOfficeDocument(String name, InputStream is)
Returns the appropriate "Office" Document object for this plug-in.
Definition: Convert.java:229
final ConvertData inputCD
Holds the convert input data.
Definition: Convert.java:50
DocumentMerger getDocumentMerger(Document origDoc)
Returns a DocumentMerger for the given Document.
Definition: Convert.java:131
ConvertData convert()
Convert the input specified in calls to the addInputStream method to the output format specified by t...
Definition: Convert.java:181
final ConverterInfo ci
ConvertInfo that corresponds to the from-mime/to-mime conversion.
Definition: Convert.java:41
abstract Document createOfficeDocument(String name, InputStream is)
Create a Document object that corresponds to the Office data passed in via the InputStream object.
abstract Document createDeviceDocument(String name, InputStream is)
Create a Document object that corresponds to the device data passed in via the InputStream object.
Class for storing the information about a converter plug-in.
DocumentSerializerFactory getDocSerializerFactory()
Returns an instance of the DocumentDeserializerFactory interface.
DocumentDeserializerFactory getDocDeserializerFactory()
Returns an instance of the DocumentSerializerFactory interface.
PluginFactory getPluginFactory()
Returns the PluginFactory instance for this plug-in.
DocumentMergerFactory getDocMergerFactory()
Returns an instance of the DocumentMergerFactory interface.
const char * name
A DocumentDeserializer object is used to convert from the "Device" Document format to the "Office" Do...
DocumentDeserializer createDocumentDeserializer(ConvertData cd)
The DocumentDeserializer is used to convert from the "Device" Document format to the "Office" Documen...
A DocumentDeserializer represents a converter that converts "Device" Document objects into the "Offic...
Document deserialize()
Convert the data passed into the DocumentDeserializer constructor into the "Office" Document format.
All plug-in implementations of the PluginFactory interface that also support merging must also implem...
DocumentMerger createDocumentMerger(Document doc)
Create a DocumentMerger object given a Document object.
A DocumentMerger can merge changes from a modified "Device" Document to the assigned original "Office...
A DocumentSerializer object is used to convert from the "Office" Document format to the "Device" Docu...
DocumentSerializer createDocumentSerializer(Document doc)
The DocumentSerializer is used to convert from the "Office" Document format to the "Device" Document ...
A DocumentSerializer represents a converter that converts a "Office" Document to a "Device" Document ...
ConvertData serialize()
Convert the data passed into the DocumentSerializer constructor into the "Device" Document format.
A Document represents any Document to be converted and the resulting Document from any conversion.
Definition: Document.java:36
Provides an interface for plug-in registration.
Provides general purpose utilities.
Provides interfaces for converting between two Document formats, and supports a "merge" interface for...
Definition: Convert.java:19