📄 htmldtd.java
字号:
if ( openTag.equalsIgnoreCase( "LI" ) || openTag.equalsIgnoreCase( "OPTION" ) ) return isElement( tagName, CLOSE_SELF ); // Each of these table sections closes all the others if ( openTag.equalsIgnoreCase( "THEAD" ) || openTag.equalsIgnoreCase( "TFOOT" ) || openTag.equalsIgnoreCase( "TBODY" ) || openTag.equalsIgnoreCase( "TR" ) || openTag.equalsIgnoreCase( "COLGROUP" ) ) return isElement( tagName, CLOSE_TABLE ); // TD closes TH and TH closes TD if ( openTag.equalsIgnoreCase( "TH" ) || openTag.equalsIgnoreCase( "TD" ) ) return isElement( tagName, CLOSE_TH_TD ); return false; } /** * Returns true if the specified attribute it a URI and should be * escaped appropriately. In HTML URIs are escaped differently * than normal attributes. * * @param tagName The element's tag name * @param attrName The attribute's name */ public static boolean isURI( String tagName, String attrName ) { // Stupid checks. return ( attrName.equalsIgnoreCase( "href" ) || attrName.equalsIgnoreCase( "src" ) ); } /** * Returns true if the specified attribute is a boolean and should be * printed without the value. This applies to attributes that are true * if they exist, such as selected (OPTION/INPUT). * * @param tagName The element's tag name * @param attrName The attribute's name */ public static boolean isBoolean( String tagName, String attrName ) { String[] attrNames; attrNames = (String[]) _boolAttrs.get( tagName.toUpperCase() ); if ( attrNames == null ) return false; for ( int i = 0 ; i < attrNames.length ; ++i ) if ( attrNames[ i ].equalsIgnoreCase( attrName ) ) return true; return false; } /** * Returns the value of an HTML character reference by its name. If the * reference is not found or was not defined as a character reference, * returns EOF (-1). * * @param name Name of character reference * @return Character code or EOF (-1) */ public static int charFromName( String name ) { Object value; initialize(); value = _byName.get( name ); if ( value != null && value instanceof Integer ) return ( (Integer) value ).intValue(); else return -1; } /** * Returns the name of an HTML character reference based on its character * value. Only valid for entities defined from character references. If no * such character value was defined, return null. * * @param value Character value of entity * @return Entity's name or null */ public static String fromChar(int value ) { if (value > 0xffff) return null; String name; initialize(); name = (String) _byChar.get( new Integer( value ) ); return name; } /** * Initialize upon first access. Will load all the HTML character references * into a list that is accessible by name or character value and is optimized * for character substitution. This method may be called any number of times * but will execute only once. */ private static void initialize() { InputStream is = null; BufferedReader reader = null; int index; String name; String value; int code; String line; // Make sure not to initialize twice. if ( _byName != null ) return; try { _byName = new HashMap(); _byChar = new HashMap(); is = HTMLdtd.class.getResourceAsStream( ENTITIES_RESOURCE ); if ( is == null ) throw new RuntimeException( "SER003 The resource [" + ENTITIES_RESOURCE + "] could not be found.\n" + ENTITIES_RESOURCE); reader = new BufferedReader( new InputStreamReader( is ) ); line = reader.readLine(); while ( line != null ) { if ( line.length() == 0 || line.charAt( 0 ) == '#' ) { line = reader.readLine(); continue; } index = line.indexOf( ' ' ); if ( index > 1 ) { name = line.substring( 0, index ); ++index; if ( index < line.length() ) { value = line.substring( index ); index = value.indexOf( ' ' ); if ( index > 0 ) value = value.substring( 0, index ); code = Integer.parseInt( value ); defineEntity( name, (char) code ); } } line = reader.readLine(); } is.close(); } catch ( Exception except ) { throw new RuntimeException( "SER003 The resource [" + ENTITIES_RESOURCE + "] could not load: " + except.toString() + "\n" + ENTITIES_RESOURCE + "\t" + except.toString()); } finally { if ( is != null ) { try { is.close(); } catch ( Exception except ) { } } } // save only the unmodifiable map to the member variable. _byName = Collections.unmodifiableMap(_byName); _byChar = Collections.unmodifiableMap(_byChar); } /** * Defines a new character reference. The reference's name and value are * supplied. Nothing happens if the character reference is already defined. * <P> * Unlike internal entities, character references are a string to single * character mapping. They are used to map non-ASCII characters both on * parsing and printing, primarily for HTML documents. '<amp;' is an * example of a character reference. * * @param name The entity's name * @param value The entity's value */ private static void defineEntity( String name, char value ) { if ( _byName.get( name ) == null ) { _byName.put( name, new Integer( value ) ); _byChar.put( new Integer( value ), name ); } } private static void defineElement( String name, int flags ) { _elemDefs.put( name, new Integer( flags ) ); } private static void defineBoolean( String tagName, String attrName ) { defineBoolean( tagName, new String[] { attrName } ); } private static void defineBoolean( String tagName, String[] attrNames ) { _boolAttrs.put( tagName, attrNames ); } private static boolean isElement( String name, int flag ) { Integer flags; flags = (Integer) _elemDefs.get( name.toUpperCase() ); if ( flags == null ) return false; else return ( ( flags.intValue() & flag ) == flag ); } static { _elemDefs = new HashMap(); defineElement( "ADDRESS", CLOSE_P ); defineElement( "AREA", EMPTY ); defineElement( "BASE", EMPTY | ALLOWED_HEAD ); defineElement( "BASEFONT", EMPTY ); defineElement( "BLOCKQUOTE", CLOSE_P ); defineElement( "BODY", OPT_CLOSING ); defineElement( "BR", EMPTY ); defineElement( "COL", EMPTY ); defineElement( "COLGROUP", ELEM_CONTENT | OPT_CLOSING | CLOSE_TABLE ); defineElement( "DD", OPT_CLOSING | ONLY_OPENING | CLOSE_DD_DT ); defineElement( "DIV", CLOSE_P ); defineElement( "DL", ELEM_CONTENT | CLOSE_P ); defineElement( "DT", OPT_CLOSING | ONLY_OPENING | CLOSE_DD_DT ); defineElement( "FIELDSET", CLOSE_P ); defineElement( "FORM", CLOSE_P ); defineElement( "FRAME", EMPTY | OPT_CLOSING ); defineElement( "H1", CLOSE_P ); defineElement( "H2", CLOSE_P ); defineElement( "H3", CLOSE_P ); defineElement( "H4", CLOSE_P ); defineElement( "H5", CLOSE_P ); defineElement( "H6", CLOSE_P ); defineElement( "HEAD", ELEM_CONTENT | OPT_CLOSING ); defineElement( "HR", EMPTY | CLOSE_P ); defineElement( "HTML", ELEM_CONTENT | OPT_CLOSING ); defineElement( "IMG", EMPTY ); defineElement( "INPUT", EMPTY ); defineElement( "ISINDEX", EMPTY | ALLOWED_HEAD ); defineElement( "LI", OPT_CLOSING | ONLY_OPENING | CLOSE_SELF ); defineElement( "LINK", EMPTY | ALLOWED_HEAD ); defineElement( "MAP", ALLOWED_HEAD ); defineElement( "META", EMPTY | ALLOWED_HEAD ); defineElement( "OL", ELEM_CONTENT | CLOSE_P ); defineElement( "OPTGROUP", ELEM_CONTENT ); defineElement( "OPTION", OPT_CLOSING | ONLY_OPENING | CLOSE_SELF ); defineElement( "P", OPT_CLOSING | CLOSE_P | CLOSE_SELF ); defineElement( "PARAM", EMPTY ); defineElement( "PRE", PRESERVE | CLOSE_P ); defineElement( "SCRIPT", ALLOWED_HEAD | PRESERVE ); defineElement( "NOSCRIPT", ALLOWED_HEAD | PRESERVE ); defineElement( "SELECT", ELEM_CONTENT ); defineElement( "STYLE", ALLOWED_HEAD | PRESERVE ); defineElement( "TABLE", ELEM_CONTENT | CLOSE_P ); defineElement( "TBODY", ELEM_CONTENT | OPT_CLOSING | CLOSE_TABLE ); defineElement( "TD", OPT_CLOSING | CLOSE_TH_TD ); defineElement( "TEXTAREA", PRESERVE ); defineElement( "TFOOT", ELEM_CONTENT | OPT_CLOSING | CLOSE_TABLE ); defineElement( "TH", OPT_CLOSING | CLOSE_TH_TD ); defineElement( "THEAD", ELEM_CONTENT | OPT_CLOSING | CLOSE_TABLE ); defineElement( "TITLE", ALLOWED_HEAD ); defineElement( "TR", ELEM_CONTENT | OPT_CLOSING | CLOSE_TABLE ); defineElement( "UL", ELEM_CONTENT | CLOSE_P ); _elemDefs = Collections.unmodifiableMap(_elemDefs);; _boolAttrs = new HashMap(); defineBoolean( "AREA", "href" ); defineBoolean( "BUTTON", "disabled" ); defineBoolean( "DIR", "compact" ); defineBoolean( "DL", "compact" ); defineBoolean( "FRAME", "noresize" ); defineBoolean( "HR", "noshade" ); defineBoolean( "IMAGE", "ismap" ); defineBoolean( "INPUT", new String[] { "defaultchecked", "checked", "readonly", "disabled" } ); defineBoolean( "LINK", "link" ); defineBoolean( "MENU", "compact" ); defineBoolean( "OBJECT", "declare" ); defineBoolean( "OL", "compact" ); defineBoolean( "OPTGROUP", "disabled" ); defineBoolean( "OPTION", new String[] { "default-selected", "selected", "disabled" } ); defineBoolean( "SCRIPT", "defer" ); defineBoolean( "SELECT", new String[] { "multiple", "disabled" } ); defineBoolean( "STYLE", "disabled" ); defineBoolean( "TD", "nowrap" ); defineBoolean( "TH", "nowrap" ); defineBoolean( "TEXTAREA", new String[] { "disabled", "readonly" } ); defineBoolean( "UL", "compact" ); _boolAttrs = Collections.unmodifiableMap(_boolAttrs); initialize(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -