📄 htmlfactory.java
字号:
package it.unimi.dsi.mg4j.util.parser;/* * MG4J: Managing Gigabytes for Java * * Copyright (C) 2005-2007 Sebastiano Vigna * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */import it.unimi.dsi.fastutil.Hash;import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;import it.unimi.dsi.mg4j.util.MutableString;/** A parsing factory for (X)HTML. * * <p><strong>Warning:</strong> for maximum flexibility, the methods of this factory * do <em>not</em> perform case normalisation. If you are parsing HTML, you are invited * to downcase your names before accessing {@link #getElement(MutableString)} * and {@link #getAttribute(MutableString)}. * * <p>This class is a singleton, and its only instance is accessible using the public field * {@link #INSTANCE}. * * <p>The relationship between this class and {@link Element}/{@link Attribute} is a bit * twisted due to the need to accomodate two features: * <ul> * <li>(X)HTML interned objects must be accessible directly (see, e.g., {@link Element#A}); * <li>(X)HTML interned objects must be put into suitable name-to-object maps. * </ul> * * <p>To this purpose, this class exports packagewise some static factory methods that create {@link Element}s and * {@link Attribute}s and register them locally. The static initialisation code in * {@link Element} and {@link Attribute} creates elements such as {@link Element#A} using the abovementioned * factory methods. * * <p>An alternative implementation could use reflection, but I don't see great advantages. * @deprecated Moved to <code>dsiutils</code>. */@Deprecatedpublic class HTMLFactory implements ParsingFactory { private HTMLFactory() {} public static final HTMLFactory INSTANCE = new HTMLFactory(); public Element getElement( final MutableString name ) { return NAME2ELEMENT.get( name ); } public Attribute getAttribute( final MutableString name ) { return NAME2ATTRIBUTE.get( name ); } public Entity getEntity( final MutableString name ) { return NAME2ENTITY.get( name ); } /** A (quick) map from entity names to entites. */ static final Object2ObjectOpenHashMap<CharSequence,Entity> NAME2ENTITY = new Object2ObjectOpenHashMap<CharSequence,Entity>( Hash.DEFAULT_INITIAL_SIZE, .5f ); /** A (quick) map from attribute names to attributes. */ static final Object2ObjectOpenHashMap<CharSequence,Attribute> NAME2ATTRIBUTE = new Object2ObjectOpenHashMap<CharSequence,Attribute>( Hash.DEFAULT_INITIAL_SIZE, .5f ); /** A (quick) map from element-type names to element types. */ static final Object2ObjectOpenHashMap<CharSequence,Element> NAME2ELEMENT = new Object2ObjectOpenHashMap<CharSequence,Element>( Hash.DEFAULT_INITIAL_SIZE, .5f ); static Element newElement( final CharSequence name ) { final Element element = new Element( name ); NAME2ELEMENT.put( element.name, element ); return element; } static Element newElement( final CharSequence name, final boolean breaksFlow, final boolean isSimple ) { final Element element = new Element( name, breaksFlow, isSimple ); NAME2ELEMENT.put( element.name, element ); return element; } static Element newElement( final CharSequence name, final boolean breaksFlow, final boolean isSimple, final boolean isImplicit ) { final Element element = new Element( name, breaksFlow, isSimple, isImplicit ); NAME2ELEMENT.put( element.name, element ); return element; } static Attribute newAttribute( final CharSequence name ) { final Attribute attribute = new Attribute( name ); NAME2ATTRIBUTE.put( attribute.name, attribute ); return attribute; } static Entity newEntity( final CharSequence name, final char c ) { final Entity entity = new Entity( name, c ); NAME2ENTITY.put( entity.name, entity ); return entity; } static { NAME2ATTRIBUTE.defaultReturnValue( Attribute.UNKNOWN ); NAME2ELEMENT.defaultReturnValue( Element.UNKNOWN ); // --- Entity Names ----------------------------------- // Latin 1 HTMLFactory.newEntity( "nbsp", (char)160 ); HTMLFactory.newEntity( "iexcl", (char)161 ); HTMLFactory.newEntity( "cent", (char)162 ); HTMLFactory.newEntity( "pound", (char)163 ); HTMLFactory.newEntity( "curren", (char)164 ); HTMLFactory.newEntity( "yen", (char)165 ); HTMLFactory.newEntity( "brvbar", (char)166 ); HTMLFactory.newEntity( "sect", (char)167 ); HTMLFactory.newEntity( "uml", (char)168 ); HTMLFactory.newEntity( "copy", (char)169 ); HTMLFactory.newEntity( "ordf", (char)170 ); HTMLFactory.newEntity( "laquo", (char)171 ); HTMLFactory.newEntity( "not", (char)172 ); HTMLFactory.newEntity( "shy", (char)173 ); HTMLFactory.newEntity( "reg", (char)174 ); HTMLFactory.newEntity( "macr", (char)175 ); HTMLFactory.newEntity( "deg", (char)176 ); HTMLFactory.newEntity( "plusmn", (char)177 ); HTMLFactory.newEntity( "sup2", (char)178 ); HTMLFactory.newEntity( "sup3", (char)179 ); HTMLFactory.newEntity( "acute", (char)180 ); HTMLFactory.newEntity( "micro", (char)181 ); HTMLFactory.newEntity( "para", (char)182 ); HTMLFactory.newEntity( "middot", (char)183 ); HTMLFactory.newEntity( "cedil", (char)184 ); HTMLFactory.newEntity( "sup1", (char)185 ); HTMLFactory.newEntity( "ordm", (char)186 ); HTMLFactory.newEntity( "raquo", (char)187 ); HTMLFactory.newEntity( "frac14", (char)188 ); HTMLFactory.newEntity( "frac12", (char)189 ); HTMLFactory.newEntity( "frac34", (char)190 ); HTMLFactory.newEntity( "iquest", (char)191 ); HTMLFactory.newEntity( "Agrave", (char)192 ); HTMLFactory.newEntity( "Aacute", (char)193 ); HTMLFactory.newEntity( "Acirc", (char)194 ); HTMLFactory.newEntity( "Atilde", (char)195 ); HTMLFactory.newEntity( "Auml", (char)196 ); HTMLFactory.newEntity( "Aring", (char)197 ); HTMLFactory.newEntity( "AElig", (char)198 ); HTMLFactory.newEntity( "Ccedil", (char)199 ); HTMLFactory.newEntity( "Egrave", (char)200 ); HTMLFactory.newEntity( "Eacute", (char)201 ); HTMLFactory.newEntity( "Ecirc", (char)202 ); HTMLFactory.newEntity( "Euml", (char)203 ); HTMLFactory.newEntity( "Igrave", (char)204 ); HTMLFactory.newEntity( "Iacute", (char)205 ); HTMLFactory.newEntity( "Icirc", (char)206 ); HTMLFactory.newEntity( "Iuml", (char)207 ); HTMLFactory.newEntity( "ETH", (char)208 ); HTMLFactory.newEntity( "Ntilde", (char)209 ); HTMLFactory.newEntity( "Ograve", (char)210 ); HTMLFactory.newEntity( "Oacute", (char)211 ); HTMLFactory.newEntity( "Ocirc", (char)212 ); HTMLFactory.newEntity( "Otilde", (char)213 ); HTMLFactory.newEntity( "Ouml", (char)214 ); HTMLFactory.newEntity( "times", (char)215 ); HTMLFactory.newEntity( "Oslash", (char)216 ); HTMLFactory.newEntity( "Ugrave", (char)217 ); HTMLFactory.newEntity( "Uacute", (char)218 ); HTMLFactory.newEntity( "Ucirc", (char)219 ); HTMLFactory.newEntity( "Uuml", (char)220 ); HTMLFactory.newEntity( "Yacute", (char)221 ); HTMLFactory.newEntity( "THORN", (char)222 ); HTMLFactory.newEntity( "szlig", (char)223 ); HTMLFactory.newEntity( "agrave", (char)224 ); HTMLFactory.newEntity( "aacute", (char)225 ); HTMLFactory.newEntity( "acirc", (char)226 ); HTMLFactory.newEntity( "atilde", (char)227 ); HTMLFactory.newEntity( "auml", (char)228 ); HTMLFactory.newEntity( "aring", (char)229 ); HTMLFactory.newEntity( "aelig", (char)230 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -