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

📄 xmlimporter.java

📁 这个是perst-269.zip下面的SOURCECODE,和大家分享了。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                        offs += 4;
                    } else {
                        XMLElement item = elem.getSibling("element");
                        int len = (item == null) ? 0 : item.getCounter(); 
                        Bytes.pack4(buf.arr, offs, len);
                        offs += 4;
                        ClassDescriptor elemDesc = fd.valueDesc;
                        while (--len >= 0) {
                            offs = packObject(item, elemDesc, offs, buf);
                            item = item.getNextSibling();
                        }
                    }
                    continue;
                case ClassDescriptor.tpArrayOfRaw:
                    if (elem == null || elem.isNullValue()) {
                        buf.extend(offs + 4);
                        Bytes.pack4(buf.arr, offs, -1);
                        offs += 4;
                    } else {
                        XMLElement item = elem.getSibling("element");
                        int len = (item == null) ? 0 : item.getCounter(); 
                        Bytes.pack4(buf.arr, offs, len);
                        offs += 4;
                        while (--len >= 0) {
                            offs = importBinary(item, offs, buf, fieldName);
                            item = item.getNextSibling();
                        }
                    }
                    continue;
            }
        }
        return offs;
    }

    final XMLElement readElement(String name) throws XMLImportException 
    {
        XMLElement elem = new XMLElement(name);
        String attribute;
        int tkn;
        while (true) { 
            switch (scanner.scan()) { 
              case XMLScanner.XML_GTS:
                return elem;
              case XMLScanner.XML_GT:    
                while ((tkn = scanner.scan()) == XMLScanner.XML_LT) { 
                    if (scanner.scan() != XMLScanner.XML_IDENT) { 
                        throwException("Element name expected");
                    }
                    String siblingName = scanner.getIdentifier();
                    XMLElement sibling = readElement(siblingName);
                    elem.addSibling(sibling);
                }
                switch (tkn) { 
                  case XMLScanner.XML_SCONST:
                    elem.setStringValue(scanner.getString());
                    tkn = scanner.scan();
                    break;
                  case XMLScanner.XML_ICONST:
                    elem.setIntValue(scanner.getInt());
                    tkn = scanner.scan();
                    break;
                  case XMLScanner.XML_FCONST:
                    elem.setRealValue(scanner.getReal());
                    tkn = scanner.scan();
                    break;
                  case XMLScanner.XML_IDENT:
                    if (scanner.getIdentifier().equals("null")) { 
                        elem.setNullValue();
                    } else { 
                        elem.setStringValue(scanner.getIdentifier());
                    }
                    tkn = scanner.scan();
                }
                if (tkn != XMLScanner.XML_LTS                    
                    || scanner.scan() != XMLScanner.XML_IDENT
                    || !scanner.getIdentifier().equals(name)
                    || scanner.scan() != XMLScanner.XML_GT)
                {
                    throwException("Element is not closed");
                }
                return elem;
              case XMLScanner.XML_IDENT:
                attribute = scanner.getIdentifier();
                if (scanner.scan() != XMLScanner.XML_EQ || scanner.scan() != XMLScanner.XML_SCONST)
                {
                    throwException("Attribute value expected");
                }
                elem.addAttribute(attribute, scanner.getString());
                continue;
              default:
                throwException("Unexpected token");
            }
        }
    }

    final void throwException(String message) throws XMLImportException { 
        throw new XMLImportException(scanner.getLine(), scanner.getColumn(), message);
    }

    StorageImpl storage;
    XMLScanner  scanner;
    int[]       idMap;

    static final String     dateFormat = "EEE, d MMM yyyy kk:mm:ss z";
    static final DateFormat httpFormatter = new SimpleDateFormat(dateFormat, Locale.ENGLISH);


    static class XMLScanner { 
        static final int XML_IDENT  = 0;
        static final int XML_SCONST = 1;
        static final int XML_ICONST = 2; 
        static final int XML_FCONST = 3; 
        static final int XML_LT     = 4; 
        static final int XML_GT     = 5; 
        static final int XML_LTS    = 6; 
        static final int XML_GTS    = 7;
        static final int XML_EQ     = 8; 
        static final int XML_EOF    = 9;
        
        Reader         reader;
        int            line;
        int            column;
        char[]         sconst;
        long           iconst;
        double         fconst;
        int            slen;
        String         ident;
        int            size;
        int            ungetChar;
        boolean        hasUngetChar;

        XMLScanner(Reader in) {
            reader = in;
            sconst = new char[size = 1024];
            line = 1;
            column = 0;
            hasUngetChar = false;
        }

        final int get() throws XMLImportException { 
            if (hasUngetChar) { 
                hasUngetChar = false;
                return ungetChar;
            }
            try { 
                int ch = reader.read();
                if (ch == '\n') { 
                    line += 1;
                    column = 0;
                } else if (ch == '\t') { 
                    column += (column + 8) & ~7;
                } else { 
                    column += 1;
                }
                return ch;
            } catch (IOException x) { 
                throw new XMLImportException(line, column, x.getMessage());
            }
        }
        
        final void unget(int ch) { 
            if (ch == '\n') {
                line -= 1;
            } else { 
                column -= 1;
            }
            ungetChar = ch;
            hasUngetChar = true;
        }
        
        final int scan() throws XMLImportException
        {
            int i, ch;
            boolean floatingPoint;

            while (true) { 
                do {
                    if ((ch = get()) < 0) {
                        return XML_EOF;
                    }
                } while (ch <= ' ');
                
                switch (ch) { 
                  case '<':
                    ch = get();
                    if (ch == '?') { 
                        while ((ch = get()) != '?') { 
                            if (ch < 0) { 
                                throw new XMLImportException(line, column, "Bad XML file format");
                            }
                        }
                        if ((ch = get()) != '>') { 
                            throw new XMLImportException(line, column, "Bad XML file format");
                        }
                        continue;
                    } 
                    if (ch != '/') { 
                        unget(ch);
                        return XML_LT;
                    }
                    return XML_LTS;
                  case '>':
                    return XML_GT;
                  case '/':
                    ch = get();
                    if (ch != '>') { 
                        unget(ch);
                        throw new XMLImportException(line, column, "Bad XML file format");
                    }
                    return XML_GTS;
                  case '=':
                    return XML_EQ;
                  case '"':
                    i = 0;
                    while (true) { 
                        ch = get();
                        if (ch < 0) { 
                            throw new XMLImportException(line, column, "Bad XML file format");
                        } else if (ch == '&') { 
                            switch (get()) { 
                              case 'a':
                                if (get() != 'm' || get() != 'p' || get() != ';') { 
                                    throw new XMLImportException(line, column, "Bad XML file format");
                                }
                                ch = '&';
                                break;
                              case 'l':
                                if (get() != 't' || get() != ';') { 
                                    throw new XMLImportException(line, column, "Bad XML file format");
                                }
                                ch = '<';
                                break;
                              case 'g':
                                if (get() != 't' || get() != ';') { 
                                    throw new XMLImportException(line, column, "Bad XML file format");
                                }
                                ch = '>';
                                break;
                              case 'q':
                                if (get() != 'u' || get() != 'o' || get() != 't' || get() != ';') { 
                                    throw new XMLImportException(line, column, "Bad XML file format");
                                }
                                ch = '"';
                                break;
                              default: 
                                throw new XMLImportException(line, column, "Bad XML file format");
                            }
                        } else if (ch == '"') { 
                            slen = i;
                            return XML_SCONST;
                        }
                        if (i == size) { 
                            char[] newBuf = new char[size *= 2];
                            System.arraycopy(sconst, 0, newBuf, 0, i);
                            sconst = newBuf;
                        }
                        sconst[i++] = (char)ch;
                    }
                  case '-': case '+':
                  case '0': case '1': case '2': case '3': case '4':
                  case '5': case '6': case '7': case '8': case '9':
                    i = 0;
                    floatingPoint = false;
                    while (true) { 
                        if (!Character.isDigit((char)ch) && ch != '-' && ch != '+' && ch != '.' && ch != 'E') { 
                            unget(ch);
                            try { 
                                if (floatingPoint) { 
                                    fconst = Double.parseDouble(new String(sconst, 0, i));
                                    return XML_FCONST;
                                } else { 
                                    iconst = Long.parseLong(new String(sconst, 0, i));
                                    return XML_ICONST;
                                }
                            } catch (NumberFormatException x) { 
                                throw new XMLImportException(line, column, "Bad XML file format");
                            }
                        }
                        if (i == size) { 
                            throw new XMLImportException(line, column, "Bad XML file format");
                        }
                        sconst[i++] = (char)ch;
                        if (ch == '.') { 
                            floatingPoint = true;
                        }
                        ch = get();
                    }
                  default:
                    i = 0;
                    while (Character.isLetterOrDigit((char)ch) || ch == '-' || ch == ':' || ch == '_' || ch == '.') {
                        if (i == size) { 
                            throw new XMLImportException(line, column, "Bad XML file format");
                        }
                        if (ch == '-') { 
                            ch = '$';
                        }                                
                        sconst[i++] = (char)ch;
                        ch = get();
                    }
                    unget(ch);
                    if (i == 0) { 
                        throw new XMLImportException(line, column, "Bad XML file format");
                    }
                    ident = new String(sconst, 0, i);
                    return XML_IDENT;
                }
            }
        }
        
        final String getIdentifier() { 
            return ident;
        }

        final String getString() { 
            return new String(sconst, 0, slen);
        }

        final long getInt() { 
            return iconst;
        }

        final double getReal() { 
            return fconst;
        }

        final int    getLine() { 
            return line;
        }

        final int    getColumn() { 
            return column;
        }
    }
}

⌨️ 快捷键说明

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