[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[pde-dev] Parser problem when using it as plugin
|
Hi,
I am trying to validate a XML file using SAX parser. The program works
fine when it is a standalone application. But when I convert it to a plugin,
The catch block for SAXParseException is not getting called, which it should
be otherwise. Any one has any idea what could the problem be ?
I am using the following versions
org.apache.xerces (4.0.13) "Xerces Based XML Parser"
java.version=1.4.2_01
eclipse platform version 2.1.1
And the java code snippet along with plugin.xml is as follows :
public void warning(final SAXParseException exception)
{
errorMsg = "Warning: " + exception.getMessage();
errorMsg += " at line " + exception.getLineNumber()
+ ", column " + exception.getColumnNumber();
doc.set(errorMsg);
viewer.setDocument(doc);
// Well-formedness is a prerequisite for validity
valid = false;
}
public void error(final SAXParseException exception)
{ errorMsg = "Error: " + exception.getMessage();
errorMsg += " at line " + exception.getLineNumber()
+ ", column " + exception.getColumnNumber();
doc.set(errorMsg);
viewer.setDocument(doc);
valid = false;
}
public void fatalError(final SAXParseException exception)
{
errorMsg = "Fatal Error: " + exception.getMessage();
errorMsg += " at line " + exception.getLineNumber()
+ ", column " + exception.getColumnNumber();
doc.set(errorMsg);
viewer.setDocument(doc);
}
/**
* The action has been activated. The argument of the
* method represents the 'real' action sitting
* in the workbench UI.
* @see IWorkbenchWindowActionDelegate#run
*/
public void run(IAction action) {
try {
IFile fname =((IFileEditorInput)
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getAc
tiveEditor().getEditorInput()).getFile();
document = fname.getLocation().toString();
parser = new SAXParser();
final SampleAction handler = new SampleAction();
parser.setErrorHandler(handler);
// Turn on validation.
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema",true)
;
parser.setProperty("http://apache.org/xml/properties/schema/external-
schemaLocation","http://www.w3.org/1999/xhtmlC:\\XHTML.xsd" );
parser.parse(document);
if (handler.isValid()) {
errorMsg = document + " is valid.";
doc.set(errorMsg);
viewer.setDocument(doc);
}
else {
// If the document isn't well-formed, an exception has
// already been thrown and this has been skipped.
errorMsg = document + " is well-formed.";
doc.set(errorMsg);
viewer.setDocument(doc);
}
}//try
catch (SAXParseException err)
{
errorMsg = document + " is not well-formed at ";
errorMsg += "Line " + err.getLineNumber() + ", column " +
err.getColumnNumber();
doc.set(errorMsg);
viewer.setDocument(doc);
}
catch (IOException e)
{
errorMsg = "Due to an IOException, the parser could not check " + document;
doc.set(errorMsg);
viewer.setDocument(doc);
}
catch (SAXException e) {
e.printStackTrace();
}
}
/**
* Selection in the workbench has been changed. We
* can change the state of the 'real' action here
* if we want, but this can only happen after
* the delegate has been created.
* @see IWorkbenchWindowActionDelegate#selectionChanged
*/
public void selectionChanged(IAction action, ISelection selection) {}
/**
* We can use this method to dispose of any system
* resources we previously allocated.
* @see IWorkbenchWindowActionDelegate#dispose
*/
public void dispose() {}
/**
* We will cache window object in order to
* be able to provide parent shell for the message dialog.
* @see IWorkbenchWindowActionDelegate#init
*/
public void init(IWorkbenchWindow window) {
this.window = window;
try {
consoleView =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.debug.ui.ConsoleView");
viewer = (TextViewer)((AbstractDebugView) consoleView).getViewer();
doc = viewer.getDocument();
}
catch (PartInitException e1) {
e1.printStackTrace();
}
}
}
===============================================
Plugin.xml
<runtime>
<library name="validate.jar">
<export name="*"/>
</library>
</runtime>
<requires>
<import plugin="org.eclipse.core.resources"/>
<import plugin="org.eclipse.ui"/>
<import plugin="org.apache.xerces"/>
<import plugin="org.eclipse.debug.core"/>
<import plugin="org.eclipse.debug.ui"/>
<import plugin="org.eclipse.core.runtime"/>
<import plugin="org.eclipse.core.boot"/>
<import plugin="org.eclipse.ui.views"/>
<import plugin="org.apache.lucene"/>
<import plugin="org.eclipse.help"/>
<import plugin="org.eclipse.help.appserver"/>
<import plugin="org.eclipse.jface"/>
<import plugin="org.eclipse.jface.text"/>
<import plugin="org.eclipse.swt"/>
<import plugin="org.eclipse.text"/>
<import plugin="org.eclipse.ui.editors"/>
<import plugin="org.eclipse.ui.workbench"/>
<import plugin="org.eclipse.ui.workbench.texteditor"/>
<import plugin="org.eclipse.update.core"/>
</requires>
_________________________________________________________________
Discover India. Celebrate her diversity.
http://server1.msn.co.in/features/tourism/ Come, fall in love!