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;
25 
26 import java.io.IOException;
27 
28 import org.w3c.dom.Document;
29 import org.w3c.dom.DOMException;
30 
31 
32 public abstract class EmbeddedObject {
33     protected String objName;
34     protected String objType;
35 
36     /** Representation of the file from which this object was read. */
37     protected OfficeZip zipFile = null;
38 
39     /** Flag indicating if this document has changed since reading or is new. */
40     protected boolean hasChanged = false;
41 
42     /**
43      * Constructor for an embedded object stored using an XML representation.
44      *
45      * @param   name    The name of the object.
46      * @param   type    The mime-type of the object.  See the class summary.
47      */
EmbeddedObject(String name, String type)48     public EmbeddedObject(String name, String type) {
49         objName = name;
50         objType = type;
51 
52         hasChanged = true;
53     }
54 
55 
56     /**
57      * Package private constructor for use when reading an object from a
58      * compressed SX? file.
59      *
60      * @param   name    The name of the object.
61      * @param   type    The mime-type of the object.  See the class summary.
62      * @param   source  The OfficeZip representation of the SX? file that stores
63      *                  the object.
64      */
EmbeddedObject(String name, String type, OfficeZip source)65     EmbeddedObject(String name, String type, OfficeZip source) {
66         this(name, type);
67         zipFile = source;
68     }
69 
70 
71     /**
72      * Retrieves the name of the embedded object represented by an instance of
73      * this class.
74      *
75      * <b>N.B.</b>The name referes to the name as found in the
76      * <code>META-INF/manifest.xml</code> file.
77      *
78      * @return  The name of the object.
79      */
getName()80     public final String getName() {
81         return objName;
82     }
83 
84 
85     /**
86      * Retrieves the type of the embedded object represented by an instance of
87      * this class.
88      *
89      * The <code>META-INF/manifest.xml</code> file currently represents the
90      * type of an object using MIME types.
91      */
getType()92     public final String getType() {
93         return objType;
94     }
95 
96     /**
97      * Package private method for writing the data of the EmbeddedObject to a
98      * SX? file.
99      *
100      * @param   zip     An <code>OfficeZip</code> instance representing the file
101      *                  the data is to be written to.
102      */
write(OfficeZip zip)103     abstract void write(OfficeZip zip) throws IOException;
104 
105     /**
106      * Package private method that constructs the manifest.xml entries for this
107      * embedded object.
108      */
writeManifestData(Document manifestDoc)109     abstract void writeManifestData(Document manifestDoc) throws DOMException;
110 }
111