Class myoPyx

java.lang.Object
  |
  +--myoPyx

public class myoPyx
extends java.lang.Object

myoPyx

A PYX document parser.

Still to do:


Inner Class Summary
static interface myoPyx.Listener
          Implement this to create an object that can listen to myoPyx events.
 
Constructor Summary
myoPyx()
           
 
Method Summary
 void addListener(java.lang.String tag_name, myoPyx.Listener listener)
          Add a listener for parsing events.
 void addPIListener(java.util.Observer listener)
          Attaches a listener of processing instruction (PI) events.
 void parse(java.io.Reader s)
          Parses a Reader stream, generating events that are sent to myoPyx.Listeners that are added with addListener() or addPIListener().
 void removeListener(java.lang.String tag_name, java.lang.Object listener)
          Removes a listener.
 void removePIListener(java.lang.Object listener)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

myoPyx

public myoPyx()
Method Detail

parse

public void parse(java.io.Reader s)
           throws java.io.IOException,
                  java.lang.Exception
Parses a Reader stream, generating events that are sent to myoPyx.Listeners that are added with addListener() or addPIListener().

myoPyx p = new myoPyx();
 p.addListener( my_listener );
 try {
   InputStreamReader input = new InputStreamReader(
     new FileInputStream( "my.pyx" );
   p.parse( input );
 } catch (Exception e) {
   e.printStackTrace();
 }
Throws:
java.io.IOException - if there is a problem reading from the reader
java.lang.Exception - if there is a parsing exception, such as bad markup or bad document formatting. The error message will contnain the line number where the error occurred.

addListener

public void addListener(java.lang.String tag_name,
                        myoPyx.Listener listener)
Add a listener for parsing events.
myoPyx.Listener my_listener = new myoPyx.Listener() {
   public void startElement( String name, HashMap attrs ) {
     System.out.println("MyTag has attributes:");
     for (Iterator i=attrs.keys(); i.hasNext(); ) {
       Object key = i.next();
       System.out.println("\t"+key.toString()+" -> "+
         attrs.get(key).toString());
     }
   }
   public void endElement( String name ) { }
   public void text( String content ) { }
 };
 myoPyx.Listener all = new myoPyx.Listener() {
   public void startElement( String name, HashMap attrs ) {
     System.out.println("Got tag "+name);
   }
   public void endElement( String name ) { }
   public void text( String content ) { }
 };
 pyx.addListener( null, all );
 pyx.addListener( "MyTag", my_listener );
Listeners for all events will be notified before listeners of specific events. After this, Listeners are notified in the order they are added.
Parameters:
tag_name - if null, the listener will be notified of all events. If not null, the listener will be notified of only events pertaining to elements matching the tag_name.

addPIListener

public void addPIListener(java.util.Observer listener)
Attaches a listener of processing instruction (PI) events. Uses the Observer intefrace; The first argument (Observable) passed to Observer.notify will always be null; the second (Object) will be the contents of the processing instruction, in raw String form.

removePIListener

public void removePIListener(java.lang.Object listener)

removeListener

public void removeListener(java.lang.String tag_name,
                           java.lang.Object listener)
Removes a listener. The tag must match the tag under which the Listener was added; for example, if a listener is added as both a "MyTag1" and "MyTag2", then removeListener(null, listener) will do nothing, and removeListener("MyTag1", listener) will only remove the listener for events on "MyTag1", not "MyTag2".