4,10 → 4,10 |
* Coded by: Group 5, software practice summer 2003 |
* University of Bielefeld, Germany |
* |
* @version $Revision: 1.54 $ |
* @version $Revision: 1.55 $ |
* |
* Last modification: $Date: 2003/07/22 14:46:00 $ |
* $Id: OurDocument.java,v 1.54 2003/07/22 14:46:00 smcsporr Exp $ |
* Last modification: $Date: 2003/07/22 16:03:37 $ |
* $Id: OurDocument.java,v 1.55 2003/07/22 16:03:37 smcsporr Exp $ |
*/ |
|
package src.document; |
38,11 → 38,12 |
|
/** |
* This class represents the document object the program |
* is working on. |
* is working on. Instances of this class are handled by the |
* <code>DocumentManager</code>. |
* |
* @author S. McSporran |
* |
* @version $Revision: 1.54 $ Last modification: $Date: 2003/07/22 14:46:00 $ |
* @version $Revision: 1.55 $ Last modification: $Date: 2003/07/22 16:03:37 $ |
*/ |
public class OurDocument { |
|
56,12 → 57,20 |
/* A reference variable to the log panel. */ |
private LogInterface LogInterfaceReference; |
|
/* 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). */ |
private File name; |
|
/* The title of the current document. */ |
private String title; |
|
/* Indicates, if the current document has been changed. */ |
private boolean isChanged; |
|
private LinkedList visibleTree = new LinkedList(); |
private String xpathExpression = ""; |
|
91,13 → 100,13 |
} |
|
/** |
* The method <code>setVisibleTree</code> savex the currently expanded |
* The method <code>setVisibleTree</code> saves the currently expanded |
* nodes. |
* |
* @see java.util.LinkedList; |
* @see javax.swing.tree.TreePath; |
* @param en: A <code>LinkedList</code> of visible <code>TreePath</code>s. |
* |
* @param en: A <code>LinkedList</code> of visible <code>TreePath</code>s. |
* @see java.util.LinkedList |
* @see javax.swing.tree.TreePath |
*/ |
public void setVisibleTree(LinkedList en) { |
if (en != null) { |
106,10 → 115,13 |
} |
|
/** |
* The method <code>getVisibleTree</code> returns the currently expanded |
* The method <code>getVisibleTree</code> returns the saved expanded |
* nodes. |
* |
* @return A <code>LinkedList</code> of <code>TreePath</code>s. |
* |
* @see java.util.LinkedList |
* @see javax.swing.tree.TreePath |
*/ |
public LinkedList getVisibleTree() { |
return (LinkedList)visibleTree.clone(); |
116,8 → 128,7 |
} |
|
/** |
* <code>setExpression</code> sets an XPath expression to |
* save the currently expanded tree nodes. |
* TODO comment |
* |
* @param expression: The XPath expression. |
*/ |
199,6 → 210,8 |
* |
* @param fName: The new file name. |
* |
* @see java.io.File |
* |
* Last revision: 17-Jul-2003 |
*/ |
public void setFileName(File fName) { |
210,6 → 223,8 |
* |
* @return The name of the document's file as <code>File</code>-object. |
* |
* @see java.io.File |
* |
* Last revision: 17-Jul-2003 |
*/ |
public File getFileName() { |
217,14 → 232,16 |
} |
|
/** |
* <code>changeSchemaGrammar</code> changes a document's schema. |
* <code>changeSchemaGrammar</code> changes a document's schema grammar. |
* |
* @param changeDoc: The document who's schema should be changed. |
* @param changeDoc: The document who's associated schema should be changed. |
* @param dtdFile: The new schema's path and filename as <code>File</code>-object. |
* |
* @see java.io.File |
* |
* author S. McSporran |
* |
* Last revision: 14-Jul-2003 |
* Last revision: 19-Jul-2003 by S. McSporran |
*/ |
public void changeSchemaGrammar(DocumentImpl changeDoc, File schemaFile) { |
|
239,9 → 256,11 |
/** |
* <code>changeDTDGrammar</code> changes a document's DTD. |
* |
* @param changeDoc: The document who's DTD should be changed. |
* @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 |
* |
* Last revision: 18-Jul-2003 |
269,8 → 288,8 |
/* Get the buffer associated with the StringWriter outputWr. */ |
String bufferString = strWriter.getBuffer().toString(); |
|
/* Parse the document and set it as the instances document. */ |
aParser.parse(bufferString); |
|
myDocument = aParser.getDocument(); |
|
log(LogInterface.TYPE_INFO, "DTD changed to: " + myDocument.getDoctype().getSystemId()); |
278,7 → 297,6 |
|
/* Catch and log transformation errors. */ |
catch (TransformerException te) { |
|
log (LogInterface.TYPE_ERROR, "Transformation error: " + te.getMessage()); |
} |
} |
289,6 → 307,8 |
* @param saveDoc: The document to be saved. |
* @param ftsi: A valid file name. |
* |
* @see java.io.File |
* |
* author S. McSporran |
* |
* Last revision: 23-Jun-2003 |
311,7 → 331,6 |
/* 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. */ |
324,7 → 343,7 |
|
/** |
* <code>setSaved</code> set's the current <code>OurDocument</code> object |
* as the latest saved version of the document; should only be used after saving |
* to be the latest saved version of the document; should only be used after saving |
* the document. |
* |
* author H. Jakusch |
336,9 → 355,12 |
} |
|
/** |
* <code>getIsChanged</code> returns true, if the |
* actual document has been changed and not saved; otherwise it returns false. |
* <code>getIsChanged</code> returns <code>true</code>, if the |
* actual document has been changed and not saved; otherwise it returns <code>false</code>. |
* |
* @return A <code>boolean</code> value indicating if the document of the current |
* <code>OurDocument</code> instance has been changed since the last save. |
* |
* author H. Jakusch |
* |
* Last revision: 18-Jul-2003 |
348,26 → 370,22 |
try { |
if (lastSaved.compareTo(domToString(myDocument))!= 0) { |
return true; |
} |
else { |
} else { |
return false; |
} |
} |
|
catch(Exception e) { |
LogInterfaceReference.log(LogInterface.TYPE_ERROR, |
"Fatal Error: Document doesn't contain Text"); |
"Fatal error: Document doesn't contain text."); |
return false; |
} |
} |
|
|
/** |
* @see src.gui.LogInterface#log(java.lang.String) |
*/ |
/* Sends messages to the log panel. */ |
private void log(int i, String message) { |
LogInterfaceReference.log(i,message); |
} |
|
|
/** |
* <code>domToString</code> converts a DOM document instance into |
374,13 → 392,22 |
* a <code>String</code> representation. |
* |
* @param docuNode: The root node of the document to transform. |
* |
* @return A string representation of the document. |
* |
* author Group 5 |
* |
* Last revision: 21-Jul-2003 by H. Jakusch |
*/ |
private String domToString(DocumentImpl docuNode) { |
|
/* Set the document as source for the transformation. */ |
DOMSource source = new DOMSource(docuNode); |
|
/* Create a StringWriter and assign it to be the result target for the transformation. */ |
java.io.StringWriter stringWriter = new java.io.StringWriter(); |
StreamResult stream = new StreamResult(stringWriter); |
|
try { |
|
/* Create a TransformerFactory and a new Transformer. */ |
404,11 → 431,13 |
docTransformer.transform(source, stream); |
} |
|
/* Catch and log exceptions thrown by the Transformer. */ |
catch (TransformerException te){ |
LogInterfaceReference.log(LogInterface.TYPE_ERROR, "Transformer error: " |
+ te.getMessage()); |
} |
|
/* Convert the Writer's buffer into a string and return it's content. */ |
String string = stringWriter.getBuffer().toString(); |
return string; |
} |