Initial import
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@5 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
75e32b1e8f
commit
b0b66fcae9
252 changed files with 49000 additions and 0 deletions
165
source/java/writer2latex/xmerge/BinaryGraphicsDocument.java
Normal file
165
source/java/writer2latex/xmerge/BinaryGraphicsDocument.java
Normal file
|
@ -0,0 +1,165 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* BinaryGraphicsDocument.java
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2008 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.0 (2008-11-23)
|
||||
*
|
||||
*/
|
||||
|
||||
package writer2latex.xmerge;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.InputStream;
|
||||
//import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import writer2latex.util.Misc;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Class representing a binary graphics document.
|
||||
* This class is used for representing graphics documents that are <i>not</i>
|
||||
* interpreted in any way, but simply copied verbatim from the source format
|
||||
* to the target format.</p>
|
||||
*
|
||||
* <p><code>GraphicsDocument</code> is used to create new graphics documents.</p>
|
||||
*
|
||||
*/
|
||||
public class BinaryGraphicsDocument implements Document {
|
||||
|
||||
//private final static int BUFFERSIZE = 1024;
|
||||
|
||||
private String docName;
|
||||
|
||||
private byte[] data;
|
||||
private int nOff;
|
||||
private int nLen;
|
||||
|
||||
private String sFileExtension;
|
||||
private String sMimeType;
|
||||
|
||||
/**
|
||||
* <p>Constructs a new graphics document.</p>
|
||||
*
|
||||
* <p>This new document does not contain any information. Document data must
|
||||
* either be added using appropriate methods, or an existing file can be
|
||||
* {@link #read(InputStream) read} from an <code>InputStream</code>.</p>
|
||||
*
|
||||
* @param name The name of the <code>GraphicsDocument</code>.
|
||||
*/
|
||||
public BinaryGraphicsDocument(String name, String sFileExtension, String sMimeType) {
|
||||
this.sFileExtension = sFileExtension;
|
||||
this.sMimeType = sMimeType;
|
||||
docName = trimDocumentName(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>This method reads <code>byte</code> data from the InputStream.</p>
|
||||
*
|
||||
* @param is InputStream containing a binary data file.
|
||||
*
|
||||
* @throws IOException In case of any I/O errors.
|
||||
*/
|
||||
public void read(InputStream is) throws IOException {
|
||||
data = Misc.inputStreamToByteArray(is);
|
||||
}
|
||||
|
||||
public void read(byte[] data) {
|
||||
read(data,0,data.length);
|
||||
}
|
||||
|
||||
public void read(byte[] data, int nOff, int nLen) {
|
||||
this.data = data;
|
||||
this.nOff = nOff;
|
||||
this.nLen = nLen;
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility method to make sure the document name is stripped of any file
|
||||
* extensions before use.
|
||||
*/
|
||||
private String trimDocumentName(String name) {
|
||||
String temp = name.toLowerCase();
|
||||
|
||||
if (temp.endsWith(getFileExtension())) {
|
||||
// strip the extension
|
||||
int nlen = name.length();
|
||||
int endIndex = nlen - getFileExtension().length();
|
||||
name = name.substring(0,endIndex);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns the <code>Document</code> name with no file extension.</p>
|
||||
*
|
||||
* @return The <code>Document</code> name with no file extension.
|
||||
*/
|
||||
public String getName() {
|
||||
return docName;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns the <code>Document</code> name with file extension.</p>
|
||||
*
|
||||
* @return The <code>Document</code> name with file extension.
|
||||
*/
|
||||
public String getFileName() {
|
||||
return new String(docName + getFileExtension());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Writes out the <code>Document</code> content to the specified
|
||||
* <code>OutputStream</code>.</p>
|
||||
*
|
||||
* <p>This method may not be thread-safe.
|
||||
* Implementations may or may not synchronize this
|
||||
* method. User code (i.e. caller) must make sure that
|
||||
* calls to this method are thread-safe.</p>
|
||||
*
|
||||
* @param os <code>OutputStream</code> to write out the
|
||||
* <code>Document</code> content.
|
||||
*
|
||||
* @throws IOException If any I/O error occurs.
|
||||
*/
|
||||
public void write(OutputStream os) throws IOException {
|
||||
os.write(data, nOff, nLen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file extension for this type of
|
||||
* <code>Document</code>.
|
||||
*
|
||||
* @return The file extension of <code>Document</code>.
|
||||
*/
|
||||
public String getFileExtension(){ return sFileExtension; }
|
||||
|
||||
/**
|
||||
* Method to return the MIME type of the document.
|
||||
*
|
||||
* @return String The document's MIME type.
|
||||
*/
|
||||
public String getDocumentMIMEType(){ return sMimeType; }
|
||||
|
||||
}
|
179
source/java/writer2latex/xmerge/ConvertData.java
Normal file
179
source/java/writer2latex/xmerge/ConvertData.java
Normal file
|
@ -0,0 +1,179 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
// This version is adapted for Writer2LaTeX
|
||||
// Change: The first document added will become the "master document" 2006/10/05
|
||||
// Version 1.0 (2008-11-24)
|
||||
|
||||
package writer2latex.xmerge;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
import java.util.Iterator;
|
||||
|
||||
import writer2latex.api.ConverterResult;
|
||||
import writer2latex.api.OutputFile;
|
||||
|
||||
/**
|
||||
* <p><code>ConvertData</code> is used as a container for passing
|
||||
* <code>OutputFile</code> objects in and out of the <code>Convert</code>
|
||||
* class. The <code>ConvertData</code> contains a <code>String</code>
|
||||
* name and a <code>Vector</code> of <code>OutputFile</code> objects.</p>
|
||||
*
|
||||
* @author Martin Maher
|
||||
*/
|
||||
public class ConvertData implements ConverterResult {
|
||||
|
||||
/**
|
||||
* Vector of <code>OutputFile</code> objects.
|
||||
*/
|
||||
private Vector v = new Vector();
|
||||
|
||||
/** Master doc */
|
||||
private OutputFile masterDoc = null;
|
||||
|
||||
/**
|
||||
* Name of the <code>ConvertData</code> object.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
|
||||
/**
|
||||
* Resets ConvertData. This empties all <code>OutputFile</code>
|
||||
* objects from this class. This allows reuse of a
|
||||
* <code>ConvertData</code>.
|
||||
*/
|
||||
public void reset() {
|
||||
name = null;
|
||||
v.removeAllElements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>OutputFile</code> name.
|
||||
*
|
||||
* @return The <code>OutputFile</code> name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the <code>OutputFile</code> name.
|
||||
*
|
||||
* @param docName The name of the <code>OutputFile</code>.
|
||||
*/
|
||||
public void setName(String docName) {
|
||||
name = docName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a <code>OutputFile</code> to the vector.
|
||||
*
|
||||
* @param doc The <code>OutputFile</code> to add.
|
||||
*/
|
||||
public void addDocument(OutputFile doc) {
|
||||
if (v.size()==0) { masterDoc = doc; }
|
||||
v.add(doc);
|
||||
}
|
||||
|
||||
/** Get the master document
|
||||
* @return <code>OutputFile</code> the master document
|
||||
*/
|
||||
public OutputFile getMasterDocument() {
|
||||
return masterDoc;
|
||||
}
|
||||
|
||||
/** Check if a given document is the master document
|
||||
* @param doc The <code>OutputFile</code> to check
|
||||
* @return true if this is the master document
|
||||
*/
|
||||
public boolean isMasterDocument(OutputFile doc) {
|
||||
return doc == masterDoc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets an <code>Iterator</code> to access the <code>Vector</code>
|
||||
* of <code>OutputFile</code> objects
|
||||
*
|
||||
* @return The <code>Iterator</code> to access the
|
||||
* <code>Vector</code> of <code>OutputFile</code> objects.
|
||||
*/
|
||||
public Iterator iterator() {
|
||||
return v.iterator();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of <code>OutputFile</code> objects currently stored
|
||||
*
|
||||
* @return The number of <code>OutputFile</code> objects currently
|
||||
* stored.
|
||||
*/
|
||||
public int getNumDocuments() {
|
||||
return (v.size());
|
||||
}
|
||||
|
||||
public void write(File dir) throws IOException {
|
||||
if (dir!=null && !dir.exists()) throw new IOException("Directory does not exist");
|
||||
Iterator docEnum = iterator();
|
||||
while (docEnum.hasNext()) {
|
||||
OutputFile docOut = (OutputFile) docEnum.next();
|
||||
String sDirName = "";
|
||||
String sFileName = docOut.getFileName();
|
||||
File subdir = dir;
|
||||
int nSlash = sFileName.indexOf("/");
|
||||
if (nSlash>-1) {
|
||||
sDirName = sFileName.substring(0,nSlash);
|
||||
sFileName = sFileName.substring(nSlash+1);
|
||||
subdir = new File(dir,sDirName);
|
||||
if (!subdir.exists()) { subdir.mkdir(); }
|
||||
}
|
||||
File outfile = new File (subdir,sFileName);
|
||||
FileOutputStream fos = new FileOutputStream(outfile);
|
||||
docOut.write(fos);
|
||||
fos.flush();
|
||||
fos.close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
400
source/java/writer2latex/xmerge/DOMDocument.java
Normal file
400
source/java/writer2latex/xmerge/DOMDocument.java
Normal file
|
@ -0,0 +1,400 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
// This version is adapted for writer2latex
|
||||
// Version 1.0 (2008-11-23)
|
||||
|
||||
package writer2latex.xmerge;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
//import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
//import java.io.ByteArrayInputStream;
|
||||
//import java.io.IOException;
|
||||
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
//import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* An implementation of <code>Document</code> for
|
||||
* StarOffice documents.
|
||||
*/
|
||||
public class DOMDocument
|
||||
implements writer2latex.xmerge.Document {
|
||||
|
||||
/** Factory for <code>DocumentBuilder</code> objects. */
|
||||
private static DocumentBuilderFactory factory =
|
||||
DocumentBuilderFactory.newInstance();
|
||||
|
||||
/** DOM <code>Document</code> of content.xml. */
|
||||
private Document contentDoc = null;
|
||||
|
||||
/** DOM <code>Document</code> of styles.xml. */
|
||||
//private Document styleDoc = null;
|
||||
|
||||
private String documentName = null;
|
||||
private String fileName = null;
|
||||
private String fileExt = null;
|
||||
|
||||
/** Resources object. */
|
||||
//private Resources res = null;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*
|
||||
* @param name <code>Document</code> name.
|
||||
* @param ext <code>Document</code> extension.
|
||||
*/
|
||||
public DOMDocument(String name,String ext)
|
||||
{
|
||||
this(name,ext,true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file extension of the <code>Document</code>
|
||||
* represented.
|
||||
*
|
||||
* @return file extension of the <code>Document</code>.
|
||||
*/
|
||||
protected String getFileExtension() {
|
||||
return fileExt;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor with arguments to set <code>namespaceAware</code>
|
||||
* and <code>validating</code> flags.
|
||||
*
|
||||
* @param name <code>Document</code> name (may or may not
|
||||
* contain extension).
|
||||
* @param ext <code>Document</code> extension.
|
||||
* @param namespaceAware Value for <code>namespaceAware</code> flag.
|
||||
* @param validating Value for <code>validating</code> flag.
|
||||
*/
|
||||
public DOMDocument(String name, String ext,boolean namespaceAware, boolean validating) {
|
||||
|
||||
//res = Resources.getInstance();
|
||||
factory.setValidating(validating);
|
||||
factory.setNamespaceAware(namespaceAware);
|
||||
this.fileExt = ext;
|
||||
this.documentName = trimDocumentName(name);
|
||||
this.fileName = documentName + getFileExtension();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the file extension from the <code>Document</code>
|
||||
* name.
|
||||
*
|
||||
* @param name Full <code>Document</code> name with extension.
|
||||
*
|
||||
* @return Name of <code>Document</code> without the extension.
|
||||
*/
|
||||
private String trimDocumentName(String name) {
|
||||
String temp = name.toLowerCase();
|
||||
String ext = getFileExtension();
|
||||
|
||||
if (temp.endsWith(ext)) {
|
||||
// strip the extension
|
||||
int nlen = name.length();
|
||||
int endIndex = nlen - ext.length();
|
||||
name = name.substring(0,endIndex);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a DOM <code>Document</code> object of the document content
|
||||
* file. Note that a content DOM is not created when the constructor
|
||||
* is called. So, either the <code>read</code> method or the
|
||||
* <code>initContentDOM</code> method will need to be called ahead
|
||||
* on this object before calling this method.
|
||||
*
|
||||
* @return DOM <code>Document</code> object.
|
||||
*/
|
||||
public Document getContentDOM() {
|
||||
|
||||
return contentDoc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Content of the <code>Document</code> to the contents of the
|
||||
* supplied <code>Node</code> list.
|
||||
*
|
||||
* @param newDom DOM <code>Document</code> object.
|
||||
*/
|
||||
public void setContentDOM( Node newDom) {
|
||||
contentDoc=(Document)newDom;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of the <code>Document</code>.
|
||||
*
|
||||
* @return The name of <code>Document</code>.
|
||||
*/
|
||||
public String getName() {
|
||||
|
||||
return documentName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the file name of the <code>Document</code>, possibly
|
||||
* with the standard extension.
|
||||
*
|
||||
* @return The file name of <code>Document</code>.
|
||||
*/
|
||||
public String getFileName() {
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read the Office <code>Document</code> from the specified
|
||||
* <code>InputStream</code>.
|
||||
*
|
||||
* @param is Office document <code>InputStream</code>.
|
||||
*
|
||||
* @throws IOException If any I/O error occurs.
|
||||
*/
|
||||
public void read(InputStream is) throws IOException {
|
||||
DocumentBuilder builder = null;
|
||||
try {
|
||||
builder = factory.newDocumentBuilder();
|
||||
} catch (ParserConfigurationException ex) {
|
||||
throw new IOException(ex.getMessage());
|
||||
}
|
||||
try {
|
||||
contentDoc= builder.parse(is);
|
||||
} catch (SAXException ex) {
|
||||
throw new IOException(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write out content to the supplied <code>OutputStream</code>.
|
||||
*
|
||||
* @param os XML <code>OutputStream</code>.
|
||||
*
|
||||
* @throws IOException If any I/O error occurs.
|
||||
*/
|
||||
public void write(OutputStream os) throws IOException {
|
||||
|
||||
// set bytes for writing to output stream
|
||||
byte contentBytes[] = docToBytes(contentDoc);
|
||||
|
||||
os.write(contentBytes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Write out a <code>org.w3c.dom.Document</code> object into a
|
||||
* <code>byte</code> array.</p>
|
||||
*
|
||||
* <p>TODO: remove dependency on com.sun.xml.tree.XmlDocument
|
||||
* package!</p>
|
||||
*
|
||||
* @param Document DOM <code>Document</code> object.
|
||||
*
|
||||
* @return <code>byte</code> array of DOM <code>Document</code>
|
||||
* object.
|
||||
*
|
||||
* @throws IOException If any I/O error occurs.
|
||||
*/
|
||||
private byte[] docToBytes(Document doc)
|
||||
throws IOException {
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
java.lang.reflect.Constructor con;
|
||||
java.lang.reflect.Method meth;
|
||||
|
||||
String domImpl = doc.getClass().getName();
|
||||
|
||||
/*
|
||||
* We may have multiple XML parsers in the Classpath.
|
||||
* Depending on which one is first, the actual type of
|
||||
* doc may vary. Need a way to find out which API is being
|
||||
* used and use an appropriate serialization method.
|
||||
*/
|
||||
try {
|
||||
// First of all try for JAXP 1.0
|
||||
if (domImpl.equals("com.sun.xml.tree.XmlDocument")) {
|
||||
Class jaxpDoc = Class.forName("com.sun.xml.tree.XmlDocument");
|
||||
|
||||
// The method is in the XMLDocument class itself, not a helper
|
||||
meth = jaxpDoc.getMethod("write",
|
||||
new Class[] { Class.forName("java.io.OutputStream") } );
|
||||
|
||||
meth.invoke(doc, new Object [] { baos } );
|
||||
}
|
||||
else if (domImpl.equals("org.apache.crimson.tree.XmlDocument"))
|
||||
{
|
||||
Class crimsonDoc = Class.forName("org.apache.crimson.tree.XmlDocument");
|
||||
// The method is in the XMLDocument class itself, not a helper
|
||||
meth = crimsonDoc.getMethod("write",
|
||||
new Class[] { Class.forName("java.io.OutputStream") } );
|
||||
|
||||
meth.invoke(doc, new Object [] { baos } );
|
||||
}
|
||||
else if (domImpl.equals("org.apache.xerces.dom.DocumentImpl")
|
||||
|| domImpl.equals("org.apache.xerces.dom.DeferredDocumentImpl")) {
|
||||
// Try for Xerces
|
||||
Class xercesSer =
|
||||
Class.forName("org.apache.xml.serialize.XMLSerializer");
|
||||
|
||||
// Get the OutputStream constructor
|
||||
// May want to use the OutputFormat parameter at some stage too
|
||||
con = xercesSer.getConstructor(new Class []
|
||||
{ Class.forName("java.io.OutputStream"),
|
||||
Class.forName("org.apache.xml.serialize.OutputFormat") } );
|
||||
|
||||
|
||||
// Get the serialize method
|
||||
meth = xercesSer.getMethod("serialize",
|
||||
new Class [] { Class.forName("org.w3c.dom.Document") } );
|
||||
|
||||
|
||||
// Get an instance
|
||||
Object serializer = con.newInstance(new Object [] { baos, null } );
|
||||
|
||||
|
||||
// Now call serialize to write the document
|
||||
meth.invoke(serializer, new Object [] { doc } );
|
||||
}
|
||||
else if (domImpl.equals("gnu.xml.dom.DomDocument")) {
|
||||
|
||||
Class gnuSer = Class.forName("gnu.xml.dom.ls.DomLSSerializer");
|
||||
|
||||
// Get the serialize method
|
||||
meth = gnuSer.getMethod("serialize",
|
||||
new Class [] { Class.forName("org.w3c.dom.Node"),
|
||||
Class.forName("java.io.OutputStream") } );
|
||||
|
||||
// Get an instance
|
||||
Object serializer = gnuSer.newInstance();
|
||||
|
||||
// Now call serialize to write the document
|
||||
meth.invoke(serializer, new Object [] { doc, baos } );
|
||||
}
|
||||
else {
|
||||
// We dont have another parser
|
||||
throw new IOException("No appropriate API (JAXP/Xerces) to serialize XML document: " + domImpl);
|
||||
}
|
||||
}
|
||||
catch (ClassNotFoundException cnfe) {
|
||||
throw new IOException(cnfe.toString());
|
||||
}
|
||||
catch (Exception e) {
|
||||
// We may get some other errors, but the bottom line is that
|
||||
// the steps being executed no longer work
|
||||
throw new IOException(e.toString());
|
||||
}
|
||||
|
||||
byte bytes[] = baos.toByteArray();
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes a new DOM <code>Document</code> with the content
|
||||
* containing minimum XML tags.
|
||||
*
|
||||
* @throws IOException If any I/O error occurs.
|
||||
*/
|
||||
public final void initContentDOM() throws IOException {
|
||||
contentDoc = createDOM("");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Creates a new DOM <code>Document</code> containing minimum
|
||||
* OpenOffice XML tags.</p>
|
||||
*
|
||||
* <p>This method uses the subclass
|
||||
* <code>getOfficeClassAttribute</code> method to get the
|
||||
* attribute for <i>office:class</i>.</p>
|
||||
*
|
||||
* @param rootName root name of <code>Document</code>.
|
||||
*
|
||||
* @throws IOException If any I/O error occurs.
|
||||
*/
|
||||
private final Document createDOM(String rootName) throws IOException {
|
||||
|
||||
Document doc = null;
|
||||
|
||||
try {
|
||||
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
doc = builder.newDocument();
|
||||
|
||||
} catch (ParserConfigurationException ex) {
|
||||
System.err.println("Error:"+ ex);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Element root = (Element) doc.createElement(rootName);
|
||||
doc.appendChild(root);
|
||||
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
86
source/java/writer2latex/xmerge/Document.java
Normal file
86
source/java/writer2latex/xmerge/Document.java
Normal file
|
@ -0,0 +1,86 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
* This version is adapted for Writer2LaTeX
|
||||
* version 1.0 (2008-11-22)
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
package writer2latex.xmerge;
|
||||
|
||||
//import java.io.OutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import writer2latex.api.OutputFile;
|
||||
|
||||
/**
|
||||
* <p>A <code>Document</code> represents any <code>Document</code>
|
||||
* to be converted and the resulting <code>Document</code> from any
|
||||
* conversion.</p>
|
||||
*
|
||||
*
|
||||
* @author Herbie Ong
|
||||
*/
|
||||
public interface Document extends OutputFile {
|
||||
|
||||
|
||||
/**
|
||||
* <p>Reads the content from the <code>InputStream</code> into
|
||||
* the <code>Document</code>.</p>
|
||||
*
|
||||
* <p>This method may not be thread-safe.
|
||||
* Implementations may or may not synchronize this
|
||||
* method. User code (i.e. caller) must make sure that
|
||||
* calls to this method are thread-safe.</p>
|
||||
*
|
||||
* @param is <code>InputStream</code> to read in the
|
||||
* <code>Document</code> content.
|
||||
*
|
||||
* @throws IOException If any I/O error occurs.
|
||||
*/
|
||||
public void read(InputStream is) throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the <code>Document</code> name with no file extension.
|
||||
*
|
||||
* @return The <code>Document</code> name with no file extension.
|
||||
*/
|
||||
public String getName();
|
||||
|
||||
|
||||
}
|
||||
|
143
source/java/writer2latex/xmerge/EmbeddedBinaryObject.java
Normal file
143
source/java/writer2latex/xmerge/EmbeddedBinaryObject.java
Normal file
|
@ -0,0 +1,143 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
* either of the following licenses
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
// This version is adapted for Writer2LaTeX
|
||||
// Version 1.0 (2008-11-22)
|
||||
|
||||
package writer2latex.xmerge;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Element;
|
||||
//import org.w3c.dom.Node;
|
||||
|
||||
|
||||
/**
|
||||
* This class represents embedded object's in an OpenOffice.org document that
|
||||
* have a binary representation.
|
||||
*/
|
||||
public class EmbeddedBinaryObject extends EmbeddedObject {
|
||||
|
||||
/** The object's binary representation. */
|
||||
protected byte[] objData = null;
|
||||
|
||||
/**
|
||||
* Constructor for an embedded object stored using an XML representation.
|
||||
*
|
||||
* @param name The name of the object.
|
||||
* @param type The mime-type of the object. See the class summary.
|
||||
*/
|
||||
public EmbeddedBinaryObject(String name, String type) {
|
||||
super(name, type);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Package private constructor for use when reading an object from a
|
||||
* compressed SX? file.
|
||||
*
|
||||
* @param name The name of the object.
|
||||
* @param type The mime-type of the object. See the class summary.
|
||||
* @param source The OfficeZip representation of the SX? file that stores
|
||||
* the object.
|
||||
*/
|
||||
EmbeddedBinaryObject(String name, String type, OfficeZip source) {
|
||||
super(name, type, source);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns the data for this object.
|
||||
*
|
||||
* @return A <code>byte</code> array containing the object's data.
|
||||
*/
|
||||
public byte[] getBinaryData() {
|
||||
|
||||
if (objData == null) {
|
||||
// See if we came from a Zip file
|
||||
if (zipFile != null) {
|
||||
objData = zipFile.getNamedBytes(objName);
|
||||
}
|
||||
}
|
||||
|
||||
return objData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the data for this object.
|
||||
*
|
||||
* @param data A <code>byte</code> array containing data for the object.
|
||||
*/
|
||||
public void setBinaryData(byte[] data) {
|
||||
objData = data;
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Package private method for writing the data of the EmbeddedObject to a
|
||||
* SX? file.
|
||||
*
|
||||
* @param zip An <code>OfficeZip</code> instance representing the file
|
||||
* the data is to be written to.
|
||||
*/
|
||||
void write(OfficeZip zip) {
|
||||
if (hasChanged) {
|
||||
zip.setNamedBytes(objName, objData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Package private method that constructs the manifest.xml entries for this
|
||||
* embedded object.
|
||||
*
|
||||
* @return Document <code>Document</code> containing the manifest entries.
|
||||
*/
|
||||
void writeManifestData(Document manifestDoc) throws DOMException {
|
||||
Element objNode = manifestDoc.createElement(OfficeConstants.TAG_MANIFEST_FILE);
|
||||
|
||||
objNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_TYPE, objType);
|
||||
objNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_PATH, objName);
|
||||
|
||||
manifestDoc.getDocumentElement().appendChild(objNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
129
source/java/writer2latex/xmerge/EmbeddedObject.java
Normal file
129
source/java/writer2latex/xmerge/EmbeddedObject.java
Normal file
|
@ -0,0 +1,129 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
// This version is adapted for Writer2LaTeX
|
||||
|
||||
package writer2latex.xmerge;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.DOMException;
|
||||
|
||||
|
||||
public abstract class EmbeddedObject {
|
||||
protected String objName;
|
||||
protected String objType;
|
||||
|
||||
/** Representation of the file from which this object was read. */
|
||||
protected OfficeZip zipFile = null;
|
||||
|
||||
/** Flag indicating if this document has changed since reading or is new. */
|
||||
protected boolean hasChanged = false;
|
||||
|
||||
/**
|
||||
* Constructor for an embedded object stored using an XML representation.
|
||||
*
|
||||
* @param name The name of the object.
|
||||
* @param type The mime-type of the object. See the class summary.
|
||||
*/
|
||||
public EmbeddedObject(String name, String type) {
|
||||
objName = name;
|
||||
objType = type;
|
||||
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Package private constructor for use when reading an object from a
|
||||
* compressed SX? file.
|
||||
*
|
||||
* @param name The name of the object.
|
||||
* @param type The mime-type of the object. See the class summary.
|
||||
* @param source The OfficeZip representation of the SX? file that stores
|
||||
* the object.
|
||||
*/
|
||||
EmbeddedObject(String name, String type, OfficeZip source) {
|
||||
this(name, type);
|
||||
zipFile = source;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the name of the embedded object represented by an instance of
|
||||
* this class.
|
||||
*
|
||||
* <b>N.B.</b>The name referes to the name as found in the
|
||||
* <code>META-INF/manifest.xml</code> file.
|
||||
*
|
||||
* @return The name of the object.
|
||||
*/
|
||||
public final String getName() {
|
||||
return objName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the type of the embedded object represented by an instance of
|
||||
* this class.
|
||||
*
|
||||
* The <code>META-INF/manifest.xml</code> file currently represents the
|
||||
* type of an object using MIME types.
|
||||
*/
|
||||
public final String getType() {
|
||||
return objType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Package private method for writing the data of the EmbeddedObject to a
|
||||
* SX? file.
|
||||
*
|
||||
* @param zip An <code>OfficeZip</code> instance representing the file
|
||||
* the data is to be written to.
|
||||
*/
|
||||
abstract void write(OfficeZip zip) throws IOException;
|
||||
|
||||
/**
|
||||
* Package private method that constructs the manifest.xml entries for this
|
||||
* embedded object.
|
||||
*
|
||||
* @return Document <code>Document</code> containing the manifest entries.
|
||||
*/
|
||||
abstract void writeManifestData(Document manifestDoc) throws DOMException;
|
||||
}
|
312
source/java/writer2latex/xmerge/EmbeddedXMLObject.java
Normal file
312
source/java/writer2latex/xmerge/EmbeddedXMLObject.java
Normal file
|
@ -0,0 +1,312 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
// This version is adapted for Writer2LaTeX
|
||||
// Version 1.0 (2008-11-23)
|
||||
|
||||
package writer2latex.xmerge;
|
||||
|
||||
//import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
//import org.xml.sax.EntityResolver;
|
||||
//import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* This class represents those embedded objects in an OpenOffice.org document
|
||||
* that have an XML representation. Currently, according to the OpenOffice.org
|
||||
* File Format 1.0 document, there are 6 such objects:
|
||||
*
|
||||
* Formulae created with Math (application/vnd.sun.xml.math)
|
||||
* Charts created with Chart (application/vnd.sun.xml.chart)
|
||||
* Spreadsheets created with Calc (application/vnd.sun.xml.calc)
|
||||
* Text created with Writer (application/vnd.sun.xml.writer)
|
||||
* Drawings created with Draw (application/vnd.sun.xml.draw)
|
||||
* Presentations created with Impress (application/vnd.sun.xml.impress)
|
||||
*
|
||||
* These object types are stored using a combination of content, settings and styles
|
||||
* XML files.
|
||||
*/
|
||||
public class EmbeddedXMLObject extends EmbeddedObject {
|
||||
|
||||
// Entries for the subdocuments that constitute this object;
|
||||
protected Document contentDOM = null;
|
||||
protected Document settingsDOM = null;
|
||||
protected Document stylesDOM = null;
|
||||
|
||||
private DocumentBuilder builder = null;
|
||||
|
||||
/**
|
||||
* Constructor for an embedded object stored using an XML representation.
|
||||
*
|
||||
* @param name The name of the object.
|
||||
* @param type The mime-type of the object. See the class summary.
|
||||
*/
|
||||
public EmbeddedXMLObject(String name, String type) {
|
||||
super(name, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Package private constructor for use when reading an object from a
|
||||
* compressed SX? file.
|
||||
*
|
||||
* @param name The name of the object.
|
||||
* @param type The mime-type of the object. See the class summary.
|
||||
* @param source The OfficeZip representation of the SX? file that stores
|
||||
* the object.
|
||||
*/
|
||||
EmbeddedXMLObject(String name, String type, OfficeZip source) {
|
||||
super(name, type, source);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the content data for this embedded object.
|
||||
*
|
||||
* @return DOM represenation of "content.xml"
|
||||
*
|
||||
* @throws SAXException If any parser error occurs
|
||||
* @throws IOException If any IO error occurs
|
||||
*/
|
||||
public Document getContentDOM() throws SAXException, IOException {
|
||||
|
||||
if (contentDOM == null) {
|
||||
contentDOM = getNamedDOM("content.xml");
|
||||
}
|
||||
|
||||
return contentDOM;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the content data for the embedded object.
|
||||
*
|
||||
* @param content DOM representation of the object's content.
|
||||
*/
|
||||
public void setContentDOM(Document content) {
|
||||
contentDOM = content;
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the settings data for this embedded object.
|
||||
*
|
||||
* @return DOM represenation of "settings.xml"
|
||||
*
|
||||
* @throws SAXException If any parser error occurs
|
||||
* @throws IOException If any IO error occurs
|
||||
*/
|
||||
public Document getSettingsDOM() throws SAXException, IOException {
|
||||
|
||||
if (settingsDOM == null) {
|
||||
settingsDOM = getNamedDOM("settings.xml");
|
||||
}
|
||||
|
||||
return settingsDOM;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the settings data for the embedded object.
|
||||
*
|
||||
* @param settings DOM representation of the object's settings.
|
||||
*/
|
||||
public void setSettingsDOM(Document settings) {
|
||||
settingsDOM = settings;
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the style data for this embedded object.
|
||||
*
|
||||
* @return DOM represenation of "styles.xml"
|
||||
*
|
||||
* @throws SAXException If any parser error occurs
|
||||
* @throws IOException If any IO error occurs
|
||||
*/
|
||||
public Document getStylesDOM() throws SAXException, IOException {
|
||||
|
||||
if (stylesDOM == null) {
|
||||
stylesDOM = getNamedDOM("styles.xml");
|
||||
}
|
||||
|
||||
return stylesDOM;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the styles data for the embedded object.
|
||||
*
|
||||
* @param styles DOM representation of the object's styles.
|
||||
*/
|
||||
public void setStylesDOM(Document styles) {
|
||||
stylesDOM = styles;
|
||||
hasChanged = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method extracts the data for the given XML file from the SX? file
|
||||
* and creates a DOM representation of it.
|
||||
*
|
||||
* @param name The name of the XML file to retrieve. It is paired with
|
||||
* the object name to access the SX? file.
|
||||
*
|
||||
* @return DOM representation of the named XML file.
|
||||
*
|
||||
* @throws SAXException If any parser error occurs
|
||||
* @throws IOException If any IO error occurs
|
||||
*/
|
||||
private Document getNamedDOM(String name) throws SAXException, IOException {
|
||||
if (zipFile == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
if (builder == null) {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
factory.setValidating(false);
|
||||
builder = factory.newDocumentBuilder();
|
||||
}
|
||||
|
||||
byte[] data = zipFile.getNamedBytes(new String(objName + "/" + name));
|
||||
if (data != null) {
|
||||
return OfficeDocument.parse(builder, data);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (SAXException se) {
|
||||
throw se;
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
throw ioe;
|
||||
}
|
||||
catch (ParserConfigurationException pce) {
|
||||
throw new SAXException(pce);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Package private method for writing the data of the EmbeddedObject to a
|
||||
* SX? file.
|
||||
*
|
||||
* @param zip An <code>OfficeZip</code> instance representing the file
|
||||
* the data is to be written to.
|
||||
*/
|
||||
void write(OfficeZip zip) throws IOException {
|
||||
if (hasChanged == true) {
|
||||
if (contentDOM != null) {
|
||||
zip.setNamedBytes(new String(objName + "/content.xml"),
|
||||
OfficeDocument.docToBytes(contentDOM));
|
||||
}
|
||||
if (settingsDOM != null) {
|
||||
zip.setNamedBytes(new String(objName + "/settings.xml"),
|
||||
OfficeDocument.docToBytes(settingsDOM));
|
||||
}
|
||||
if (stylesDOM != null) {
|
||||
zip.setNamedBytes(new String(objName + "/styles.xml"),
|
||||
OfficeDocument.docToBytes(stylesDOM));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Package private method that constructs the manifest.xml entries for this
|
||||
* embedded object.
|
||||
*
|
||||
* @param manifestDoc <code>Document</code> containing the manifest entries.
|
||||
*/
|
||||
void writeManifestData(Document manifestDoc) throws DOMException {
|
||||
Node root = manifestDoc.getDocumentElement();
|
||||
|
||||
if (contentDOM != null) {
|
||||
Element contentNode = manifestDoc.createElement(OfficeConstants.TAG_MANIFEST_FILE);
|
||||
|
||||
contentNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_TYPE, "text/xml");
|
||||
contentNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_PATH,
|
||||
new String(objName + "/content.xml"));
|
||||
|
||||
root.appendChild(contentNode);
|
||||
}
|
||||
|
||||
if (settingsDOM != null) {
|
||||
Element settingsNode = manifestDoc.createElement(OfficeConstants.TAG_MANIFEST_FILE);
|
||||
|
||||
settingsNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_TYPE, "text/xml");
|
||||
settingsNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_PATH,
|
||||
new String(objName + "/settings.xml"));
|
||||
|
||||
root.appendChild(settingsNode);
|
||||
}
|
||||
|
||||
if (stylesDOM != null) {
|
||||
Element stylesNode = manifestDoc.createElement(OfficeConstants.TAG_MANIFEST_FILE);
|
||||
|
||||
stylesNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_TYPE, "text/xml");
|
||||
stylesNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_PATH,
|
||||
new String(objName + "/styles.xml"));
|
||||
}
|
||||
|
||||
|
||||
Element objectNode = manifestDoc.createElement(OfficeConstants.TAG_MANIFEST_FILE);
|
||||
|
||||
objectNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_TYPE, objType);
|
||||
objectNode.setAttribute(OfficeConstants.ATTRIBUTE_MANIFEST_FILE_PATH,
|
||||
new String(objName + "/"));
|
||||
|
||||
root.appendChild(objectNode);
|
||||
}
|
||||
|
||||
}
|
160
source/java/writer2latex/xmerge/NewDOMDocument.java
Normal file
160
source/java/writer2latex/xmerge/NewDOMDocument.java
Normal file
|
@ -0,0 +1,160 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* NewDOMDocument.java
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2006 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 0.5 (2006-10-01)
|
||||
*
|
||||
*/
|
||||
|
||||
package writer2latex.xmerge;
|
||||
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
|
||||
import writer2latex.xmerge.DOMDocument;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An extension of <code>DOMDocument</code>
|
||||
* that overrides the write method.
|
||||
* (This method fails with the version of xerces shipped with jre 1.5)
|
||||
*/
|
||||
public class NewDOMDocument extends DOMDocument {
|
||||
|
||||
/** Constructor
|
||||
*/
|
||||
public NewDOMDocument(String sFileName, String sExtension) {
|
||||
super(sFileName,sExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out content to the supplied <code>OutputStream</code>.
|
||||
* (with pretty printing)
|
||||
* @param os XML <code>OutputStream</code>.
|
||||
* @throws IOException If any I/O error occurs.
|
||||
*/
|
||||
public void write(OutputStream os) throws IOException {
|
||||
OutputStreamWriter osw = new OutputStreamWriter(os,"UTF-8");
|
||||
osw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
|
||||
write(getContentDOM().getDocumentElement(),0,osw);
|
||||
osw.flush();
|
||||
osw.close();
|
||||
}
|
||||
|
||||
// Write nodes; we only need element, text and comment nodes
|
||||
private void write(Node node, int nLevel, OutputStreamWriter osw) throws IOException {
|
||||
short nType = node.getNodeType();
|
||||
switch (nType) {
|
||||
case Node.ELEMENT_NODE:
|
||||
if (node.hasChildNodes()) {
|
||||
// Block pretty print from this node?
|
||||
NodeList list = node.getChildNodes();
|
||||
int nLen = list.getLength();
|
||||
boolean bBlockPrettyPrint = false;
|
||||
if (nLevel>=0) {
|
||||
for (int i = 0; i < nLen; i++) {
|
||||
bBlockPrettyPrint |= list.item(i).getNodeType()==Node.TEXT_NODE;
|
||||
}
|
||||
}
|
||||
// Print start tag
|
||||
if (nLevel>=0) { writeSpaces(nLevel,osw); }
|
||||
osw.write("<"+node.getNodeName());
|
||||
writeAttributes(node,osw);
|
||||
osw.write(">");
|
||||
if (nLevel>=0 && !bBlockPrettyPrint) { osw.write("\n"); }
|
||||
// Print children
|
||||
for (int i = 0; i < nLen; i++) {
|
||||
int nNextLevel;
|
||||
if (bBlockPrettyPrint || nLevel<0) { nNextLevel=-1; }
|
||||
else { nNextLevel=nLevel+1; }
|
||||
write(list.item(i),nNextLevel,osw);
|
||||
}
|
||||
// Print end tag
|
||||
if (nLevel>=0 && !bBlockPrettyPrint) { writeSpaces(nLevel,osw); }
|
||||
osw.write("</"+node.getNodeName()+">");
|
||||
if (nLevel>=0) { osw.write("\n"); }
|
||||
}
|
||||
else { // empty element
|
||||
if (nLevel>=0) { writeSpaces(nLevel,osw); }
|
||||
osw.write("<"+node.getNodeName());
|
||||
writeAttributes(node,osw);
|
||||
osw.write(" />");
|
||||
if (nLevel>=0) { osw.write("\n"); }
|
||||
}
|
||||
break;
|
||||
case Node.TEXT_NODE:
|
||||
write(node.getNodeValue(),osw);
|
||||
break;
|
||||
case Node.COMMENT_NODE:
|
||||
if (nLevel>=0) { writeSpaces(nLevel,osw); }
|
||||
osw.write("<!-- ");
|
||||
write(node.getNodeValue(),osw);
|
||||
osw.write(" -->");
|
||||
if (nLevel>=0) { osw.write("\n"); }
|
||||
}
|
||||
}
|
||||
|
||||
private void writeAttributes(Node node, OutputStreamWriter osw) throws IOException {
|
||||
NamedNodeMap attr = node.getAttributes();
|
||||
int nLen = attr.getLength();
|
||||
for (int i=0; i<nLen; i++) {
|
||||
Node item = attr.item(i);
|
||||
osw.write(" ");
|
||||
write(item.getNodeName(),osw);
|
||||
osw.write("=\"");
|
||||
write(item.getNodeValue(),osw);
|
||||
osw.write("\"");
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSpaces(int nCount, OutputStreamWriter osw) throws IOException {
|
||||
for (int i=0; i<nCount; i++) { osw.write(" "); }
|
||||
}
|
||||
|
||||
private void write(String s, OutputStreamWriter osw) throws IOException {
|
||||
int nLen = s.length();
|
||||
char c;
|
||||
for (int i=0; i<nLen; i++) {
|
||||
c = s.charAt(i);
|
||||
switch (c) {
|
||||
case ('<'): osw.write("<"); break;
|
||||
case ('>'): osw.write(">"); break;
|
||||
case ('&'): osw.write("&"); break;
|
||||
case ('"'): osw.write("""); break;
|
||||
case ('\''): osw.write( "'"); break;
|
||||
default: osw.write(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
455
source/java/writer2latex/xmerge/OfficeConstants.java
Normal file
455
source/java/writer2latex/xmerge/OfficeConstants.java
Normal file
|
@ -0,0 +1,455 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
// This version has been adapted for Writer2LaTeX
|
||||
|
||||
package writer2latex.xmerge;
|
||||
|
||||
/**
|
||||
* This interface contains constants for StarOffice XML tags,
|
||||
* attributes (StarCalc cell types, etc.).
|
||||
*
|
||||
* @author Herbie Ong, Paul Rank, Martin Maher
|
||||
*/
|
||||
public interface OfficeConstants {
|
||||
|
||||
/** Element tag for <i>office:document</i>, this is the root tag. */
|
||||
public final static String TAG_OFFICE_DOCUMENT = "office:document";
|
||||
|
||||
/**
|
||||
* Element tag for <i>office:document-content</i>, this is the root
|
||||
* tag in content.xml.
|
||||
*/
|
||||
public final static String TAG_OFFICE_DOCUMENT_CONTENT = "office:document-content";
|
||||
|
||||
/**
|
||||
* Element tag for <i>office:document-settings</i>, this is the root
|
||||
* tag in content.xml.
|
||||
*/
|
||||
public final static String TAG_OFFICE_DOCUMENT_SETTINGS= "office:document-settings";
|
||||
|
||||
/**
|
||||
* Element tag for <i>office:document-meta</i>, this is the root
|
||||
* tag in content.xml.
|
||||
*/
|
||||
public final static String TAG_OFFICE_DOCUMENT_META= "office:document-meta";
|
||||
|
||||
/**
|
||||
* Element tag for <i>office:document-styles</i>, this is the root tag
|
||||
* in styles.xml.
|
||||
*/
|
||||
public final static String TAG_OFFICE_DOCUMENT_STYLES = "office:document-styles";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>office:class</i> of element
|
||||
* <i>office:document</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_OFFICE_CLASS = "office:class";
|
||||
|
||||
/** Element tag for <i>office:styles</i>. */
|
||||
public final static String TAG_OFFICE_STYLES = "office:styles";
|
||||
|
||||
/** Element tag for <i>office:meta</i>. */
|
||||
public final static String TAG_OFFICE_META = "office:meta";
|
||||
|
||||
/** Element tag for <i>office:automatic-styles</i>. */
|
||||
public final static String TAG_OFFICE_AUTOMATIC_STYLES = "office:automatic-styles";
|
||||
|
||||
/** Element tag for <i>office:master-styles</i>. */
|
||||
public final static String TAG_OFFICE_MASTER_STYLES = "office:master-styles";
|
||||
|
||||
/** Element tag for <i>office:body</i>. */
|
||||
public final static String TAG_OFFICE_BODY = "office:body";
|
||||
|
||||
/** Element tag for <i>office:font-face-decls</i>. */
|
||||
public final static String TAG_OFFICE_FONT_FACE_DECLS = "office:font-face-decls";
|
||||
|
||||
/** Element tag for <i>office:settings</i>. */
|
||||
public final static String TAG_OFFICE_SETTINGS = "office:settings";
|
||||
|
||||
//Adding
|
||||
|
||||
/** Element tag for <i>text:variable-set</i>. */
|
||||
public final static String TAG_TEXT_VARIABLE_SET = "text:variable-set";
|
||||
|
||||
/** Element tag for <i>text:variable-get</i>. */
|
||||
public final static String TAG_TEXT_VARIABLE_GET = "text:variable-get";
|
||||
/** Element tag for <i>text:expression</i>. */
|
||||
public final static String TAG_TEXT_EXPRESSION = "text:expression";
|
||||
|
||||
/** Element tag for <i>text:user-field-get</i>. */
|
||||
public final static String TAG_TEXT_USER_FIELD_GET = "text:user-field-get";
|
||||
|
||||
/** Element tag for <i>text:page-variable-get</i>. */
|
||||
public final static String TAG_TEXT_PAGE_VARIABLE_GET = "text:page-variable-get";
|
||||
/** Element tag for <i>text:sequence</i>. */
|
||||
public final static String TAG_TEXT_SEQUENCE = "text:sequence";
|
||||
|
||||
/** Element tag for <i>text:text-input</i>. */
|
||||
public final static String TAG_TEXT_VARIABLE_INPUT = "text:variable-input";
|
||||
/** Element tag for <i>text:time</i>. */
|
||||
public final static String TAG_TEXT_TIME = "text:time";
|
||||
|
||||
/** Element tag for <i>text:page-count</i>. */
|
||||
public final static String TAG_TEXT_PAGE_COUNT = "text:page-count";
|
||||
/** Element tag for <i>text:page-number</i>. */
|
||||
public final static String TAG_TEXT_PAGE_NUMBER = "text:page-number";
|
||||
/** Element tag for <i>text:author-initials</i>. */
|
||||
public final static String TAG_TEXT_AUTHOR_INITIALS = "text:author-initials";
|
||||
/** Element tag for <i>text:subject</i>. */
|
||||
public final static String TAG_TEXT_SUBJECT = "text:subject";
|
||||
/** Element tag for <i>text:title</i>. */
|
||||
public final static String TAG_TEXT_TITLE = "text:title";
|
||||
/** Element tag for <i>text:creation-time</i>. */
|
||||
public final static String TAG_TEXT_CREATION_TIME = "text:creation-time";
|
||||
|
||||
/** Element tag for <i>text:date</i>. */
|
||||
public final static String TAG_TEXT_DATE = "text:date";
|
||||
/** Element tag for <i>text:text-input</i>. */
|
||||
public final static String TAG_TEXT_TEXT_INPUT = "text:text-input";
|
||||
|
||||
|
||||
//end adding
|
||||
|
||||
/** Element tag for <i>office:font-decls</i>. */
|
||||
public final static String TAG_OFFICE_FONT_DECLS = "office:font-decls";
|
||||
|
||||
/** Element tag for <i>style:font-decl</i>. */
|
||||
public final static String TAG_STYLE_FONT_DECL = "style:font-decl";
|
||||
|
||||
/** Attribute tag for <i>style:name</i> of element <i>style:name</i>. */
|
||||
public final static String ATTRIBUTE_STYLE_NAME = "style:name";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>style:font-pitch</i> of element
|
||||
* <i>style:font-pitch</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_STYLE_FONT_PITCH = "style:font-pitch";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>fo:font-family</i> of element
|
||||
* <i>fo:font-family</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_FO_FONT_FAMILY = "fo:font-family";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>fo:font-family</i> of element
|
||||
* <i>fo:font-family</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_FO_FONT_FAMILY_GENERIC = "fo:font-family-generic";
|
||||
|
||||
/** Element tag for <i>text:p</i>. */
|
||||
public final static String TAG_PARAGRAPH = "text:p";
|
||||
|
||||
/** Element tag for <i>text:</i>. */
|
||||
public final static String TAG_TEXT = "text:";
|
||||
|
||||
/** Element tag for <i>text:h</i>. */
|
||||
public final static String TAG_HEADING = "text:h";
|
||||
|
||||
/** Element tag for <i>text:s</i>. */
|
||||
public final static String TAG_SPACE = "text:s";
|
||||
|
||||
/** Element tag for <i>text:tab-stop</i>. */
|
||||
public final static String TAG_TAB_STOP = "text:tab-stop";
|
||||
|
||||
/** Element tag for <i>text:line-break</i>. */
|
||||
public final static String TAG_LINE_BREAK = "text:line-break";
|
||||
|
||||
/** Element tag for <i>text:span</i>. */
|
||||
public final static String TAG_SPAN = "text:span";
|
||||
|
||||
/** Element tag for <i>text:a</i>. */
|
||||
public final static String TAG_HYPERLINK = "text:a";
|
||||
|
||||
/** Element tag for <i>text:bookmark</i>. */
|
||||
public final static String TAG_BOOKMARK = "text:bookmark";
|
||||
|
||||
/** Element tag for <i>text:bookmark-start</i>. */
|
||||
public final static String TAG_BOOKMARK_START = "text:bookmark-start";
|
||||
|
||||
/** Element tag for <i>text:unordered-list</i>. */
|
||||
public final static String TAG_UNORDERED_LIST = "text:unordered-list";
|
||||
|
||||
/** Element tag for <i>text:ordered-list</i>. */
|
||||
public final static String TAG_ORDERED_LIST = "text:ordered-list";
|
||||
|
||||
/** Element tag for <i>text:list-header</i>. */
|
||||
public final static String TAG_LIST_HEADER = "text:list-header";
|
||||
|
||||
/** Element tag for <i>text:list-item</i>. */
|
||||
public final static String TAG_LIST_ITEM = "text:list-item";
|
||||
|
||||
/** Attribute tag for <i>text:c</i> of element <i>text:s</i>. */
|
||||
public final static String ATTRIBUTE_SPACE_COUNT = "text:c";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>text:style-name</i> of element
|
||||
* <i>text:style-name</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TEXT_STYLE_NAME = "text:style-name";
|
||||
|
||||
/** Element tag for <i>table:table</i>. */
|
||||
public final static String TAG_TABLE = "table:table";
|
||||
|
||||
/** Element tag for <i>table:named-expression</i>. */
|
||||
public final static String TAG_NAMED_EXPRESSIONS = "table:named-expressions";
|
||||
|
||||
/** Element tag for <i>table:named-range</i>. */
|
||||
public final static String TAG_TABLE_NAMED_RANGE= "table:named-range";
|
||||
|
||||
/** Element tag for <i>table:named-expression</i>. */
|
||||
public final static String TAG_TABLE_NAMED_EXPRESSION= "table:named-expression";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:name</i> of element
|
||||
* <i>table:table</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_NAME = "table:name";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:expression</i> of element
|
||||
* <i>table:named-range</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_EXPRESSION = "table:expression";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:base-cell-address</i> of element
|
||||
* <i>table:named-range</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_BASE_CELL_ADDRESS = "table:base-cell-address";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:cell-range-address</i> of element
|
||||
* <i>table:named-range</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_CELL_RANGE_ADDRESS = "table:cell-range-address";
|
||||
|
||||
/** Element tag for <i>table:table-row</i>. */
|
||||
public final static String TAG_TABLE_ROW = "table:table-row";
|
||||
|
||||
/** Element tag for <i>table:table-column</i>. */
|
||||
public final static String TAG_TABLE_COLUMN = "table:table-column";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:default-cell-style-name</i>
|
||||
* of element <i>table:table-column</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_DEFAULT_CELL_STYLE = "table:default-cell-style-name";
|
||||
|
||||
/** Element tag for <i>table:scenario</i>. */
|
||||
public final static String TAG_TABLE_SCENARIO = "table:scenario";
|
||||
|
||||
/** Element tag for <i>table:table-cell</i>. */
|
||||
public final static String TAG_TABLE_CELL = "table:table-cell";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:value-type</i> of element
|
||||
* <i>table:table-cell</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_VALUE_TYPE = "table:value-type";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:number-columns-repeated</i>
|
||||
* of element <i>table:table-cell</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_NUM_COLUMNS_REPEATED =
|
||||
"table:number-columns-repeated";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:number-rows-repeated</i>
|
||||
* of element <i>table:table-row</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_NUM_ROWS_REPEATED =
|
||||
"table:number-rows-repeated";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:formula</i> of element
|
||||
* <i>table:table-cell</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_FORMULA = "table:formula";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:value</i> of element
|
||||
* <i>table:table-cell</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_VALUE = "table:value";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:date-value</i> of element
|
||||
* <i>table:table-cell</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_DATE_VALUE = "table:date-value";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:time-value</i> of element
|
||||
* <i>table:table-cell</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_TIME_VALUE = "table:time-value";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:string-value</i> of element
|
||||
* <i>table:table-cell</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_STRING_VALUE =
|
||||
"table:string-value";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:time-boolean-value</i> of element
|
||||
* <i>table:table-cell</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_BOOLEAN_VALUE =
|
||||
"table:boolean-value";
|
||||
|
||||
/** Attribute tag for <i>table:style-name</i> of table elements. */
|
||||
public final static String ATTRIBUTE_TABLE_STYLE_NAME = "table:style-name";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>table:currency</i> of element
|
||||
* <i>table:table-cell</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_TABLE_CURRENCY = "table:currency";
|
||||
|
||||
/** The cell contains data of type <i>string</i>. */
|
||||
public final static String CELLTYPE_STRING = "string";
|
||||
|
||||
/** The cell contains data of type <i>float</i>. */
|
||||
public final static String CELLTYPE_FLOAT = "float";
|
||||
|
||||
/** The cell contains data of type <i>time</i>. */
|
||||
public final static String CELLTYPE_TIME = "time";
|
||||
|
||||
/** The cell contains data of type <i>date</i>. */
|
||||
public final static String CELLTYPE_DATE = "date";
|
||||
|
||||
/** The cell contains data of type <i>currency</i>. */
|
||||
public final static String CELLTYPE_CURRENCY = "currency";
|
||||
|
||||
/** The cell contains data of type <i>boolean</i>. */
|
||||
public final static String CELLTYPE_BOOLEAN = "boolean";
|
||||
|
||||
/** The cell contains data of type <i>percent</i>. */
|
||||
public final static String CELLTYPE_PERCENT = "percentage";
|
||||
|
||||
/** StarWriter XML file extension. */
|
||||
public final static String SXW_FILE_EXTENSION = ".sxw";
|
||||
|
||||
/** StarWriter XML <i>office:class</i> value. */
|
||||
public final static String SXW_TYPE = "text";
|
||||
|
||||
/** StarCalc XML file extension. */
|
||||
public final static String SXC_FILE_EXTENSION = ".sxc";
|
||||
|
||||
/** StarCalc XML <i>office:class</i> value. */
|
||||
public final static String SXC_TYPE = "spreadsheet";
|
||||
|
||||
/** Element tag for <i>manifest:manifest</i>entry in Manifest XML */
|
||||
public final static String TAG_MANIFEST_ROOT = "manifest:manifest";
|
||||
|
||||
/** Element tag for <i>manifest:file-entry</i> entry in Manifest XML. */
|
||||
public final static String TAG_MANIFEST_FILE = "manifest:file-entry";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>manifest:media-type</i> of element
|
||||
* <i>manifest:file-entry</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_MANIFEST_FILE_TYPE = "manifest:media-type";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>manifest:full-path</i> of element
|
||||
* <i>manifest:file-entry</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_MANIFEST_FILE_PATH = "manifest:full-path";
|
||||
|
||||
// Tags and Elements for the settings.xml
|
||||
|
||||
/** Element tag for <i>config:config-item</i>. */
|
||||
public final static String TAG_CONFIG_ITEM = "config:config-item";
|
||||
|
||||
/** Element tag for <i>config:config-item-set</i>. */
|
||||
public final static String TAG_CONFIG_ITEM_SET = "config:config-item-set";
|
||||
|
||||
/** Element tag for <i>config:config-item-map-indexed</i>. */
|
||||
public final static String TAG_CONFIG_ITEM_MAP_INDEXED = "config:config-item-map-indexed";
|
||||
|
||||
/** Element tag for <i>config:config-item-map-named</i>. */
|
||||
public final static String TAG_CONFIG_ITEM_MAP_NAMED = "config:config-item-map-named";
|
||||
|
||||
/** Element tag for <i>config:config-item-map-entry</i>. */
|
||||
public final static String TAG_CONFIG_ITEM_MAP_ENTRY= "config:config-item-map-entry";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>config:name</i> of element
|
||||
* <i>config:config-item</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_CONFIG_NAME = "config:name";
|
||||
|
||||
/**
|
||||
* Attribute tag for <i>config:type</i> of element
|
||||
* <i>config:config-item</i>.
|
||||
*/
|
||||
public final static String ATTRIBUTE_CONFIG_TYPE = "config:type";
|
||||
|
||||
|
||||
/** StarWriter XML MIME type. */
|
||||
public final static String SXW_MIME_TYPE = "application/vnd.sun.xml.writer";
|
||||
|
||||
/** StarWriter XML Template MIME type. */
|
||||
public final static String STW_MIME_TYPE = "application/vnd.sun.xml.writer.template";
|
||||
|
||||
/** StarCalc XML MIME type. */
|
||||
public final static String SXC_MIME_TYPE = "application/vnd.sun.xml.calc";
|
||||
|
||||
/** StarCalc XML Template MIME type. */
|
||||
public final static String STC_MIME_TYPE = "application/vnd.sun.xml.calc.template";
|
||||
|
||||
/** StarImpress XML MIME type. */
|
||||
public final static String SXI_MIME_TYPE = "application/vnd.sun.xml.impress";
|
||||
|
||||
/** StarImpress XML Template MIME type. */
|
||||
public final static String STI_MIME_TYPE = "application/vnd.sun.xml.impress.template";
|
||||
|
||||
/** StarDraw XML MIME type. */
|
||||
public final static String SXD_MIME_TYPE = "application/vnd.sun.xml.draw";
|
||||
|
||||
/** StarMath XML MIME type. */
|
||||
public final static String SXM_MIME_TYPE = "application/vnd.sun.xml.math";
|
||||
|
||||
/** StarWriter Global XML MIME Type */
|
||||
public final static String SXG_MIME_TYPE = "application/vnd.sun.xml.writer.global";
|
||||
}
|
1287
source/java/writer2latex/xmerge/OfficeDocument.java
Normal file
1287
source/java/writer2latex/xmerge/OfficeDocument.java
Normal file
File diff suppressed because it is too large
Load diff
145
source/java/writer2latex/xmerge/OfficeDocumentException.java
Normal file
145
source/java/writer2latex/xmerge/OfficeDocumentException.java
Normal file
|
@ -0,0 +1,145 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
// This version is adapted for Writer2LaTeX
|
||||
// Version 1.0 (2008-11-22)
|
||||
|
||||
package writer2latex.xmerge;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
//import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
//import org.openoffice.xmerge.util.Resources;
|
||||
|
||||
/**
|
||||
* Used by OfficeDocument to encapsulate exceptions. It will add
|
||||
* more details to the message string if it is of type
|
||||
* <code>SAXParseException</code>.
|
||||
*
|
||||
* @author Herbie Ong
|
||||
*/
|
||||
|
||||
public final class OfficeDocumentException extends IOException {
|
||||
|
||||
StringBuffer message = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor, capturing additional information from the
|
||||
* <code>SAXException</code>.
|
||||
*
|
||||
* @param e The <code>SAXException</code>.
|
||||
*/
|
||||
public OfficeDocumentException(SAXException e) {
|
||||
super(e.toString());
|
||||
message = new StringBuffer();
|
||||
if (e instanceof SAXParseException) {
|
||||
String msgParseError =
|
||||
"PARSE_ERROR";
|
||||
String msgLine =
|
||||
"LINE";
|
||||
String msgColumn =
|
||||
"COLUMN";
|
||||
String msgPublicId =
|
||||
"PUBLIC_ID";
|
||||
String msgSystemId =
|
||||
"SYSTEM_ID";
|
||||
SAXParseException spe = (SAXParseException) e;
|
||||
message.append(msgParseError);
|
||||
message.append(": ");
|
||||
message.append(msgLine);
|
||||
message.append(": ");
|
||||
message.append(spe.getLineNumber());
|
||||
message.append(", ");
|
||||
message.append(msgColumn);
|
||||
message.append(": ");
|
||||
message.append(spe.getColumnNumber());
|
||||
message.append(", ");
|
||||
message.append(msgSystemId);
|
||||
message.append(": ");
|
||||
message.append(spe.getSystemId());
|
||||
message.append(", ");
|
||||
message.append(msgPublicId);
|
||||
message.append(": ");
|
||||
message.append(spe.getPublicId());
|
||||
message.append("\n");
|
||||
}
|
||||
|
||||
// if there exists an embedded exception
|
||||
Exception ex = e.getException();
|
||||
if (ex != null) {
|
||||
message.append(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor, creates exception with provided message.
|
||||
*
|
||||
* @param s Message value for the exception.
|
||||
*/
|
||||
public OfficeDocumentException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor, creates exception with the message
|
||||
* corresponding to the message value of the provided
|
||||
* exception.
|
||||
*
|
||||
* @param e The Exception.
|
||||
*/
|
||||
public OfficeDocumentException(Exception e) {
|
||||
super(e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the message value for the <code>Exception</code>.
|
||||
*
|
||||
* @return The message value for the <code>Exception</code>.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message.toString() + super.getMessage();
|
||||
}
|
||||
}
|
||||
|
473
source/java/writer2latex/xmerge/OfficeZip.java
Normal file
473
source/java/writer2latex/xmerge/OfficeZip.java
Normal file
|
@ -0,0 +1,473 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* The Contents of this file are made available subject to the terms of
|
||||
*
|
||||
* - GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* Sun Microsystems Inc., October, 2000
|
||||
*
|
||||
* GNU Lesser General Public License Version 2.1
|
||||
* =============================================
|
||||
* Copyright 2000 by Sun Microsystems, Inc.
|
||||
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
||||
*
|
||||
* Copyright: 2000 by Sun Microsystems, Inc.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): _______________________________________
|
||||
*
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
// This version is adapted for Writer2LaTeX
|
||||
// Version 1.0 (2008-11-22)
|
||||
|
||||
package writer2latex.xmerge;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.CRC32;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
//import org.openoffice.xmerge.util.Debug;
|
||||
|
||||
/**
|
||||
* Class used by {@link
|
||||
* org.openoffice.xmerge.converter.OfficeDocument
|
||||
* OfficeDocument} to handle reading and writing
|
||||
* from a ZIP file, as well as storing ZIP entries.
|
||||
*
|
||||
* @author Herbie Ong
|
||||
*/
|
||||
class OfficeZip {
|
||||
|
||||
/** File name of the XML file in a zipped document. */
|
||||
private final static String CONTENTXML = "content.xml";
|
||||
|
||||
private final static String STYLEXML = "styles.xml";
|
||||
private final static String METAXML = "meta.xml";
|
||||
private final static String SETTINGSXML = "settings.xml";
|
||||
private final static String MANIFESTXML = "META-INF/manifest.xml";
|
||||
|
||||
private final static int BUFFERSIZE = 1024;
|
||||
|
||||
private List entryList = null;
|
||||
|
||||
private int contentIndex = -1;
|
||||
private int styleIndex = -1;
|
||||
private int metaIndex = -1;
|
||||
private int settingsIndex = -1;
|
||||
private int manifestIndex = -1;
|
||||
|
||||
/** Default constructor. */
|
||||
OfficeZip() {
|
||||
|
||||
entryList = new LinkedList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Read each zip entry in the <code>InputStream</code> object
|
||||
* and store in entryList both the <code>ZipEntry</code> object
|
||||
* as well as the bits of each entry. Call this method before
|
||||
* calling the <code>getContentXMLBytes</code> method or the
|
||||
* <code>getStyleXMLBytes</code> method.</p>
|
||||
*
|
||||
* <p>Keep track of the CONTENTXML and STYLEXML using
|
||||
* contentIndex and styleIndex, respectively.</p>
|
||||
*
|
||||
* @param is <code>InputStream</code> object to read.
|
||||
*
|
||||
* @throws IOException If any I/O error occurs.
|
||||
*/
|
||||
void read(InputStream is) throws IOException {
|
||||
|
||||
ZipInputStream zis = new ZipInputStream(is);
|
||||
ZipEntry ze = null;
|
||||
int i = -1;
|
||||
|
||||
while ((ze = zis.getNextEntry()) != null) {
|
||||
|
||||
String name = ze.getName();
|
||||
//System.out.println("Found "+name);
|
||||
|
||||
// Debug.log(Debug.TRACE, "reading entry: " + name);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
int len = 0;
|
||||
byte buffer[] = new byte[BUFFERSIZE];
|
||||
|
||||
while ((len = zis.read(buffer)) > 0) {
|
||||
baos.write(buffer, 0, len);
|
||||
}
|
||||
|
||||
byte bytes[] = baos.toByteArray();
|
||||
Entry entry = new Entry(ze,bytes);
|
||||
|
||||
entryList.add(entry);
|
||||
|
||||
i++;
|
||||
|
||||
if (name.equalsIgnoreCase(CONTENTXML)) {
|
||||
contentIndex = i;
|
||||
}
|
||||
else if (name.equalsIgnoreCase(STYLEXML)) {
|
||||
styleIndex = i;
|
||||
}
|
||||
else if (name.equalsIgnoreCase(METAXML)) {
|
||||
metaIndex = i;
|
||||
}
|
||||
else if (name.equalsIgnoreCase(SETTINGSXML)) {
|
||||
settingsIndex = i;
|
||||
}
|
||||
else if (name.equalsIgnoreCase(MANIFESTXML)) {
|
||||
manifestIndex = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
zis.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns the CONTENTXML file in a
|
||||
* <code>byte</code> array. It returns null if there is no
|
||||
* CONTENTXML in this zip file.
|
||||
*
|
||||
* @return CONTENTXML in a <code>byte</code> array.
|
||||
*/
|
||||
byte[] getContentXMLBytes() {
|
||||
|
||||
return getEntryBytes(contentIndex);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns the STYLEXML file in a
|
||||
* <code>byte</code> array. It returns null if there is
|
||||
* no STYLEXML in this zip file.
|
||||
*
|
||||
* @return STYLEXML in a <code>byte</code> array.
|
||||
*/
|
||||
byte[] getStyleXMLBytes() {
|
||||
|
||||
return getEntryBytes(styleIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the METAXML file in a
|
||||
* <code>byte</code> array. It returns null if there is
|
||||
* no METAXML in this zip file.
|
||||
*
|
||||
* @return METAXML in a <code>byte</code> array.
|
||||
*/
|
||||
byte[] getMetaXMLBytes() {
|
||||
return getEntryBytes(metaIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the SETTINGSXML file in a
|
||||
* <code>byte</code> array. It returns null if there is
|
||||
* no SETTINGSXML in this zip file.
|
||||
*
|
||||
* @return SETTINGSXML in a <code>byte</code> array.
|
||||
*/
|
||||
byte[] getSettingsXMLBytes() {
|
||||
return getEntryBytes(settingsIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the MANIFESTXML file in a <code>byte</code> array.
|
||||
* It returns null if there is no MANIFESTXML in this zip file.
|
||||
*
|
||||
* @return MANIFESTXML in a <code>byte</code> array.
|
||||
*/
|
||||
byte[] getManifestXMLBytes() {
|
||||
return getEntryBytes(manifestIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns the bytes corresponding to the entry named in the
|
||||
* parameter.
|
||||
*
|
||||
* @param name The name of the entry in the Zip file to retrieve.
|
||||
*
|
||||
* @return The data for the named entry in a <code>byte</code> array or
|
||||
* <code>null</code> if no entry is found.
|
||||
*/
|
||||
byte[] getNamedBytes(String name) {
|
||||
|
||||
// The list is not sorted, and sorting it for a binary search would
|
||||
// invalidate the indices stored for the main files.
|
||||
|
||||
// Could improve performance by caching the name and index when
|
||||
// iterating through the ZipFile in read().
|
||||
for (int i = 0; i < entryList.size(); i++) {
|
||||
Entry e = (Entry)entryList.get(i);
|
||||
|
||||
if (e.zipEntry.getName().equals(name)) {
|
||||
return getEntryBytes(i);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method sets the bytes for the named entry. It searches for a
|
||||
* matching entry in the LinkedList. If no entry is found, a new one is
|
||||
* created.
|
||||
*
|
||||
* Writing of data is defferred to setEntryBytes().
|
||||
*
|
||||
* @param name The name of the entry to search for.
|
||||
* @param bytes The new data to write.
|
||||
*/
|
||||
void setNamedBytes(String name, byte[] bytes) {
|
||||
for (int i = 0; i < entryList.size(); i++) {
|
||||
Entry e = (Entry)entryList.get(i);
|
||||
|
||||
if (e.zipEntry.getName().equals(name)) {
|
||||
setEntryBytes(i, bytes, name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If we're here, no entry was found. Call setEntryBytes with an index
|
||||
// of -1 to insert a new entry.
|
||||
setEntryBytes(-1, bytes, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by the <code>getContentXMLBytes</code> method and the
|
||||
* <code>getStyleXMLBytes</code> method to return the
|
||||
* <code>byte</code> array from the corresponding
|
||||
* <code>entry</code> in the <code>entryList</code>.
|
||||
*
|
||||
* @param index Index of <code>Entry</code> object in
|
||||
* <code>entryList</code>.
|
||||
*
|
||||
* @return <code>byte</code> array associated in that
|
||||
* <code>Entry</code> object or null, if there is
|
||||
* not such <code>Entry</code>.
|
||||
*/
|
||||
private byte[] getEntryBytes(int index) {
|
||||
|
||||
byte[] bytes = null;
|
||||
|
||||
if (index > -1) {
|
||||
Entry entry = (Entry) entryList.get(index);
|
||||
bytes = entry.bytes;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set or replace the <code>byte</code> array for the
|
||||
* CONTENTXML file.
|
||||
*
|
||||
* @param bytes <code>byte</code> array for the
|
||||
* CONTENTXML file.
|
||||
*/
|
||||
void setContentXMLBytes(byte bytes[]) {
|
||||
|
||||
contentIndex = setEntryBytes(contentIndex, bytes, CONTENTXML);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set or replace the <code>byte</code> array for the
|
||||
* STYLEXML file.
|
||||
*
|
||||
* @param bytes <code>byte</code> array for the
|
||||
* STYLEXML file.
|
||||
*/
|
||||
void setStyleXMLBytes(byte bytes[]) {
|
||||
|
||||
styleIndex = setEntryBytes(styleIndex, bytes, STYLEXML);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set or replace the <code>byte</code> array for the
|
||||
* METAXML file.
|
||||
*
|
||||
* @param bytes <code>byte</code> array for the
|
||||
* METAXML file.
|
||||
*/
|
||||
void setMetaXMLBytes(byte bytes[]) {
|
||||
|
||||
metaIndex = setEntryBytes(metaIndex, bytes, METAXML);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set or replace the <code>byte</code> array for the
|
||||
* SETTINGSXML file.
|
||||
*
|
||||
* @param bytes <code>byte</code> array for the
|
||||
* SETTINGSXML file.
|
||||
*/
|
||||
void setSettingsXMLBytes(byte bytes[]) {
|
||||
|
||||
settingsIndex = setEntryBytes(settingsIndex, bytes, SETTINGSXML);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set or replace the <code>byte</code> array for the MANIFESTXML file.
|
||||
*
|
||||
* @param bytes <code>byte</code> array for the MANIFESTXML file.
|
||||
*/
|
||||
void setManifestXMLBytes(byte bytes[]) {
|
||||
manifestIndex = setEntryBytes(manifestIndex, bytes, MANIFESTXML);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Used by the <code>setContentXMLBytes</code> method and
|
||||
* the <code>setStyleXMLBytes</code> to either replace an
|
||||
* existing <code>Entry</code>, or create a new entry in
|
||||
* <code>entryList</code>.</p>
|
||||
*
|
||||
* <p>If there is an <code>Entry</code> object within
|
||||
* entryList that corresponds to the index, replace the
|
||||
* <code>ZipEntry</code> info.</p>
|
||||
*
|
||||
* @param index Index of <code>Entry</code> to modify.
|
||||
* @param bytes <code>Entry</code> value.
|
||||
* @param name Name of <code>Entry</code>.
|
||||
*
|
||||
* @return Index of value added or modified in entryList
|
||||
*/
|
||||
private int setEntryBytes(int index, byte bytes[], String name) {
|
||||
|
||||
if (index > -1) {
|
||||
|
||||
// replace existing entry in entryList
|
||||
|
||||
Entry entry = (Entry) entryList.get(index);
|
||||
name = entry.zipEntry.getName();
|
||||
int method = entry.zipEntry.getMethod();
|
||||
|
||||
ZipEntry ze = createZipEntry(name, bytes, method);
|
||||
|
||||
entry.zipEntry = ze;
|
||||
entry.bytes= bytes;
|
||||
|
||||
} else {
|
||||
|
||||
// add a new entry into entryList
|
||||
ZipEntry ze = createZipEntry(name, bytes, ZipEntry.DEFLATED);
|
||||
Entry entry = new Entry(ze, bytes);
|
||||
entryList.add(entry);
|
||||
index = entryList.size() - 1;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write out the ZIP entries into the <code>OutputStream</code>
|
||||
* object.
|
||||
*
|
||||
* @param os <code>OutputStream</code> object to write ZIP.
|
||||
*
|
||||
* @throws IOException If any ZIP I/O error occurs.
|
||||
*/
|
||||
void write(OutputStream os) throws IOException {
|
||||
|
||||
// Debug.log(Debug.TRACE, "Writing out the following entries into zip.");
|
||||
|
||||
ZipOutputStream zos = new ZipOutputStream(os);
|
||||
|
||||
ListIterator iterator = entryList.listIterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
Entry entry = (Entry) iterator.next();
|
||||
ZipEntry ze = entry.zipEntry;
|
||||
|
||||
//String name = ze.getName();
|
||||
|
||||
// Debug.log(Debug.TRACE, "... " + name);
|
||||
|
||||
zos.putNextEntry(ze);
|
||||
zos.write(entry.bytes);
|
||||
}
|
||||
|
||||
zos.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a <code>ZipEntry</code> object based on the given params.
|
||||
*
|
||||
* @param name Name for the <code>ZipEntry</code>.
|
||||
* @param bytes <code>byte</code> array for <code>ZipEntry</code>.
|
||||
* @param method ZIP method to be used for <code>ZipEntry</code>.
|
||||
*
|
||||
* @return A <code>ZipEntry</code> object.
|
||||
*/
|
||||
private ZipEntry createZipEntry(String name, byte bytes[], int method) {
|
||||
|
||||
ZipEntry ze = new ZipEntry(name);
|
||||
|
||||
ze.setMethod(method);
|
||||
ze.setSize(bytes.length);
|
||||
|
||||
CRC32 crc = new CRC32();
|
||||
crc.reset();
|
||||
crc.update(bytes);
|
||||
ze.setCrc(crc.getValue());
|
||||
|
||||
ze.setTime(System.currentTimeMillis());
|
||||
|
||||
return ze;
|
||||
}
|
||||
|
||||
/**
|
||||
* This inner class is used as a data structure for holding
|
||||
* a <code>ZipEntry</code> info and its corresponding bytes.
|
||||
* These are stored in entryList.
|
||||
*/
|
||||
private class Entry {
|
||||
|
||||
ZipEntry zipEntry = null;
|
||||
byte bytes[] = null;
|
||||
|
||||
Entry(ZipEntry zipEntry, byte bytes[]) {
|
||||
this.zipEntry = zipEntry;
|
||||
this.bytes = bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
source/java/writer2latex/xmerge/Package.html
Normal file
15
source/java/writer2latex/xmerge/Package.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>The package writer2latex.xmerge</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>Classes originating from OOo's xmerge.</p>
|
||||
<p>Previously, Writer2LaTeX was based on xmerge, but this is not the case
|
||||
anymore. The classes in this packages are reminiscent of that.</p>
|
||||
<p>This package is supposed to go away in a future version and be replaced by
|
||||
something else (probably ODFDOM)</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue