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 
19 package org.openoffice.xmerge;
20 
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.util.Iterator;
24 
26 
38 public 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) {
86  inputDoc = ci.getPluginFactory().createDeviceDocument(name, is);
87  } else {
88  inputDoc = ci.getPluginFactory().createOfficeDocument(name, is);
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) {
114  inputDoc = ci.getPluginFactory().createDeviceDocument(name, is);
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 =
191  DocumentDeserializer deser =
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 {
231  return ci.getPluginFactory().createOfficeDocument(name, is);
232  }
233 }
Provides general purpose utilities.
DocumentSerializer createDocumentSerializer(Document doc)
The.
DocumentSerializerFactory getDocSerializerFactory()
Returns an instance of the.
Provides an interface for plug-in registration.
DocumentMerger getDocumentMerger(Document origDoc)
Returns a.
Definition: Convert.java:131
Document deserialize()
Convert the data passed into the.
void addInputStream(String name, InputStream is, boolean isZip)
Adds an.
Definition: Convert.java:108
Document getOfficeDocument(String name, InputStream is)
Returns the appropriate "Office".
Definition: Convert.java:229
exports com.sun.star. java
ConvertData serialize()
Convert the data passed into the.
Object clone()
Clones a.
Definition: Convert.java:158
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.
DocumentMergerFactory getDocMergerFactory()
Returns an instance of the DocumentMergerFactory interface.
void reset()
Resets ConvertData.
final ConvertData inputCD
Holds the convert input data.
Definition: Convert.java:50
DocumentMerger createDocumentMerger(Document doc)
Create a.
Iterator< Object > getDocumentEnumeration()
Gets an.
DocumentDeserializerFactory getDocDeserializerFactory()
Returns an instance of the.
void reset()
Resets the input queue, so that the user can use this class to perform another conversion.
Definition: Convert.java:144
Convert(ConverterInfo ci, boolean toOffice)
Construct a Convert class with specified.
Definition: Convert.java:61
const char * name
Class for storing the information about a converter plug-in.
DocumentDeserializer createDocumentDeserializer(ConvertData cd)
The.
void addDocument(Document doc)
Adds a.
Provides interfaces for converting between two.
Definition: Convert.java:19
void addInputStream(String name, InputStream is)
Adds an.
Definition: Convert.java:80
ConvertData convert()
Convert the input specified in calls to the.
Definition: Convert.java:181
abstract Document createDeviceDocument(String name, InputStream is)
Create a.