htmldocument.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 1,709 行 · 第 1/4 页
JAVA
1,709 行
/** * An iterator over a particular type of tag. */ public abstract static class Iterator { /** * Return the attribute set for this tag. * @return the <code>AttributeSet</code> (null if none found). */ public abstract AttributeSet getAttributes(); /** * Get the end of the range for the current occurrence of the tag * being defined and having the same attributes. * @return the end of the range */ public abstract int getEndOffset(); /** * Get the start of the range for the current occurrence of the tag * being defined and having the same attributes. * @return the start of the range (-1 if it can't be found). */ public abstract int getStartOffset(); /** * Move the iterator forward. */ public abstract void next(); /** * Indicates whether or not the iterator currently represents an occurrence * of the tag. * @return true if the iterator currently represents an occurrence of the * tag. */ public abstract boolean isValid(); /** * Type of tag this iterator represents. * @return the tag. */ public abstract HTML.Tag getTag(); } public class BlockElement extends AbstractDocument.BranchElement { public BlockElement (Element parent, AttributeSet a) { super(parent, a); } /** * Gets the resolving parent. Since HTML attributes are not * inherited at the model level, this returns null. */ public AttributeSet getResolveParent() { return null; } /** * Gets the name of the element. * * @return the name of the element if it exists, null otherwise. */ public String getName() { Object tag = getAttribute(StyleConstants.NameAttribute); String name = null; if (tag != null) name = tag.toString(); return name; } } /** * RunElement represents a section of text that has a set of * HTML character level attributes assigned to it. */ public class RunElement extends AbstractDocument.LeafElement { /** * Constructs an element that has no children. It represents content * within the document. * * @param parent - parent of this * @param a - elements attributes * @param start - the start offset >= 0 * @param end - the end offset */ public RunElement(Element parent, AttributeSet a, int start, int end) { super(parent, a, start, end); } /** * Gets the name of the element. * * @return the name of the element if it exists, null otherwise. */ public String getName() { Object tag = getAttribute(StyleConstants.NameAttribute); String name = null; if (tag != null) name = tag.toString(); return name; } /** * Gets the resolving parent. HTML attributes do not inherit at the * model level, so this method returns null. * * @return null */ public AttributeSet getResolveParent() { return null; } } /** * A reader to load an HTMLDocument with HTML structure. * * @author Anthony Balkissoon abalkiss at redhat dot com */ public class HTMLReader extends HTMLEditorKit.ParserCallback { /** Holds the current character attribute set **/ protected MutableAttributeSet charAttr = new SimpleAttributeSet(); protected Vector parseBuffer = new Vector(); /** A stack for character attribute sets **/ Stack charAttrStack = new Stack(); /** * The parse stack. This stack holds HTML.Tag objects that reflect the * current position in the parsing process. */ private Stack parseStack = new Stack(); /** A mapping between HTML.Tag objects and the actions that handle them **/ HashMap tagToAction; /** Tells us whether we've received the '</html>' tag yet **/ boolean endHTMLEncountered = false; /** Variables related to the constructor with explicit insertTag **/ int popDepth, pushDepth, offset; HTML.Tag insertTag; boolean insertTagEncountered = false; /** A temporary variable that helps with the printing out of debug information **/ boolean debug = false; void print (String line) { if (debug) System.out.println (line); } public class TagAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. By default this does nothing. */ public void start(HTML.Tag t, MutableAttributeSet a) { // Nothing to do here. } /** * Called when an end tag is seen for one of the types of tags associated * with this Action. By default does nothing. */ public void end(HTML.Tag t) { // Nothing to do here. } } public class BlockAction extends TagAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) { // Tell the parse buffer to open a new block for this tag. blockOpen(t, a); } /** * Called when an end tag is seen for one of the types of tags associated * with this Action. */ public void end(HTML.Tag t) { // Tell the parse buffer to close this block. blockClose(t); } } public class CharacterAction extends TagAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) { // Put the old attribute set on the stack. pushCharacterStyle(); // And create the new one by adding the attributes in <code>a</code>. if (a != null) charAttr.addAttribute(t, a.copyAttributes()); } /** * Called when an end tag is seen for one of the types of tags associated * with this Action. */ public void end(HTML.Tag t) { popCharacterStyle(); } } public class FormAction extends SpecialAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) { // FIXME: Implement. print ("FormAction.start not implemented"); } /** * Called when an end tag is seen for one of the types of tags associated * with this Action. */ public void end(HTML.Tag t) { // FIXME: Implement. print ("FormAction.end not implemented"); } } public class HiddenAction extends TagAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) { // FIXME: Implement. print ("HiddenAction.start not implemented"); } /** * Called when an end tag is seen for one of the types of tags associated * with this Action. */ public void end(HTML.Tag t) { // FIXME: Implement. print ("HiddenAction.end not implemented"); } } public class IsindexAction extends TagAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) { // FIXME: Implement. print ("IsindexAction.start not implemented"); } /** * Called when an end tag is seen for one of the types of tags associated * with this Action. */ public void end(HTML.Tag t) { // FIXME: Implement. print ("IsindexAction.end not implemented"); } } public class ParagraphAction extends BlockAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) { // FIXME: What else must be done here? blockOpen(t, a); } /** * Called when an end tag is seen for one of the types of tags associated * with this Action. */ public void end(HTML.Tag t) { // FIXME: What else must be done here? blockClose(t); } } public class PreAction extends BlockAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) { // FIXME: Implement. print ("PreAction.start not implemented"); } /** * Called when an end tag is seen for one of the types of tags associated * with this Action. */ public void end(HTML.Tag t) { // FIXME: Implement. print ("PreAction.end not implemented"); } } public class SpecialAction extends TagAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) { // FIXME: Implement. print ("SpecialAction.start not implemented"); } /** * Called when an end tag is seen for one of the types of tags associated * with this Action. */ public void end(HTML.Tag t) { // FIXME: Implement. print ("SpecialAction.end not implemented"); } } class AreaAction extends TagAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) { // FIXME: Implement. print ("AreaAction.start not implemented"); } /** * Called when an end tag is seen for one of the types of tags associated * with this Action. */ public void end(HTML.Tag t) { // FIXME: Implement. print ("AreaAction.end not implemented"); } } class BaseAction extends TagAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) { // FIXME: Implement. print ("BaseAction.start not implemented"); } /** * Called when an end tag is seen for one of the types of tags associated * with this Action. */ public void end(HTML.Tag t) { // FIXME: Implement. print ("BaseAction.end not implemented"); } } class HeadAction extends BlockAction { /** * This method is called when a start tag is seen for one of the types * of tags associated with this Action. */ public void start(HTML.Tag t, MutableAttributeSet a) { // FIXME: Implement. print ("HeadAction.start not implemented: "+t);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?