?? requesthandler.java
字號:
package sax;
import java.io.*;
import java.net.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
/**
* This class extends <tt>HandlerBase</tt> and is used to handle events
* created as an XML document is parsed by a SAX compliant
* parser.
*
* @author Copyright (c) 2002 by BEA Systems, Inc. All Rights Reserved.
*/
public class RequestHandler extends DefaultHandler {
/** Default constructor. */
public RequestHandler() {}
//==========================================================================
// DocumentHandler methods
//==========================================================================
// Amount to indent
private int indentLevel = 0;
/**
* Receives notification of the beginning of the XML document.
* Starts printing information to the shell from which you started the
* WebLogic server.
*
* @exception SAXException If an error occurred starting to parse the XML doc
*/
public void startDocument() throws SAXException {
System.out.println("\nSTART DOCUMENT\n");
System.out.println("<?xml version='1.0' encoding='UTF-8'?>");
}
/**
* Receives notification of the end of the XML document. Prints a
* final message to the shell from which you started the WebLogic server.
*
* @exception SAXException If an error occurred while parsing the XML doc
*/
public void endDocument() throws SAXException {
try {
System.out.println("\nEND DOCUMENT");
} catch (Exception e) {
throw new SAXException ("I/O error", e);
}
}
/**
* Receives notification of the start of an element. Prints out the
* name and value of the element, properly indented, to the shell from
* which you started the WebLogic server.
*
* @param name the string name of the element
* @param attrs the list of attributes of the element
* @exception SAXException if an error occurred while parsing the XML doc
*/
public void startElement(String name, Attributes attrs) throws SAXException {
System.out.println("in startElement()");
//indentLevel++;
System.out.println("ELEMENT: " +name);
if (attrs != null) {
for (int i = 0; i < attrs.getLength (); i++) {
System.out.println(" ATTR: " +attrs.getLocalName(i) + " = " + attrs.getValue(i));
}
}
System.out.println("end startElement()");
}
/**
* Receives notification of the end of an element. Prints
* notice to the shell from which you started the WebLogic server.
*
* @param name the string name of the element
* @exception SAXException If an error occurred while parsing the XML doc
*/
public void endElement(String name) throws SAXException {
System.out.println ("END_ELM: " + name);
//indentLevel--;
}
/**
* Receives notification of character data inside an element. Prints out
* characters to the shell from which you started the WebLogic server.
*
* @param buf array of characters
* @param offset the start position in the character array
* @param len the number of characters to use from the array
* @exception SAXException if an error occurred while parsing the XML doc
*/
public void characters (char buf [], int offset, int len) throws SAXException {
//nl();
String s = new String(buf, offset, len);
if (!s.trim().equals("")) System.out.println ("CHARS: " + s);
}
//=============================================================
// ErrorHandler methods
//=============================================================
/**
* Receives notification of a recoverable parser error.
*
* @param x the parser exception that occurred
* @exception SAXException if an error occurred while receiving the original error
*/
public void error (SAXParseException x) throws SAXException {
throw x;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -