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/24 14:20:05 $ |
* $Id: Parser.java,v 1.54 2003/07/24 14:20:05 smcsporr Exp $ |
* Last modification: $Date: 2003/07/24 14:30:56 $ |
* $Id: Parser.java,v 1.55 2003/07/24 14:30:56 smcsporr Exp $ |
*/ |
|
package src.parser; |
35,8 → 35,8 |
import org.apache.xerces.impl.Constants; |
import org.apache.xerces.parsers.DOMParser; |
import org.apache.xerces.parsers.XMLGrammarPreparser; |
import org.apache.xerces.util.SymbolTable; |
import org.apache.xerces.xni.grammars.XSGrammar; |
import org.apache.xerces.xni.grammars.XMLDTDDescription; |
import org.apache.xerces.xni.grammars.XMLGrammarDescription; |
import org.apache.xerces.xni.parser.XMLInputSource; |
|
47,10 → 47,13 |
import src.gui.StatusInterface; |
|
/** |
* <b><code>Parser</code></b>class instances are XML file and XML schema parsers. |
* An XML data file will be parsed in a DOM representation, a schema grammar |
* in an <code>XSModel</code> schema grammar model. |
* A <b><code>Parser</code></b>class instance is an XML file or string parser. |
* An XML data file will be parsed in a DOM representation. |
* |
* As second function, it can be used to parse an XML schema grammar to retrieve |
* the possible top level elements, that are candidates of being the root |
* element of an instance document of that schema. |
* |
* The <code>AdapterDomToTreeModel</code> needs such a document. |
* |
* @see <code>AdapterDomToTreeModel</code> |
57,53 → 60,47 |
* |
* @author Group 5 |
* |
* @version $Revision: 1.54 $ Last modification: $Date: 2003/07/24 14:20:05 $ |
* @version $Revision: 1.55 $ Last modification: $Date: 2003/07/24 14:30:56 $ |
*/ |
public class Parser { |
|
/* XNI property identifier for symbol table. */ |
/** Xerces XNI property identifier for symbol table. */ |
private static final String SYMBOL_TABLE = |
Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; |
|
/* XNI property identifier for grammar pool. */ |
/** Xerces XNI property identifier for grammar pool. */ |
private static final String GRAMMAR_POOL = |
Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; |
|
/* Feature ID for namespace processing. */ |
/** Xerces feature ID for namespace processing. */ |
private static final String NAMESPACE_FEAT_ID = |
"http://xml.org/sax/features/namespaces"; |
|
/* Feature ID for validation. */ |
/** Xerces feature ID for validation. */ |
private static final String VALIDATION_FEAT_ID = |
"http://xml.org/sax/features/validation"; |
|
/* Feature ID for XML validation against schemas. */ |
/** Xerces feature ID for XML validation against schemas. */ |
private static final String VALIDATION_SCHEMA_FEAT_ID = |
"http://apache.org/xml/features/validation/schema"; |
|
/* Feature ID for schema full checking. */ |
/** Xerces feature ID for schema full checking. */ |
private static final String SCHEMA_CHECKING_FEAT_ID = |
"http://apache.org/xml/features/validation/schema-full-checking"; |
|
/* A SymbolTable guarantees unique identifiers. */ |
private SymbolTable symbolTable = new SymbolTable(); |
|
/* Used to parse a DTD or schema grammar. */ |
/** Used to parse a DTD or schema grammar. */ |
private XMLGrammarPreparser preParser = new XMLGrammarPreparser(); |
|
/* An XML schema grammar used for grammar parsing. */ |
private XSGrammar schemaGrammar; |
|
/* The main Document of this class */ |
/** The main Document of this class */ |
private DocumentImpl doc; |
|
/* A DOM parser. */ |
/** A DOM parser. */ |
private DOMParser dParser = new DOMParser(); |
|
/* A reference to the log panel. */ |
/** A reference to the log panel. */ |
private LogInterface logInterfaceReference; |
|
/* A reference to the status panel. */ |
/** A reference to the status panel. */ |
private StatusInterface statusInterfaceReference; |
|
private Transformer myTransformer; |
271,7 → 268,49 |
} |
} |
|
/** |
* Parses a DTD grammar and returns the root element of an instance document. |
* |
* @param DTDFile The DTD grammar file to be parsed. |
* |
* @return A <code>Vector</code> containing the name of the root element. |
* |
* @see java.util.Vector |
* |
* Last revision: 24-Jul-2003 by S. McSporran |
*/ |
public String parseDTDGrammar(File DTDFile) { |
|
XMLDTDDescription grammarDescription; |
|
/* A string used to store the root element retrieved from the DTD. */ |
String root = null; |
|
/* Set the grammar type to DTD. */ |
preParser.registerPreparser(XMLGrammarDescription.XML_DTD, null); |
|
/* Set the required parser features. */ |
preParser.setFeature(NAMESPACE_FEAT_ID, true); |
preParser.setFeature(VALIDATION_FEAT_ID, true); |
|
try { |
|
/* Parse the specified DTD file and cast the grammar's description to an |
* XMLDTDDescription object. */ |
grammarDescription = (XMLDTDDescription) (preParser.preparseGrammar(XMLGrammarDescription.XML_DTD, |
new XMLInputSource(null, DTDFile.getPath(), null)).getGrammarDescription()); |
|
/* Get the root name. */ |
root = grammarDescription.getRootName(); |
} |
catch (IOException ioe) { |
log(LogInterface.TYPE_ERROR, "I/O-error while parsing DTD file " |
+ DTDFile.getPath() + " : " + ioe.getMessage()); |
} |
|
return root; |
} |
|
/** |
* Parses an XML schema grammar and returns the top-level elements |
* that are candidates of being the root element of an instance document. |
287,6 → 326,9 |
*/ |
public Vector parseSchemaGrammar(File schemaFile) { |
|
/** An XML schema grammar used for grammar parsing. */ |
XSGrammar schemaGrammar; |
|
/* A Vector used to store the names of the schema's top level elements. */ |
Vector elementNames = new Vector(); |
|