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

📄 xmlentitymanager.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        String expandedSystemId = expandSystemId(literalSystemId, baseSystemId, fStrictURI);        if (baseSystemId == null) {            baseSystemId = expandedSystemId;        }        if (reader == null) {            stream = xmlInputSource.getByteStream();            if (stream == null) {                URL location = new URL(expandedSystemId);                 URLConnection connect = location.openConnection();                if (!(connect instanceof HttpURLConnection)) {                    stream = connect.getInputStream();                }                else {                    boolean followRedirects = true;                                        // setup URLConnection if we have an HTTPInputSource                    if (xmlInputSource instanceof HTTPInputSource) {                        final HttpURLConnection urlConnection = (HttpURLConnection) connect;                        final HTTPInputSource httpInputSource = (HTTPInputSource) xmlInputSource;                                                // set request properties                        Iterator propIter = httpInputSource.getHTTPRequestProperties();                        while (propIter.hasNext()) {                            Map.Entry entry = (Map.Entry) propIter.next();                            urlConnection.setRequestProperty((String) entry.getKey(), (String) entry.getValue());                        }                                                // set preference for redirection                        followRedirects = httpInputSource.getFollowHTTPRedirects();                        if (!followRedirects) {                            setInstanceFollowRedirects(urlConnection, followRedirects);                        }                    }                                        stream = connect.getInputStream();                                        // REVISIT: If the URLConnection has external encoding                    // information, we should be reading it here. It's located                    // in the charset parameter of Content-Type. -- mrglavas                                        if (followRedirects) {                        String redirect = connect.getURL().toString();                        // E43: Check if the URL was redirected, and then                        // update literal and expanded system IDs if needed.                        if (!redirect.equals(expandedSystemId)) {                            literalSystemId = redirect;                            expandedSystemId = redirect;                        }                    }                }            }                        // wrap this stream in RewindableInputStream            stream = new RewindableInputStream(stream);                        // perform auto-detect of encoding if necessary            if (encoding == null) {                // read first four bytes and determine encoding                final byte[] b4 = new byte[4];                int count = 0;                for (; count<4; count++ ) {                    b4[count] = (byte)stream.read();                }                if (count == 4) {                    Object [] encodingDesc = getEncodingName(b4, count);                    encoding = (String)(encodingDesc[0]);                    isBigEndian = (Boolean)(encodingDesc[1]);                                        stream.reset();                                        // Special case UTF-8 files with BOM created by Microsoft                    // tools. It's more efficient to consume the BOM than make                    // the reader perform extra checks. -Ac                    if (count > 2 && encoding.equals("UTF-8")) {                        int b0 = b4[0] & 0xFF;                        int b1 = b4[1] & 0xFF;                        int b2 = b4[2] & 0xFF;                        if (b0 == 0xEF && b1 == 0xBB && b2 == 0xBF) {                            // ignore first three bytes...                            stream.skip(3);                        }                    }                    reader = createReader(stream, encoding, isBigEndian);                } else {                    reader = createReader(stream, encoding, isBigEndian);                }            }                        // use specified encoding            else {                encoding = encoding.toUpperCase(Locale.ENGLISH);                                // If encoding is UTF-8, consume BOM if one is present.                if (encoding.equals("UTF-8")) {                    final int[] b3 = new int[3];                    int count = 0;                    for (; count < 3; ++count) {                        b3[count] = stream.read();                        if (b3[count] == -1)                            break;                    }                    if (count == 3) {                        if (b3[0] != 0xEF || b3[1] != 0xBB || b3[2] != 0xBF) {                            // First three bytes are not BOM, so reset.                            stream.reset();                        }                    } else {                        stream.reset();                    }                }                // If encoding is UTF-16, we still need to read the first four bytes                // in order to discover the byte order.                else if (encoding.equals("UTF-16")) {                    final int[] b4 = new int[4];                    int count = 0;                    for (; count < 4; ++count) {                        b4[count] = stream.read();                        if (b4[count] == -1)                            break;                    }                    stream.reset();                                        String utf16Encoding = "UTF-16";                    if (count >= 2) {                        final int b0 = b4[0];                        final int b1 = b4[1];                        if (b0 == 0xFE && b1 == 0xFF) {                            // UTF-16, big-endian                            utf16Encoding = "UTF-16BE";                            isBigEndian = Boolean.TRUE;                        }                        else if (b0 == 0xFF && b1 == 0xFE) {                            // UTF-16, little-endian                            utf16Encoding = "UTF-16LE";                            isBigEndian = Boolean.FALSE;                        }                        else if (count == 4) {                            final int b2 = b4[2];                            final int b3 = b4[3];                            if (b0 == 0x00 && b1 == 0x3C && b2 == 0x00 && b3 == 0x3F) {                                // UTF-16, big-endian, no BOM                                utf16Encoding = "UTF-16BE";                                isBigEndian = Boolean.TRUE;                            }                            if (b0 == 0x3C && b1 == 0x00 && b2 == 0x3F && b3 == 0x00) {                                // UTF-16, little-endian, no BOM                                utf16Encoding = "UTF-16LE";                                isBigEndian = Boolean.FALSE;                            }                        }                    }                    reader = createReader(stream, utf16Encoding, isBigEndian);                }                // If encoding is UCS-4, we still need to read the first four bytes                // in order to discover the byte order.                else if (encoding.equals("ISO-10646-UCS-4")) {                    final int[] b4 = new int[4];                    int count = 0;                    for (; count < 4; ++count) {                        b4[count] = stream.read();                        if (b4[count] == -1)                            break;                    }                    stream.reset();                                        // Ignore unusual octet order for now.                    if (count == 4) {                        // UCS-4, big endian (1234)                        if (b4[0] == 0x00 && b4[1] == 0x00 && b4[2] == 0x00 && b4[3] == 0x3C) {                            isBigEndian = Boolean.TRUE;                        }                        // UCS-4, little endian (1234)                        else if (b4[0] == 0x3C && b4[1] == 0x00 && b4[2] == 0x00 && b4[3] == 0x00) {                            isBigEndian = Boolean.FALSE;                        }                    }                }                // If encoding is UCS-2, we still need to read the first four bytes                // in order to discover the byte order.                else if (encoding.equals("ISO-10646-UCS-2")) {                    final int[] b4 = new int[4];                    int count = 0;                    for (; count < 4; ++count) {                        b4[count] = stream.read();                        if (b4[count] == -1)                            break;                    }                    stream.reset();                                        if (count == 4) {                        // UCS-2, big endian                        if (b4[0] == 0x00 && b4[1] == 0x3C && b4[2] == 0x00 && b4[3] == 0x3F) {                            isBigEndian = Boolean.TRUE;                        }                        // UCS-2, little endian                        else if (b4[0] == 0x3C && b4[1] == 0x00 && b4[2] == 0x3F && b4[3] == 0x00) {                            isBigEndian = Boolean.FALSE;                        }                    }                }                                reader = createReader(stream, encoding, isBigEndian);            }                        // read one character at a time so we don't jump too far            // ahead, converting characters from the byte stream in            // the wrong encoding            if (DEBUG_ENCODINGS) {                System.out.println("$$$ no longer wrapping reader in OneCharReader");            }            //reader = new OneCharReader(reader);        }                // We've seen a new Reader.        // Push it on the stack so we can close it later.        //fOwnReaders.add(reader);                // push entity on stack        if (fCurrentEntity != null) {            fEntityStack.push(fCurrentEntity);        }                // create entity        /* if encoding is specified externally, 'encoding' information present          * in the prolog of the XML document is not considered. Hence, prolog can         * be read in Chunks of data instead of byte by byte.           */        fCurrentEntity = new com.sun.xml.internal.stream.Entity.ScannedEntity(name,new XMLResourceIdentifierImpl(publicId, literalSystemId, baseSystemId, expandedSystemId),stream, reader, encoding, literal, encodingExternallySpecified, isExternal);                fCurrentEntity.setEncodingExternallySpecified(encodingExternallySpecified);        fEntityScanner.setCurrentEntity(fCurrentEntity);        fResourceIdentifier.setValues(publicId, literalSystemId, baseSystemId, expandedSystemId);        return encoding;    } //setupCurrentEntity(String, XMLInputSource, boolean, boolean):  String    /**     * Checks whether an entity given by name is external.     *     * @param entityName The name of the entity to check.     * @return True if the entity is external, false otherwise     * (including when the entity is not declared).     */                   public boolean isExternalEntity(String entityName) {                Entity entity = (Entity)fEntities.get(entityName);        if (entity == null) {            return false;        }        return entity.isExternal();    }        /**     * Checks whether the declaration of an entity given by name is     * // in the external subset.     *     * @param entityName The name of the entity to check.     * @return True if the entity was declared in the external subset, false otherwise     *           (including when the entity is not declared).     */    public boolean isEntityDeclInExternalSubset(String entityName) {                Entity entity = (Entity)fEntities.get(entityName);        if (entity == null) {            return false;        }        return entity.isEntityDeclInExternalSubset();    }                //    // Public methods    //        /**     * Sets whether the document entity is standalone.     *     * @param standalone True if document entity is standalone.     */    public void setStandalone(boolean standalone) {        fStandalone = standalone;    }    // setStandalone(boolean)        /** Returns true if the document entity is standalone. */    public boolean isStandalone() {        return fStandalone;    }  //isStandalone():boolean        public boolean isDeclaredEntity(String entityName) {                Entity entity = (Entity)fEntities.get(entityName);        return entity != null;    }        public boolean isUnparsedEntity(String entityName) {                Entity entity = (Entity)fEntities.get(entityName);        if (entity == null) {            return false;        }        return entity.isUnparsed();    }                // this simply returns the fResourceIdentifier object;    // this should only be used with caution by callers that    // carefully manage the entity manager's behaviour, so that    // this doesn't returning meaningless or misleading data.    // @return  a reference to the current fResourceIdentifier object    public XMLResourceIdentifier getCurrentResourceIdentifier() {        return fResourceIdentifier;    }        /**     * Sets the entity handler. When an entity starts and ends, the     * entity handler is notified of the change.     *     * @param entityHandler The new entity handler.     */    

⌨️ 快捷键说明

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