4,10 → 4,10 |
* Coded by: Group 5, software practice summer 2003 |
* University of Bielefeld, Germany |
* |
* @version $Revision: 1.60 $ |
* @version $Revision: 1.61 $ |
* |
* Last modification: $Date: 2003/07/25 14:56:04 $ |
* $Id: Parser.java,v 1.60 2003/07/25 14:56:04 smcsporr Exp $ |
* Last modification: $Date: 2003/07/26 10:27:48 $ |
* $Id: Parser.java,v 1.61 2003/07/26 10:27:48 smcsporr Exp $ |
*/ |
|
package src.parser; |
25,10 → 25,6 |
import javax.xml.parsers.FactoryConfigurationError; |
import javax.xml.parsers.ParserConfigurationException; |
|
import javax.xml.transform.Transformer; |
import javax.xml.transform.TransformerConfigurationException; |
import javax.xml.transform.TransformerFactory; |
|
import org.apache.xerces.impl.xs.psvi.XSConstants; |
import org.apache.xerces.impl.xs.psvi.XSNamedMap; |
import org.apache.xerces.impl.xs.psvi.XSModel; |
64,7 → 60,7 |
* |
* @author Group 5 |
* |
* @version $Revision: 1.60 $ Last modification: $Date: 2003/07/25 14:56:04 $ |
* @version $Revision: 1.61 $ Last modification: $Date: 2003/07/26 10:27:48 $ |
*/ |
public class Parser { |
|
95,7 → 91,7 |
private GrammarErrorHandler grammarErrorHandler = new GrammarErrorHandler(); |
|
/** An XML grammar implementation representation for grammar parsing. */ |
Grammar grammar; |
private Grammar grammar; |
|
/** The main Document of this class */ |
private DocumentImpl doc; |
109,14 → 105,14 |
/** A reference to the status panel. */ |
private StatusInterface statusInterfaceReference; |
|
private Transformer myTransformer; |
private TransformerFactory transFactory; |
|
/** Create a new DocumentBuilderFactory. */ |
private DocumentBuilderFactory dBF = DocumentBuilderFactory.newInstance(); |
|
/** |
* The default class constructor creates an empty <code>Document</code> object. |
* The default class constructor initializes basic class features. |
* |
* A new empty DOM document object will be created to store parsed XML documents. |
* The grammar preparser will get an error handler assigned to. |
*/ |
public Parser() { |
|
123,20 → 119,10 |
/* Creates a new document object. */ |
doc = new DocumentImpl(); |
|
try { |
/* Create a new TransformerFactory and build a transformer. */ |
transFactory = TransformerFactory.newInstance(); |
myTransformer = transFactory.newTransformer(); |
} |
/* Catch and log creation errors. */ |
catch (TransformerConfigurationException tce) { |
|
log(LogInterface.TYPE_ERROR, "Transformer cannot be created: " + tce.getMessage()); |
} |
|
dBF.setValidating(false); |
dBF.setNamespaceAware(false); |
|
/* Register an error handler to the preparser. */ |
preParser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true); |
preParser.setErrorHandler(grammarErrorHandler); |
} |
143,7 → 129,7 |
|
|
/** |
* This constructor creates a new empty <code>Document</code> object and |
* This constructor creates a new empty DOM document object and |
* calls the method <code>parse</code> with a given file. |
* |
* @param file The file to be parsed. |
155,17 → 141,6 |
/* Creates a new document object. */ |
doc = new DocumentImpl(); |
|
try { |
/* Create a new TransformerFactory and build a transformer. */ |
transFactory = TransformerFactory.newInstance(); |
myTransformer = transFactory.newTransformer(); |
} |
/* Catch and log creation errors. */ |
catch (TransformerConfigurationException tce) { |
|
log(LogInterface.TYPE_ERROR, "Transformer cannot be created: " + tce.getMessage()); |
} |
|
dBF.setValidating(false); |
dBF.setNamespaceAware(false); |
|
182,7 → 157,6 |
public void parse(File file) { |
|
try { |
|
DocumentBuilder dB = dBF.newDocumentBuilder(); |
|
/* Check if the file exists and is readable. */ |
189,11 → 163,11 |
if (file.exists() && file.canRead()) { |
doc = (DocumentImpl)dB.parse(file); |
} else { |
log(LogInterface.TYPE_ERROR, " The file " + file.getName() + |
log(LogInterface.TYPE_ERROR, "[Parser] The file " + file.getName() + |
" is not accessable."); |
} |
|
log(LogInterface.TYPE_INFO, "File " + file.getName() + " successfully parsed"); |
log(LogInterface.TYPE_INFO, "[Parser] File " + file.getName() + " successfully parsed"); |
} |
|
/* Catch and log factory configuration errors. */ |
202,7 → 176,7 |
|
/* Show error icon and message in the status panel. */ |
setNewIcon(StatusInterface.ICON_ERROR); |
sendMessage("Parser factory error: " + factoryConfigExc.getMessage()); |
sendMessage("[Parser] Parser factory error: " + factoryConfigExc.getMessage()); |
} |
|
/* Catch and log configuration errors. */ |
210,7 → 184,7 |
|
/* Show error icon and message in the status panel. */ |
setNewIcon(StatusInterface.ICON_ERROR); |
sendMessage("Parser configuration error: " + parseConfigExc.getMessage()); |
sendMessage("[Parser] Parser configuration error: " + parseConfigExc.getMessage()); |
} |
catch (SAXException saxException) { |
// Error generated during parsing |
218,10 → 192,10 |
if (saxException.getException() != null){ |
x = saxException.getException(); |
} |
log(LogInterface.TYPE_ERROR, "Parsing error: " + x.getMessage()); |
log(LogInterface.TYPE_ERROR, "[Parser] Parsing error: " + x.getMessage()); |
} |
catch (IOException iOexc) { |
log(LogInterface.TYPE_ERROR, "I/O-error: " + iOexc.getMessage()); |
log(LogInterface.TYPE_ERROR, "[Parser] I/O-error: " + iOexc.getMessage()); |
} |
} |
|
237,7 → 211,6 |
public void parse(String inputString) { |
|
try { |
|
DocumentBuilder dB = dBF.newDocumentBuilder(); |
doc = (DocumentImpl)dB.parse(new InputSource(new StringReader(inputString))); |
} |
248,7 → 221,7 |
|
/* Show error icon and message in the status panel. */ |
setNewIcon(StatusInterface.ICON_ERROR); |
sendMessage("Parser factory error: " + factoryConfigExc.getMessage()); |
sendMessage("[Parser] Parser factory error: " + factoryConfigExc.getMessage()); |
} |
|
/* Catch and log configuration errors. */ |
256,7 → 229,7 |
|
/* Show error icon and message in the status panel. */ |
setNewIcon(StatusInterface.ICON_ERROR); |
sendMessage("Parser configuration error: " + parseConfigExc.getMessage()); |
sendMessage("[Parser] Parser configuration error: " + parseConfigExc.getMessage()); |
} |
catch (SAXException saxException) { |
|
265,10 → 238,10 |
if (saxException.getException() != null){ |
x = saxException.getException(); |
} |
log(LogInterface.TYPE_ERROR, "Parsing error: " + x.getMessage()); |
log(LogInterface.TYPE_ERROR, "[Parser] Parsing error: " + x.getMessage()); |
} |
catch (IOException iOexc) { |
log(LogInterface.TYPE_ERROR, "I/O-error: " + iOexc.getMessage()); |
log(LogInterface.TYPE_ERROR, "[Parser] I/O-error: " + iOexc.getMessage()); |
} |
} |
|
322,11 → 295,11 |
|
/* Catch and log IO-errors. */ |
catch (IOException ioe) { |
log(LogInterface.TYPE_ERROR, "I/O-error while parsing DTD file " |
log(LogInterface.TYPE_ERROR, "[Parser] I/O-error while parsing DTD file " |
+ DTDFile.getPath() + " : " + ioe.getMessage()); |
} |
} else { |
log(LogInterface.TYPE_ERROR, "The file " + DTDFile.getName() + |
log(LogInterface.TYPE_ERROR, "[Parser] The file " + DTDFile.getName() + |
" is not accessable."); |
} |
|
334,9 → 307,11 |
} |
|
/** |
* Parses an XML schema grammar and returns the top-level elements |
* that are candidates of being the root element of an instance document. |
* Parses an XML schema grammar and returns the top-level elements. |
* |
* Top level elements are candidates of being the root element of an instance |
* document. |
* |
* The file must be accessable to parse it, non-existing or non-readable |
* files will produce an error message. |
* |
396,11 → 371,11 |
|
/* Catch and log IO-errors. */ |
catch (IOException ioe) { |
log(LogInterface.TYPE_ERROR, "I/O-error while parsing schema file " |
log(LogInterface.TYPE_ERROR, "[Parser] I/O-error while parsing schema file " |
+ schemaFile.getPath() + " : " + ioe.getMessage()); |
} |
} else { |
log(LogInterface.TYPE_ERROR, "The file " + schemaFile.getName() + |
log(LogInterface.TYPE_ERROR, "[Parser] The file " + schemaFile.getName() + |
" is not accessable."); |
} |
|
410,7 → 385,7 |
/** |
* <code>getDocument</code> returns the parsed document. |
* |
* @return A DOM representation of the document. |
* @return A DOM representation of the XML document (currently level 2). |
* |
* Last revision: 14-Jun-2003 |
*/ |
442,8 → 417,12 |
* This method sets an internal reference to the status panel. |
* |
* @param stat A status panel implementation compliant to src.gui.StatusInterface. |
* |
* @see src.gui.StatusInterface |
* |
* author S. McSporran |
* |
* Last revision: 11-Jul-2003 |
* Last Revision: 11-Jul-2003 |
*/ |
public void setStatusInterface(StatusInterface stat) { |
statusInterfaceReference = stat; |
461,6 → 440,8 |
* 2 or src.gui.LogInterface.TYPE_ERROR -> error message (red) |
* |
* @param message The text message to display in the log panel. |
* |
* @see src.gui.LogInterface#log |
*/ |
private void log(int i, String message) { |
logInterfaceReference.log(i,message); |
476,13 → 457,18 |
statusInterfaceReference.setMessage(message); |
} |
|
/** |
* <code>setPoint</code> sets a new point to display in the status panel. |
* |
* @param point: A <code>Point</code> object containing the information to display. |
/** |
* Sets a new point in the status panel. |
* |
* This info is used to give a little more detail about where in the document |
* an error happened. |
* |
* @param p A <code>Point</code> object, pointing to a specific line and character |
* where an error occured. |
* |
* @see src.gui.StatusInterface#setPoint |
*/ |
private void setPoint(Point point) { |
statusInterfaceReference.setPoint(point); |
} |
|
} |