4,10 → 4,10 |
* Coded by: Group 5, software practice summer 2003 |
* University of Bielefeld, Germany |
* |
* @version $Revision: 1.67 $ |
* @version $Revision: 1.68 $ |
* |
* Last modification: $Date: 2003/07/26 11:48:47 $ |
* $Id: OurDocument.java,v 1.67 2003/07/26 11:48:47 smcsporr Exp $ |
* Last modification: $Date: 2003/07/26 13:05:50 $ |
* $Id: OurDocument.java,v 1.68 2003/07/26 13:05:50 smcsporr Exp $ |
*/ |
|
package src.document; |
44,7 → 44,7 |
* |
* @author S. McSporran |
* |
* @version $Revision: 1.67 $ Last modification: $Date: 2003/07/26 11:48:47 $ |
* @version $Revision: 1.68 $ Last modification: $Date: 2003/07/26 13:05:50 $ |
*/ |
public class OurDocument { |
|
316,52 → 316,66 |
*/ |
public void changeDTDGrammar(DocumentImpl changeDoc, File dtdFile) { |
|
/* Set the document parameter as source for the transformation. */ |
DOMSource dSource = new DOMSource(changeDoc); |
String oldDocType = null; |
Transformer DTDDocTransformer; |
|
if (changeDoc.getDoctype() != null) { |
oldDocType = changeDoc.getDoctype().getName(); |
} |
try { |
/* Create a TransformerFactory and a new Transformer. */ |
transFactory = TransformerFactory.newInstance(); |
DTDDocTransformer = transFactory.newTransformer(); |
|
/* Save the transformation result to a string buffer. */ |
StringWriter strWriter = new StringWriter(); |
PrintWriter outputWr = new PrintWriter(strWriter); |
StreamResult sResult = new StreamResult(outputWr); |
/* Set the document parameter as source for the transformation. */ |
DOMSource dSource = new DOMSource(changeDoc); |
String oldDocType = null; |
|
try { |
if (dtdFile != null) { |
/* Set the 'DOCTYPE' entry in the XML file. */ |
docTransformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dtdFile.getPath()); |
} else { |
if (changeDoc.getDoctype() != null) { |
oldDocType = changeDoc.getDoctype().getName(); |
} |
|
/* Save the transformation result to a string buffer. */ |
StringWriter strWriter = new StringWriter(); |
PrintWriter outputWr = new PrintWriter(strWriter); |
StreamResult sResult = new StreamResult(outputWr); |
|
try { |
if (dtdFile != null) { |
/* Set the 'DOCTYPE' entry in the XML file. */ |
DTDDocTransformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dtdFile.getPath()); |
} else { |
} |
|
/* Transform the document, delete any DOCTYPE entry. */ |
docTransformer.transform(dSource,sResult); |
/* Transform the document, delete any DOCTYPE entry. */ |
DTDDocTransformer.transform(dSource,sResult); |
|
/* Get the buffer associated with the StringWriter outputWr. */ |
String bufferString = strWriter.getBuffer().toString(); |
|
aParser.parse(bufferString); |
myDocument = aParser.getDocument(); |
/* Get the buffer associated with the StringWriter outputWr. */ |
String bufferString = strWriter.getBuffer().toString(); |
|
/* Operation: Change DTD. */ |
if (dtdFile != null) { |
log(LogInterface.TYPE_INFO, "DTD changed to: " + myDocument.getDoctype().getSystemId()); |
} |
aParser.parse(bufferString); |
myDocument = aParser.getDocument(); |
|
/* Operation: Change DTD. */ |
if (dtdFile != null) { |
log(LogInterface.TYPE_INFO, "DTD changed to: " + myDocument.getDoctype().getSystemId()); |
} |
|
/* Operation: Remove DTD. */ |
else { |
if (oldDocType != null) { |
log(LogInterface.TYPE_INFO, "DTD "+ oldDocType + " removed."); |
/* Operation: Remove DTD. */ |
else { |
if (oldDocType != null) { |
log(LogInterface.TYPE_INFO, "DTD "+ oldDocType + " removed."); |
} |
} |
} |
} |
|
/* Catch and log transformation errors. */ |
catch (TransformerException te) { |
log(LogInterface.TYPE_ERROR, "Transformation error: " + te.getMessage()); |
/* Catch and log transformation errors. */ |
catch (TransformerException te) { |
log(LogInterface.TYPE_ERROR, "Transformation error: " + te.getMessage()); |
} |
} |
|
/* Catch and log exceptions thrown by the TransformerFactory.*/ |
catch (TransformerConfigurationException tce) { |
log(LogInterface.TYPE_ERROR, "TransformerFactory error: " + |
tce.getMessage()); |
} |
} |
|
/** |