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

📄 xmlinfohandler.java

📁 Jive 是一个系统工程
💻 JAVA
字号:
/* *  XMLInfoHandler.java *  11/05/00 *  CoolServlets.com */package com.coolservlets.forum.xml;import java.text.*;import java.util.*;import org.xml.sax.*;import org.xml.sax.helpers.*;public class XMLInfoHandler implements ContentHandler, ErrorHandler {    private static SimpleDateFormat formatter =		new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SS z");    private Locator locator;    private XMLInfo xmlinfo;    private boolean inJiveBlock = false;    private boolean inPropertyListBlock = false;    private boolean inUserListBlock = false;    private boolean inUserBlock = false;    private boolean inUsernameBlock = false;    private boolean inForumListBlock = false;    private boolean inForumBlock = false;    private boolean inForumnameBlock = false;    private boolean inFilterBlock = false;    public XMLInfoHandler( XMLInfo xmlinfo ) {        this.xmlinfo = xmlinfo;    }    public void setDocumentLocator(Locator locator) {        this.locator = locator;    }    public void startDocument() throws SAXException {        System.err.println( "Starting parse ..." );    }    public void endDocument() throws SAXException {        System.err.println( "... parse done." );    }    public void processingInstruction(String target, String data)            throws SAXException    {    }    public void startPrefixMapping(String prefix, String uri) {    }    public void endPrefixMapping(String prefix) {    }    public void startElement(String namespaceURI, String localName,                             String rawName, Attributes atts)            throws SAXException    {        if( inJiveBlock && localName.equals("PropertyList") ) {            inPropertyListBlock = true;        }        else if( inPropertyListBlock && localName.equals("Property") ) {            // get all attributes of this property, store in xmlinfo object            int length = atts.getLength();            String propName = null;            String propValue = null;            for( int i=0; i<length; i++ ) {                String attName = atts.getLocalName(i);                String value = null;                if( attName.equalsIgnoreCase("name") ) {                    propName = atts.getValue(i);                }                else if( attName.equalsIgnoreCase("value") ) {                    propValue = atts.getValue(i);                }            }            if( propName != null ) {                xmlinfo.addProperty(propName,propValue);            }        }        else if( inJiveBlock && localName.equals("UserList") ) {            inUserListBlock = true;            inJiveBlock = false;        }        else if( inUserListBlock && localName.equals("User") ) {            inUserBlock = true;        }        else if( inUserBlock && localName.equals("Username") ) {            inUsernameBlock = true;        }        else if( inJiveBlock && localName.equalsIgnoreCase("ForumList") ) {            inForumListBlock = true;            inJiveBlock = false;        }        else if( inForumListBlock && localName.equals("Forum") ) {            inForumBlock = true;        }        else if( inForumBlock && localName.equals("Filter") ) {            inFilterBlock = true;        }        else if( inForumBlock && !inFilterBlock && inForumListBlock && localName.equals("Name") ) {            inForumnameBlock = true;        }        else if( localName.equals("GroupList")                 || localName.equals("UserPermissionList")                 || localName.equals("GroupPermissionList") )        {            inJiveBlock = false;        }        // Get the Jive XML version        else if( localName.equals("Jive") ) {            inJiveBlock = true;            String version = "";            String exportDate = "";            int length = atts.getLength();            for( int i=0; i<length; i++ ) {                if( atts.getLocalName(i).equals("version") ) {                    version = atts.getValue(i);                }                else if( atts.getLocalName(i).equals("exportDate") ) {                    exportDate = atts.getValue(i);                }            }            xmlinfo.setJiveXMLVersion( version );            // parse the date            try {                Date date = formatter.parse(exportDate);                xmlinfo.setExportDate(date);            } catch( ParseException e ) {                xmlinfo.setExportDate( new Date() );            }        }    }    public void endElement(String namespaceURI, String localName, String rawName)            throws SAXException    {        if( inPropertyListBlock && !(inUserListBlock||inUserBlock||inUsernameBlock||inForumListBlock||inForumBlock||inForumnameBlock) && localName.equals("PropertyList") ) {            inPropertyListBlock = false;        }        else if( (inUserListBlock||inJiveBlock) && localName.equals("UserList") ) {            inUserListBlock = false;            inJiveBlock = true;        }        else if( inUserBlock && !(inForumListBlock||inForumBlock) && localName.equals("User") ) {            inUserBlock = false;        }        else if( inUsernameBlock && !(inForumListBlock||inForumBlock||inForumnameBlock) && localName.equals("Username") ) {            inUsernameBlock = false;        }        else if( (inForumListBlock||!inJiveBlock) && !(inUserListBlock||inUserBlock||inUsernameBlock) && localName.equals("ForumList") ) {            inForumListBlock = false;            inJiveBlock = true;        }        else if( inForumBlock && localName.equals("Forum") ) {            inForumBlock = false;        }        else if( inFilterBlock && localName.equals("Filter") ) {            inFilterBlock = false;        }        else if( inForumnameBlock && localName.equals("Name") ) {            inForumnameBlock = false;        }        else if( inJiveBlock && localName.equals("Jive") ) {            inJiveBlock = false;        }        else if( !inJiveBlock &&                 (localName.equals("GroupList")                 || localName.equals("UserPermissionList")                 || localName.equals("GroupPermissionList")))        {            inJiveBlock = true;        }    }    public void characters(char[] ch, int start, int end)            throws SAXException    {        if( inUsernameBlock ) {            String username = new String( ch, start, end );            xmlinfo.addUsername(username);        }        else if( inForumnameBlock && !inFilterBlock ) {            String forumname = new String( ch, start, end );            xmlinfo.addForumName(forumname);        }    }    public void ignorableWhitespace(char[] ch, int start, int end)            throws SAXException    {    }    public void skippedEntity(String name) throws SAXException    {    }    public void warning( SAXParseException e ) {        System.err.println( "SAX parse warning: " + e );        System.err.println( "At XML file line: " + locator.getLineNumber()            + ":" + locator.getColumnNumber() );    }    public void error( SAXParseException e ) {        fatalError(e);    }    public void fatalError( SAXParseException e ) {        System.err.println( "SAX parse exception: " + e );        System.err.println( "At XML file line: " + locator.getLineNumber()            + ":" + locator.getColumnNumber() );    }}

⌨️ 快捷键说明

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