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

📄 groupsimpl.java

📁 java写的qq代码实现qq的部分功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        String aLine = null;        while ( (aLine = reader.readLine()) != null ) {            aLine = aLine.trim().toLowerCase();            if (aLine.length() == 0)                continue;            if (!aLine.startsWith("<"))                break;            aLine = aLine.substring(1).trim();            if (!aLine.startsWith("?"))                break;            int index = aLine.indexOf("encoding");            if (index == -1)                break;            aLine = aLine.substring(index+8).trim();            if (!aLine.startsWith("="))                break;            aLine = aLine.substring(1).trim();            if (!aLine.startsWith("\""))                break;            if (aLine.indexOf("\"", 1) == -1)                break;            inputEncoding = aLine.substring(1, aLine.indexOf("\"", 1));            break;        }        reader.close();        return inputEncoding;    }    public static Groups unmarshal(File file) throws IOException {        // Delegate to the unmarshal(Reader) method        String encoding = getInputEncoding( new BufferedReader(new InputStreamReader(new FileInputStream(file), "ISO-8859-1")) );        return unmarshal(new InputStreamReader(new FileInputStream(file), encoding));    }    public static Groups unmarshal(File file, boolean validate) throws IOException {        // Delegate to the unmarshal(Reader) method        String encoding = getInputEncoding( new BufferedReader(new InputStreamReader(new FileInputStream(file), "ISO-8859-1")) );        return unmarshal(new InputStreamReader(new FileInputStream(file), encoding), validate);    }    public static Groups unmarshal(InputStream inputStream) throws IOException {        // Delegate to the unmarshal(Reader) method                String encoding = getInputEncoding( new BufferedReader(new InputStreamReader(inputStream, "ISO-8859-1")) );        return unmarshal(new InputStreamReader(inputStream, encoding));    }    public static Groups unmarshal(InputStream inputStream, boolean validate) throws IOException {        // Delegate to the unmarshal(Reader) method                String encoding = getInputEncoding( new BufferedReader(new InputStreamReader(inputStream, "ISO-8859-1")) );        return unmarshal(new InputStreamReader(inputStream, encoding), validate);    }    public static Groups unmarshal(Reader reader) throws IOException {        // Delegate with default validation value        return unmarshal(reader, false);    }    public static Groups unmarshal(Reader reader, boolean validate) throws IOException {        GroupsImpl groups = GroupsImpl.newInstance();        groups.setValidating(validate);        groups.setCurrentUNode(groups);        groups.setParentUNode(null);        // Load the XML parser        XMLReader parser = null;        String parserClass = System.getProperty("org.xml.sax.driver",            "org.apache.xerces.parsers.SAXParser");        try {            parser = XMLReaderFactory.createXMLReader(parserClass);            // Set entity resolver, if needed            if (entityResolver != null) {                parser.setEntityResolver(entityResolver);            }            // Set error handler            parser.setErrorHandler(groups);            // Register lexical handler            parser.setProperty("http://xml.org/sax/properties/lexical-handler", groups);            // Register content handler            parser.setContentHandler(groups);        } catch (SAXException e) {            throw new IOException("Could not load XML parser: " +                 e.getMessage());        }        InputSource inputSource = new InputSource(reader);        try {            parser.setFeature("http://xml.org/sax/features/validation", new Boolean(validate).booleanValue());            parser.setFeature("http://xml.org/sax/features/namespaces", true);            parser.setFeature("http://xml.org/sax/features/namespace-prefixes", false);            parser.parse(inputSource);        } catch (SAXException e) {            throw new IOException("Error parsing XML document: " +                 e.getMessage());        }        // Return the resultant object        return groups;    }    public Unmarshallable getParentUNode() {        return zeus_parentUNode;    }    public void setParentUNode(Unmarshallable parentUNode) {        this.zeus_parentUNode = parentUNode;    }    public Unmarshallable getCurrentUNode() {        return zeus_currentUNode;    }    public void setCurrentUNode(Unmarshallable currentUNode) {        this.zeus_currentUNode = currentUNode;    }    public void setValidating(boolean validate) {        this.validate = validate;    }    public void startDocument() throws SAXException {        // no-op    }    public void setDocumentLocator(Locator locator) {        // no-op    }    public void startPrefixMapping(String prefix, String uri)        throws SAXException {        namespaceMappings.put(prefix, uri);    }    public void startElement(String namespaceURI, String localName,                             String qName, org.xml.sax.Attributes atts)        throws SAXException {        // Feed this to the correct ContentHandler        Unmarshallable current = getCurrentUNode();        if (current != this) {            current.startElement(namespaceURI, localName, qName, atts);            return;        }        // See if we handle, or we delegate        if ((localName.equals("Groups")) && (!zeus_thisNodeHandled)) {            // Handle ourselves            for (int i=0, len=atts.getLength(); i<len; i++) {                String attName= atts.getLocalName(i);                String attValue = atts.getValue(i);            }            zeus_thisNodeHandled = true;            return;        } else {            // Delegate handling            if (localName.equals("Group")) {                GroupImpl group = GroupImpl.newInstance();                current = getCurrentUNode();                group.setParentUNode(current);                group.setCurrentUNode(group);                this.setCurrentUNode(group);                group.startElement(namespaceURI, localName, qName, atts);                // Add this value in                GroupList.add(group);                return;            }        }    }    public void endElement(String namespaceURI, String localName,                           String qName)        throws SAXException {        Unmarshallable current = getCurrentUNode();        if (current != this) {            current.endElement(namespaceURI, localName, qName);            return;        }        Unmarshallable parent = getCurrentUNode().getParentUNode();        if (parent != null) {            parent.setCurrentUNode(parent);        }    }    public void characters(char[] ch, int start, int len)        throws SAXException {        // Feed this to the correct ContentHandler        Unmarshallable current = getCurrentUNode();        if (current != this) {            current.characters(ch, start, len);            return;        }        String text = new String(ch, start, len);    }    public void comment(char ch[], int start, int len) throws SAXException {        // Currently no-op    }    public void warning(SAXParseException e) throws SAXException {        if (errorHandler != null) {            errorHandler.warning(e);        }    }    public void error(SAXParseException e) throws SAXException {        if ((validate) && (!hasDTD)) {            throw new SAXException("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");        }        if (errorHandler != null) {            errorHandler.error(e);        }    }    public void fatalError(SAXParseException e) throws SAXException {        if ((validate) && (!hasDTD)) {            throw new SAXException("Validation is turned on, but no DTD has been specified in the input XML document. Please supply a DTD through a DOCTYPE reference.");        }        if (errorHandler != null) {            errorHandler.fatalError(e);        }    }    public void startDTD(String name, String publicID, String systemID)        throws SAXException {        if ((name == null) || (name.equals(""))) {            docTypeString = "";            return;        }        hasDTD = true;        StringBuffer docTypeSB = new StringBuffer();        boolean hasPublic = false;        docTypeSB.append("<!DOCTYPE ")                 .append(name);        if ((publicID != null) && (!publicID.equals(""))) {            docTypeSB.append(" PUBLIC \"")                     .append(publicID)                     .append("\"");            hasPublic = true;        }        if ((systemID != null) && (!systemID.equals(""))) {            if (!hasPublic) {                docTypeSB.append(" SYSTEM");            }            docTypeSB.append(" \"")                     .append(systemID)                     .append("\"");        }        docTypeSB.append(">");        docTypeString = docTypeSB.toString();    }    public void endDTD() throws SAXException {        // Currently no-op    }    public void startEntity(String name) throws SAXException {        // Currently no-op    }    public void endEntity(String name) throws SAXException {        // Currently no-op    }    public void startCDATA() throws SAXException {        // Currently no-op    }    public void endCDATA() throws SAXException {        // Currently no-op    }}

⌨️ 快捷键说明

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