📄 compositetagscanner.java
字号:
// If there is something, we close off all the tags // walked over and continue on as if nothing // happened. Vector attributes = new Vector (); attributes.addElement (new Attribute (name, null)); Tag opener = lexer.getNodeFactory ().createTagNode ( lexer.getPage (), next.getStartPosition (), next.getEndPosition (), attributes); scanner = opener.getThisScanner (); if ((null != scanner) && (scanner == this)) { // uh-oh int index = -1; for (int i = stack.size () - 1; (-1 == index) && (i >= 0); i--) { // short circuit here... assume everything on the stack has this as it's scanner // we'll need to stop if either of those conditions isn't met Tag boffo = (Tag)stack.elementAt (i); if (name.equals (boffo.getTagName ())) index = i; else if (isTagToBeEndedFor (boffo, next)) // check DTD index = i; } if (-1 != index) { // finish off the current one first finishTag (ret, lexer); addChild ((Tag)stack.elementAt (stack.size () - 1), ret); for (int i = stack.size () - 1; i > index; i--) { Tag fred = (Tag)stack.remove (i); finishTag (fred, lexer); addChild ((Tag)stack.elementAt (i - 1), fred); } ret = (Tag)stack.remove (index); node = null; } else addChild (ret, next); // default behaviour } else addChild (ret, next); // default behaviour } else addChild (ret, next); } } else { addChild (ret, node); node.doSemanticAction (); } } if (!mUseJVMStack) { // handle coming out of fake recursion if (null == node) { int depth = stack.size (); if (0 != depth) { node = stack.elementAt (depth - 1); if (node instanceof Tag) { Tag precursor = (Tag)node; scanner = precursor.getThisScanner (); if (scanner == this) { stack.remove (depth - 1); finishTag (ret, lexer); addChild (precursor, ret); ret = precursor; } else node = null; // normal recursion } else node = null; // normal recursion } } } } while (null != node); finishTag (ret, lexer); return (ret); } /** * Add a child to the given tag. * @param parent The parent tag. * @param child The child node. */ protected void addChild (Tag parent, Node child) { if (null == parent.getChildren ()) parent.setChildren (new NodeList ()); child.setParent (parent); parent.getChildren ().add (child); } /** * Finish off a tag. * Perhap add a virtual end tag. * Set the end tag parent as this tag. * Perform the semantic acton. * @param tag The tag to finish off. * @param lexer A lexer positioned at the end of the tag. */ protected void finishTag (Tag tag, Lexer lexer) throws ParserException { if (null == tag.getEndTag ()) tag.setEndTag (createVirtualEndTag (tag, lexer, lexer.getPage (), lexer.getCursor ().getPosition ())); tag.getEndTag ().setParent (tag); tag.doSemanticAction (); } /** * Creates an end tag with the same name as the given tag. * @param tag The tag to end. * @param lexer The object containg the node factory. * @param page The page the tag is on (virtually). * @param position The offset into the page at which the tag is to * be anchored. * @return An end tag with the name '"/" + tag.getTagName()' and a start * and end position at the given position. The fact these positions are * equal may be used to distinguish it as a virtual tag later on. */ protected Tag createVirtualEndTag (Tag tag, Lexer lexer, Page page, int position) throws ParserException { Tag ret; String name; Vector attributes; name = "/" + tag.getRawTagName (); attributes = new Vector (); attributes.addElement (new Attribute (name, (String)null)); ret = lexer.getNodeFactory ().createTagNode ( page, position, position, attributes); return (ret); } /** * Determine if the current tag should be terminated by the given tag. * Examines the 'enders' or 'end tag enders' lists of the current tag * for a match with the given tag. Which list is chosen depends on whether * tag is an end tag ('end tag enders') or not ('enders'). * @param current The tag that might need to be ended. * @param tag The candidate tag that might end the current one. * @return <code>true</code> if the name of the given tag is a member of * the appropriate list. */ public final boolean isTagToBeEndedFor (Tag current, Tag tag) { String name; String[] ends; boolean ret; ret = false; name = tag.getTagName (); if (tag.isEndTag ()) ends = current.getEndTagEnders (); else ends = current.getEnders (); for (int i = 0; i < ends.length; i++) if (name.equalsIgnoreCase (ends[i])) { ret = true; break; } return (ret); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -