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