4,10 → 4,10 |
* Coded by: Group 5, software practice summer 2003 |
* University of Bielefeld, Germany |
* |
* @version $Revision: 1.61 $ |
* @version $Revision: 1.62 $ |
* |
* Last modification: $Date: 2003/07/25 11:29:01 $ |
* $Id: OurDocument.java,v 1.61 2003/07/25 11:29:01 smcsporr Exp $ |
* Last modification: $Date: 2003/07/25 12:11:52 $ |
* $Id: OurDocument.java,v 1.62 2003/07/25 12:11:52 smcsporr Exp $ |
*/ |
|
package src.document; |
43,7 → 43,7 |
* |
* @author S. McSporran |
* |
* @version $Revision: 1.61 $ Last modification: $Date: 2003/07/25 11:29:01 $ |
* @version $Revision: 1.62 $ Last modification: $Date: 2003/07/25 12:11:52 $ |
*/ |
public class OurDocument { |
|
53,6 → 53,7 |
/** Declarations of a transformer and a factory. */ |
private TransformerFactory transFactory; |
private Transformer docTransformer; |
private Transformer trans; |
|
/** A reference variable to the log panel used to print out log messages. */ |
private LogInterface LogInterfaceReference; |
209,7 → 210,12 |
* Last revision: 17-Jul-2003 |
*/ |
public void setDomDoc(DocumentImpl document) { |
myDocument = document; |
try{ |
myDocument = (DocumentImpl)document.clone(); |
}catch (Exception e){ |
LogInterfaceReference.log(LogInterface.TYPE_ERROR,e.getMessage()); |
} |
|
} |
|
/** |
251,23 → 257,29 |
* Last revision: 19-Jul-2003 by S. McSporran |
*/ |
public void changeSchemaGrammar(DocumentImpl changeDoc, File schemaFile) { |
if((schemaFile == null)&&(changeDoc.getDocumentElement().hasAttribute("xsi:schemaLocation"))){ |
Element rootElement = changeDoc.getDocumentElement(); |
rootElement.removeAttribute("xsi:schemaLocation"); |
myDocument = changeDoc; |
log(LogInterface.TYPE_INFO, "Schema removed"); |
}else{ |
/* Get the root element. */ |
Element rootElement = changeDoc.getDocumentElement(); |
|
/* Get the root element. */ |
Element rootElement = changeDoc.getDocumentElement(); |
|
if (rootElement.hasAttribute("xsi:schemaLocation")) { |
if (rootElement.hasAttribute("xsi:schemaLocation")) { |
|
System.out.println(rootElement.getAttributeNode("xsi:schemaLocation").getName()); |
System.out.println(rootElement.getAttributeNode("xsi:schemaLocation").getOwnerElement()); |
System.out.println(rootElement.getAttributeNode("xsi:schemaLocation").getValue()); |
System.out.println(rootElement.getAttributeNode("xsi:schemaLocation").getName()); |
System.out.println(rootElement.getAttributeNode("xsi:schemaLocation").getOwnerElement()); |
System.out.println(rootElement.getAttributeNode("xsi:schemaLocation").getValue()); |
|
/* Set a new schemaLocation attribute on the document element. */ |
rootElement.setAttribute("xsi:schemaLocation", "http://www.techfak.uni-bielefeld.de/CVSchema/sopra" + |
" " + schemaFile.getName()); |
/* Set a new schemaLocation attribute on the document element. */ |
rootElement.setAttribute("xsi:schemaLocation", "http://www.techfak.uni-bielefeld.de/CVSchema/sopra" + |
" " + schemaFile.getName()); |
|
myDocument = changeDoc; |
myDocument = changeDoc; |
|
log(LogInterface.TYPE_INFO, "Schema changed to: " + schemaFile.getName()); |
log(LogInterface.TYPE_INFO, "Schema changed to: " + schemaFile.getName()); |
} |
} |
} |
|
287,7 → 299,28 |
* Last revision: 18-Jul-2003 |
*/ |
public void changeDTDGrammar(DocumentImpl changeDoc, File dtdFile) { |
if(dtdFile == null){ |
File transfer = new File("www"); |
/* Set the document parameter as input source for the transformer. */ |
DOMSource dSource = new DOMSource(changeDoc); |
|
/* Set the resulting stream to the file. */ |
StreamResult strResult = new StreamResult(transfer); |
|
try{ |
trans.setOutputProperty(OutputKeys.STANDALONE, null); |
trans.transform(dSource,strResult); |
Parser parser = new Parser(); |
parser.setLogInterface(LogInterfaceReference); |
parser.parse(transfer); |
setDomDoc(parser.getDocument()); |
} |
catch (Exception e){ |
log(LogInterface.TYPE_ERROR,"Transformer Error: "+e.getMessage()); |
log(LogInterface.TYPE_INFO, "DTD is "+(myDocument.getDoctype())); |
log(LogInterface.TYPE_INFO, "DTD removed"); |
} |
}else{ |
/* Set the document as source and the temporary file as target for the transformation. */ |
DOMSource dSource = new DOMSource(changeDoc); |
|
297,11 → 330,18 |
StreamResult sResult = new StreamResult(outputWr); |
|
/* Process an identity transform with the parameter DTD file. */ |
String docTypeFile = dtdFile.getPath(); |
if (dtdFile != null){ |
String docTypeFile = dtdFile.getPath(); |
/* Set the 'DOCTYPE' entry in the XML file. */ |
docTransformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dtdFile.getPath()); |
}else{ |
String docTypeFile = null; |
/* Set the 'DOCTYPE' entry in the XML file. */ |
docTransformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, null); |
} |
|
|
|
/* Set the 'DOCTYPE' entry in the XML file. */ |
docTransformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dtdFile.getPath()); |
|
try { |
|
docTransformer.transform(dSource,sResult); |
320,6 → 360,7 |
catch (TransformerException te) { |
log (LogInterface.TYPE_ERROR, "Transformation error: " + te.getMessage()); |
} |
} |
} |
|
/** |