Package ee.widespace.xmlhandler

Source Code of ee.widespace.xmlhandler.AdminHandler

package ee.widespace.xmlhandler;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import ee.widespace.forum.Admin;



/**
* @author: Igor Malinin
*/
public class AdminHandler extends DefaultHandler {
  private static final SAXParserFactory
    factory = SAXParserFactory.newInstance();


  private List root;
/**
*/
protected AdminHandler() {}


public void endDocument() throws SAXException {
}
public void endElement( String uri, String localName, String qName )
throws SAXException {
}
/**
*/
public static List parse( String uri ) throws SAXException,IOException {
  try {
    SAXParser parser = factory.newSAXParser();


    AdminHandler handler = new AdminHandler();
    parser.parse( uri, handler );


    return handler.root;
  } catch ( ParserConfigurationException e ) {
    throw new IllegalStateException(
      "XML parser configuration error: " + e.getMessage() );
  }
}


public void startDocument() throws SAXException {
}
public void startElement( String uri, String localName, String qName, Attributes attrs )
throws SAXException {
  if ( qName.equals("UserList") ) {
    root = new LinkedList();
  } else   if ( qName.equals("User") ) {
    Admin adm = new Admin();
    adm.name = attrs.getValue("name");
    adm.password = attrs.getValue("password");
    root.add(adm);
  }
}
}
TOP

Related Classes of ee.widespace.xmlhandler.AdminHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.