Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [tools-dev] Plugin SAX Parser problem

Some more info on the code in question.

org.apache.xerces (4.0.13) "Xerces Based XML Parser"
java.version=1.4.2_01

eclipse platform version 2.1.1

import org.eclipse.core.resources.IFile;
import org.eclipse.debug.ui.AbstractDebugView;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

import org.xml.sax.*;

import java.io.IOException;
import org.apache.xerces.parsers.SAXParser;


public class SampleAction implements  IWorkbenchWindowActionDelegate,ErrorHandler {
	private IWorkbenchWindow window;
	private IViewPart consoleView;
	private TextViewer viewer;
	private IDocument doc ;
   private XMLReader parser;
	private boolean valid = true;
    String document;
	String errorMsg;
	/**
	 * The constructor.
	 */

    public boolean isValid() {
	   return valid;
	 }
  	 // If this handler is used to parse more than one document,
	 // its initial state needs to be reset between parses.
	 public void reset() {
	   // Assume document is valid until proven otherwise
	   valid = true;
	 }

	 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/xhtml C:\\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 name="xmlParserAPIs.jar"/>
      <library name="xercesImpl.jar"/>
      </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>

-----Original Message-----
From: tools-dev-admin@xxxxxxxxxxx [mailto:tools-dev-admin@xxxxxxxxxxx]On
Behalf Of Kanabar, Sarika
Sent: Wednesday, December 10, 2003 11:30 AM
To: tools-dev@xxxxxxxxxxx
Subject: [tools-dev] Plugin SAX Parser problem



hi,

  My Parser is validating XHTML file against XSD. It works fine as standalone application but has a problem as plugin. Only one catch loop is getting accessed when there is any kind of error.

This is the error message on console

java.lang.NullPointerException
	at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1133)
	at validate.actions.SampleAction.run(SampleAction.java:121)
	at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
	at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:207)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:456)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent(ActionContributionItem.java:403)
	at org.eclipse.jface.action.ActionContributionItem.access$0(ActionContributionItem.java:397)
	at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent(ActionContributionItem.java:72)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:847)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2188)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1878)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1402)
	at org.eclipse.ui.internal.Workbench.run(Workbench.java:1385)
	at org.eclipse.core.internal.boot.InternalBootLoader.run(InternalBootLoader.java:858)
	at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:291)
	at org.eclipse.core.launcher.Main.run(Main.java:747)
	at org.eclipse.core.launcher.Main.main(Main.java:583)

Any help please?
Thanks
***********************************************************************************
Information contained in this email message is intended only for use of the
individual or entity named above. If the reader of this message is not the
intended recipient, or the employee or agent responsible to deliver it to
the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please immediately notify the
postmaster@xxxxxxxxxx and destroy the original message.
**************************************************************************************
_______________________________________________
tools-dev mailing list
tools-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/tools-dev
***********************************************************************************
Information contained in this email message is intended only for use of the
individual or entity named above. If the reader of this message is not the
intended recipient, or the employee or agent responsible to deliver it to
the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please immediately notify the
postmaster@xxxxxxxxxx and destroy the original message.
**************************************************************************************


Back to the top