⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlfiledochandler.java

📁 一款即时通讯软件
💻 JAVA
字号:
/*
 *   License
 *
 * The contents of this file are subject to the Jabber Open Source License
 * Version 1.0 (the "License").  You may not copy or use this file, in either
 * source code or executable form, except in compliance with the License.  You
 * may obtain a copy of the License at http://www.jabber.com/license/ or at
 * http://www.opensource.org/.  
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 *   Copyrights
 *
 * Portions created by or assigned to Jabber.com, Inc. are 
 * Copyright (c) 2000 Jabber.com, Inc.  All Rights Reserved.  Contact
 * information for Jabber.com, Inc. is available at http://www.jabber.com/.
 *
 * Portions Copyright (c) 1999-2000 David Waite 
 *
 *   Acknowledgements
 * 
 * Special thanks to the Jabber Open Source Contributors for their
 * suggestions and support of Jabber.
 * 
 *   Changes
 *   
 * @author  David Waite <a href="mailto:dwaite@jabber.com">
 *                      <i>&lt;dwaite@jabber.com&gt;</i></a>
 * @author  $Author: chris $
 * @version $Revision: 1.1 $ 
 *
 * j.komzak
 * Changed to work with files.
 */

package edu.ou.kmi.buddyspace.xml;

/*
 * XMLFileDocHandler.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2002
 *
 *
 * Created on 28 August 2002, 10:50
 */

import org.xml.sax.*;

import org.jabber.jabberbeans.*;
import org.jabber.jabberbeans.sax.*;
import org.jabber.jabberbeans.Packet;
import org.jabber.jabberbeans.ConnectionBean;

import java.io.IOException;
import java.io.FileNotFoundException;

/**
 * Main file handler given to a SAX-enabled parser.
 * 
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */
public class XMLFileDocHandler extends SubHandler {
    /** instantiating handler, used for sending messages back up
     * the pipe. */
    protected XMLFileDocInterface isi;

    /**
     * Creates a new <code>XMLFileDocHandler</code> instance.
     */
    public XMLFileDocHandler()
    {
	super();
	try
	{
	    setHandlerFactory(new HandlerFactory());
	}
	catch (IOException e)
	{
	    throw new RuntimeException
		("error with extension factory");
        }
    }

    /**
     * set the XMLFileDocInterface, used to inform client code of new 
     * received data.
     *
     * @param isi XMLFileDocInterface
     */
    public final void setDataHandler(XMLFileDocInterface isi)
    { this.isi = isi; }

    /**
     * handle the start of an element, including finding an appropriate
     * handler for the element or namespace type
     *
     * @param name element name
     * @param attributes element attributes
     * @throws SAXException unknown root element, or XML parsing error
     */
    public void handleStartElement(String name, 
				   AttributeList attributes)
	throws SAXException
    {
	SubHandler subhandler=getHandlerFactory().
	    getHandlerInstance(name,attributes);

	if (subhandler==null)
	    throw new SAXException("Unknown/invalid root element: " + name);
	setChildSubHandler(subhandler,name,attributes);
    }

    /**
     * <code>handleEndElement</code> method
     *
     * @param name a <code>String</code> value
     * @exception SAXException if an error occurs
     */
    public final void handleEndElement(String name) 
	throws SAXException
    { }

    /**
     * <code>receiveChildData</code> receives packets constructed by the
     * subordinate handlers, and shuttles it to the protocol handler
     *
     * @param subHandler a <code>SubHandler</code> value of the handler the
     * data came from, unused
     * @param p an <code>Object</code> value, a Packet
     * @throws SAXException if the data is invalid (i.e. null)
     */
    public void receiveChildData(SubHandler subHandler,Object p)
	throws SAXException
    {
	if (p==null)
	    throw new SAXException("null data returned from child");

	isi.received((XMLData)p);
    }

    /**
     * <code>stopHandler</code> returns null since there is no 'data'
     * returned which was not already sent via the 'receive' method.
     *
     * @return an <code>Object</code> value, unused.
     * @exception SAXException if an error occurs
     */
    public final Object stopHandler(String name)
	throws SAXException
    {return null;}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -