4,10 → 4,10 |
* Coded by: Group 5, software practice summer 2003 |
* University of Bielefeld, Germany |
* |
* @version $Revision: 1.59 $ |
* @version $Revision: 1.60 $ |
* |
* Last modification: $Date: 2003/07/24 13:05:42 $ |
* $Id: OurDocument.java,v 1.59 2003/07/24 13:05:42 smcsporr Exp $ |
* Last modification: $Date: 2003/07/24 13:55:29 $ |
* $Id: OurDocument.java,v 1.60 2003/07/24 13:55:29 smcsporr Exp $ |
*/ |
|
package src.document; |
43,32 → 43,32 |
* |
* @author S. McSporran |
* |
* @version $Revision: 1.59 $ Last modification: $Date: 2003/07/24 13:05:42 $ |
* @version $Revision: 1.60 $ Last modification: $Date: 2003/07/24 13:55:29 $ |
*/ |
public class OurDocument { |
|
/* Create an instance of a Parser object. */ |
/** Create an instance of the <code>Parser</code> class. */ |
private Parser aParser = new Parser(); |
|
/* Declarations of a transformer and a factory. */ |
/** Declarations of a transformer and a factory. */ |
private TransformerFactory transFactory; |
private Transformer docTransformer; |
|
/* A reference variable to the log panel. */ |
/** A reference variable to the log panel used to print out log messages. */ |
private LogInterface LogInterfaceReference; |
|
/* Create an empty DOM document used as data container. */ |
/** Create an empty DOM document used as data container. */ |
private DocumentImpl myDocument = new DocumentImpl(); |
|
private String lastSaved; |
|
/* The path and name of the current XML document file (if existing). */ |
/** The path and name of the current XML document file (if existing). */ |
private File name; |
|
/* The title of the current document. */ |
/** The title of the current document. */ |
private String title; |
|
/* Indicates, if the current document has been changed. */ |
/** Indicates, if the current document has been changed. */ |
private boolean isChanged; |
|
private LinkedList visibleTree = new LinkedList(); |
274,9 → 274,12 |
/** |
* The method <code>changeDTDGrammar</code> changes a document's DTD. |
* |
* @param changeDoc: The document who's associated DTD should be changed. |
* @param dtdFile: The new DTD's path and filename as <code>File</code>-object. |
* A DOCTYPE-entry will be inserted or replaced containing a SYSTEM-entry |
* that points to the file specified. |
* |
* @param changeDoc The document who's associated DTD should be changed. |
* @param dtdFile The new DTD's path and filename as <code>File</code>-object. |
* |
* @see java.io.File |
* |
* author S. McSporran |
322,6 → 325,9 |
/** |
* This method saves a document to a specified file. |
* |
* A transformer will be used to output the document. An optional |
* DOCTYPE-entry will be saved. |
* |
* @param saveDoc: The document to be saved. |
* @param ftsi: A valid file name. |
* |
329,33 → 335,38 |
* |
* author S. McSporran |
* |
* Last revision: 23-Jun-2003 |
* Last revision: 23-Jul-2003 by S. McSporran |
*/ |
public void saveDocument(Document saveDoc, File ftsi) { |
|
/* Set the document parameter as input source for the transformer. */ |
DOMSource dSource = new DOMSource(saveDoc); |
if (ftsi.canWrite()) { |
|
/* Set the resulting stream to the file. */ |
StreamResult strResult = new StreamResult(ftsi); |
|
/* Adds the DOCTYPE-entry to the file to save (if present). */ |
if (((saveDoc.getDoctype()) != null) && (saveDoc.getDoctype().getInternalSubset() == null)) { |
String docTypeFile = (new File(saveDoc.getDoctype().getSystemId())).getName(); |
docTransformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, docTypeFile); |
/* Set the document parameter as input source for the transformer. */ |
DOMSource dSource = new DOMSource(saveDoc); |
|
/* Set the resulting stream to the file. */ |
StreamResult strResult = new StreamResult(ftsi); |
|
/* Adds the DOCTYPE-entry to the file to save (if present). */ |
if (((saveDoc.getDoctype()) != null) && (saveDoc.getDoctype().getInternalSubset() == null)) { |
String docTypeFile = (new File(saveDoc.getDoctype().getSystemId())).getName(); |
docTransformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, docTypeFile); |
} |
|
try { |
/* Create an OutputStream from saveDoc with ftsi as output target. */ |
docTransformer.transform(dSource, strResult); |
log(LogInterface.TYPE_INFO, "Document saved successfully."); |
} |
|
/* Catch and log exceptions thrown by the transformer. */ |
catch (TransformerException te) { |
log(LogInterface.TYPE_ERROR, "Transformation error: " + |
te.getMessage()); |
} |
} else { |
log(LogInterface.TYPE_ERROR, "Cannot write to file " + ftsi.getName() + " !"); |
} |
|
try { |
/* Create an OutputStream from saveDoc with ftsi as output target. */ |
docTransformer.transform(dSource, strResult); |
log(LogInterface.TYPE_INFO, "Document saved successfully."); |
} |
|
/* Catch and log exceptions thrown by the transformer. */ |
catch (TransformerException te) { |
log(LogInterface.TYPE_ERROR, "Transformation error: " + |
te.getMessage()); |
} |
} |
|
|
401,9 → 412,17 |
} |
|
/** |
* Sends a text message of a specified type (info, error, warning) to the |
* registered log panel. |
* A reference to an implementation of a log panel can be set with the |
* <code>setLogInterface</code> method. |
* |
* @param i int: Type of the message like difinied in src.gui.LogInterface |
* @param message String: the Message wished to display on the GUI's logPanel |
* @param i The type of the message as defined in src.gui.LogInterface. |
* 0 or src.gui.LogInterface.TYPE_INFO -> info message (black) |
* 1 or src.gui.LogInterface.TYPE_WARNING -> warning message (orange) |
* 2 or src.gui.LogInterface.TYPE_ERROR -> error message (red) |
* |
* @param message The text message to display in the log panel. |
*/ |
private void log(int i, String message) { |
LogInterfaceReference.log(i,message); |
415,7 → 434,7 |
* image of the last saved document and is called by the <code>setSaved</code> |
* method. |
* |
* @param docuNode: The document to transform. |
* @param docuNode The document to transform. |
* |
* @return A string representation of the document. |
* |