RTEditor/src/main/java/com/onegravity/rteditor/converter/tagsoup/Parser.java
@Override
    public void decl(char[] buff, int offset, int length) throws SAXException {
        String s = new String(buff, offset, length);
        String name = null;
        String systemid = null;
        String publicid = null;
        String[] v = split(s);
        if (v.length > 0 && "DOCTYPE".equalsIgnoreCase(v[0])) {
            if (theDoctypeIsPresent)
                return; // one doctype only!
            theDoctypeIsPresent = true;
            if (v.length > 1) {
                name = v[1];
                if (v.length > 3 && "SYSTEM".equals(v[2])) {
                    systemid = v[3];
                } else if (v.length > 3 && "PUBLIC".equals(v[2])) {
                    publicid = v[3];
                    if (v.length > 4) {
                        systemid = v[4];
                    } else {
                        systemid = "";
                    }
                }
            }
        }
        publicid = trimquotes(publicid);
        systemid = trimquotes(systemid);
        if (name != null) {
            publicid = cleanPublicid(publicid);
            theLexicalHandler.startDTD(name, publicid, systemid);
            theLexicalHandler.endDTD();
            theDoctypeName = name;
            theDoctypePublicId = publicid;
            if (theScanner instanceof Locator) { // Must resolve systemid
                theDoctypeSystemId = ((Locator) theScanner).getSystemId();
                try {
                    theDoctypeSystemId = new URL(new URL(theDoctypeSystemId), systemid).toString();
                } catch (Exception ignore) {
                }
            }
        }
    }
@Override
    public void decl(char[] buff, int offset, int length) throws SAXException {
        String s = new String(buff, offset, length);
        String name = null;
        String systemid = null;
        String publicid = null;
        String[] v = split(s);
        if (v.length > 0 && "DOCTYPE".equalsIgnoreCase(v[0])) {
            if (theDoctypeIsPresent)
                return; // one doctype only!
            theDoctypeIsPresent = true;
            if (v.length > 1) {
                name = v[1];
                if (v.length > 3 && "SYSTEM".equals(v[2])) {
                    systemid = v[3];
                } else if (v.length > 3 && "PUBLIC".equals(v[2])) {
                    publicid = v[3];
                    if (v.length > 4) {
                        systemid = v[4];
                    } else {
                        systemid = "";
                    }
                }
            }
        }
        publicid = trimquotes(publicid);
        systemid = trimquotes(systemid);
        if (name != null) {
            publicid = cleanPublicid(publicid);
            theLexicalHandler.startDTD(name, publicid, systemid);
            theLexicalHandler.endDTD();
            theDoctypeName = name;
            theDoctypePublicId = publicid;
            if (theScanner instanceof Locator) { // Must resolve systemid
                theDoctypeSystemId = ((Locator) theScanner).getSystemId();
                try {
                    theDoctypeSystemId = new URL(new URL(theDoctypeSystemId), systemid).toString();
                } catch (Exception ignore) {
                }
            }
        }
    }
@ Override public void decl ( char [ ] buff , int offset , int length ) throws SAXException { String s = new String ( buff , offset , length ) ; String name = null ; String systemid = null ; String publicid = null ; String [ ] v = split ( s ) ; if ( v . length > 0 && "DOCTYPE" . equalsIgnoreCase ( v [ 0 ] ) ) { if ( theDoctypeIsPresent ) return ; // one doctype only! theDoctypeIsPresent = true ; if ( v . length > 1 ) { name = v [ 1 ] ; if ( v . length > 3 && "SYSTEM" . equals ( v [ 2 ] ) ) { systemid = v [ 3 ] ; } else if ( v . length > 3 && "PUBLIC" . equals ( v [ 2 ] ) ) { publicid = v [ 3 ] ; if ( v . length > 4 ) { systemid = v [ 4 ] ; } else { systemid = "" ; } } } } publicid = trimquotes ( publicid ) ; systemid = trimquotes ( systemid ) ; if ( name != null ) { publicid = cleanPublicid ( publicid ) ; theLexicalHandler . startDTD ( name , publicid , systemid ) ; theLexicalHandler . endDTD ( ) ; theDoctypeName = name ; theDoctypePublicId = publicid ; if ( theScanner instanceof Locator ) { // Must resolve systemid theDoctypeSystemId = ( ( Locator ) theScanner ) . getSystemId ( ) ; try { theDoctypeSystemId = new URL ( new URL ( theDoctypeSystemId ) , systemid ) . toString ( ) ; } catch ( Exception ignore ) { } } } }
Parsing the complete XML Document Type Definition is way too complex, but
for many simple cases we can extract something useful from it.
<p>
doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']'
S?)? '>' DeclSep ::= PEReference | S intSubset ::= (markupdecl |
DeclSep)* markupdecl ::= elementdecl | AttlistDecl | EntityDecl |
NotationDecl | PI | Comment ExternalID ::= 'SYSTEM' S SystemLiteral |
'PUBLIC' S PubidLiteral S SystemLiteral
Parsing the complete XML Document Type Definition is way too complex but for many simple cases we can extract something useful from it . <p > doctypedecl :: = <!DOCTYPE S Name ( S ExternalID ) ? S? ( [ intSubset ] S? ) ? > DeclSep :: = PEReference | S intSubset :: = ( markupdecl | DeclSep ) * markupdecl :: = elementdecl | AttlistDecl | EntityDecl | NotationDecl | PI | Comment ExternalID :: = SYSTEM S SystemLiteral | PUBLIC S PubidLiteral S SystemLiteral