Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 830 → Rev 831

/sun/xmleditor/trunk/src/document/OurDocument.java
4,10 → 4,10
* Coded by: Group 5, software practice summer 2003
* University of Bielefeld, Germany
*
* @version $Revision: 1.62 $
* @version $Revision: 1.63 $
*
* Last modification: $Date: 2003/07/25 12:11:52 $
* $Id: OurDocument.java,v 1.62 2003/07/25 12:11:52 smcsporr Exp $
* Last modification: $Date: 2003/07/25 17:14:32 $
* $Id: OurDocument.java,v 1.63 2003/07/25 17:14:32 hjokusch Exp $
*/
package src.document;
43,7 → 43,7
*
* @author S. McSporran
*
* @version $Revision: 1.62 $ Last modification: $Date: 2003/07/25 12:11:52 $
* @version $Revision: 1.63 $ Last modification: $Date: 2003/07/25 17:14:32 $
*/
public class OurDocument {
247,46 → 247,62
/**
* The method <code>changeSchemaGrammar</code> changes a document's schema grammar.
*
* @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.
* It parses the XML schema file and retrieves it's 'targetNamespace' attribute
* first to get the schema locations namespace. If no target namespace is
* specified, the default namespace declared in the XML document will be used.
*
* @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: 19-Jul-2003 by S. McSporran
* Last revision: 25-Jul-2003 by S. McSporran
*/
public void changeSchemaGrammar(DocumentImpl changeDoc, File schemaFile) {
if((schemaFile == null)&&(changeDoc.getDocumentElement().hasAttribute("xsi:schemaLocation"))){
 
/* Create an empty DOM document used as data container. */
DocumentImpl tempDocument = new DocumentImpl();
String namespaceTarget = "";
 
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();
} else {
/* Get the root element of the XML file. */
Element XMLRootElement = changeDoc.getDocumentElement();
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());
/* Parse the XML schema file and retrieve it's root element. */
aParser.parse(schemaFile);
tempDocument = aParser.getDocument();
Element schemaRootElement = tempDocument.getDocumentElement();
/* Try to get the 'targetNamespace' attribute. */
String targetNamespaceAttribute = schemaRootElement.getAttribute("targetNamespace");
if (! targetNamespaceAttribute.equals("")) {
/* 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;
log(LogInterface.TYPE_INFO, "Schema changed to: " + schemaFile.getName());
XMLRootElement.setAttribute("xsi:schemaLocation", targetNamespaceAttribute + " " +
schemaFile.getPath());
} else {
}
}
myDocument = changeDoc;
log(LogInterface.TYPE_INFO, "Schema changed to: " + schemaFile.getName());
}
/**
* The method <code>changeDTDGrammar</code> changes a document's DTD.
*
* A DOCTYPE-entry will be inserted or replaced containing a SYSTEM-entry
* 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.
296,71 → 312,62
*
* author S. McSporran
*
* Last revision: 18-Jul-2003
* Last revision: 26-Jul-2003 by S. McSporran
*/
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);
/* Set the document parameter as source for the transformation. */
DOMSource dSource = new DOMSource(changeDoc);
 
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);
/* Save the transformation result to a string buffer. */
StringWriter strWriter = new StringWriter();
PrintWriter outputWr = new PrintWriter(strWriter);
StreamResult sResult = new StreamResult(outputWr);
 
if (dtdFile == null){
/* Process an identity transform with the parameter DTD file. */
if (dtdFile != null){
try {
/* Transform the document, delete any DOCTYPE entry. */
trans.setOutputProperty(OutputKeys.STANDALONE, null);
trans.transform(dSource,sResult);
/* Get the buffer associated with the StringWriter outputWr. */
String bufferString = strWriter.getBuffer().toString();
aParser.parse(bufferString);
myDocument = aParser.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 {
/* Process an identity transform with the parameter DTD file. */
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);
}
try {
docTransformer.transform(dSource,sResult);
try {
docTransformer.transform(dSource,sResult);
 
/* Get the buffer associated with the StringWriter outputWr. */
String bufferString = strWriter.getBuffer().toString();
/* 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();
/* 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());
}
log(LogInterface.TYPE_INFO, "DTD changed to: " + myDocument.getDoctype().getSystemId());
}
/* 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());
}
}
}
}
/**