- See Also:
- Top Examples, Source Code
void addEventListener(String type,
EventListener listener,
boolean useCapture)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[1595]An utility can be attached to any DOM tree and output stream
By Anonymous on 2005/11/04 20:23:08 Rate
import java.io.*;
import java.util.Date;
import org.w3c.dom.*;
import org.w3c.dom.events.*;
public class SampleEventListener
implements EventListener
{
public SampleEventListener ( EventTarget root, OutputStream out )
{
root.addEventListener ( "DOMNodeInserted", this, true ) ;
root.addEventListener ( "DOMNodeRemoved", this, true ) ;
root.addEventListener ( "DOMAttrModified", this, true ) ;
this.out = new PrintWriter ( out ) ;
}
public void handleEvent ( Event ev )
{
out.print ( new Date ( ev.getTimeStamp ( ) ) .toString ( ) ) ;
out.print ( ": " ) ;
out.print ( ev.getType ( ) ) ;
out.print ( " -- " ) ;
Node target = ( Node ) ev.getTarget ( ) ;
out.print ( target.getNodeName ( ) ) ;
if ( target.getNodeType ( ) == Node.ELEMENT_NODE )
{
if ( target.getFirstChild ( ) instanceof Text )
{
out.print ( " ( " ) ;
out.print ( ( ( Text ) target.getFirstChild ( ) ) .getData ( ) ) ;
out.print ( " ) " ) ;
}
}
else
{
out.print ( " ( " ) ;
out.print ( target.getNodeValue ( ) ) ;
out.print ( " ) " ) ;
}
if ( ev.getType ( ) .equals ( "DOMAttrModified" ) )
{
out.print ( ' ' ) ;
Attr attr = ( Attr ) ( ( MutationEvent ) ev ) .getRelatedNode ( ) ;
out.print ( attr.getName ( ) ) ;
out.print ( '=' ) ;
out.print ( attr.getValue ( ) ) ;
}
out.println ( ) ;
out.flush ( ) ;
}
PrintWriter out;
}
boolean dispatchEvent(Event evt)
throws EventException
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
void removeEventListener(String type,
EventListener listener,
boolean useCapture)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples