📄 prototypicalnodefactory.java
字号:
put (ids[i].toUpperCase (Locale.ENGLISH), tag); } /** * Unregister a tag. * Unregisters the given tag from every {@link Tag#getIds() id} the tag has. * <p><strong>The ids are converted to uppercase to undo the operation * of registerTag.</strong> * @param tag The tag to unregister. */ public void unregisterTag (Tag tag) { String[] ids; ids = tag.getIds (); for (int i = 0; i < ids.length; i++) remove (ids[i].toUpperCase (Locale.ENGLISH)); } /** * Register all known tags in the tag package. * Registers tags from the {@link org.htmlparser.tags tag package} by * calling {@link #registerTag(Tag) registerTag()}. * @return 'this' nodefactory as a convenience. */ public PrototypicalNodeFactory registerTags () { registerTag (new AppletTag ()); registerTag (new BaseHrefTag ()); registerTag (new Bullet ()); registerTag (new BulletList ()); registerTag (new DefinitionList ()); registerTag (new DefinitionListBullet ()); registerTag (new DoctypeTag ()); registerTag (new FormTag ()); registerTag (new FrameSetTag ()); registerTag (new FrameTag ()); registerTag (new HeadingTag ()); registerTag (new ImageTag ()); registerTag (new InputTag ()); registerTag (new JspTag ()); registerTag (new LabelTag ()); registerTag (new LinkTag ()); registerTag (new MetaTag ()); registerTag (new ObjectTag ()); registerTag (new OptionTag ()); registerTag (new ParagraphTag ()); registerTag (new ProcessingInstructionTag ()); registerTag (new ScriptTag ()); registerTag (new SelectTag ()); registerTag (new StyleTag ()); registerTag (new TableColumn ()); registerTag (new TableHeader ()); registerTag (new TableRow ()); registerTag (new TableTag ()); registerTag (new TextareaTag ()); registerTag (new TitleTag ()); registerTag (new Div ()); registerTag (new Span ()); registerTag (new BodyTag ()); registerTag (new HeadTag ()); registerTag (new Html ()); return (this); } /** * Get the object that is cloned to generate text nodes. * @return The prototype for {@link Text} nodes. * @see #setTextPrototype */ public Text getTextPrototype () { return (mText); } /** * Set the object to be used to generate text nodes. * @param text The prototype for {@link Text} nodes. * If <code>null</code> the prototype is set to the default * ({@link TextNode}). * @see #getTextPrototype */ public void setTextPrototype (Text text) { if (null == text) mText = new TextNode (null, 0, 0); else mText = text; } /** * Get the object that is cloned to generate remark nodes. * @return The prototype for {@link Remark} nodes. * @see #setRemarkPrototype */ public Remark getRemarkPrototype () { return (mRemark); } /** * Set the object to be used to generate remark nodes. * @param remark The prototype for {@link Remark} nodes. * If <code>null</code> the prototype is set to the default * ({@link RemarkNode}). * @see #getRemarkPrototype */ public void setRemarkPrototype (Remark remark) { if (null == remark) mRemark = new RemarkNode (null, 0, 0); else mRemark = remark; } /** * Get the object that is cloned to generate tag nodes. * Clones of this object are returned from {@link #createTagNode} when no * specific tag is found in the list of registered tags. * @return The prototype for {@link Tag} nodes. * @see #setTagPrototype */ public Tag getTagPrototype () { return (mTag); } /** * Set the object to be used to generate tag nodes. * Clones of this object are returned from {@link #createTagNode} when no * specific tag is found in the list of registered tags. * @param tag The prototype for {@link Tag} nodes. * If <code>null</code> the prototype is set to the default * ({@link TagNode}). * @see #getTagPrototype */ public void setTagPrototype (Tag tag) { if (null == tag) mTag = new TagNode (null, 0, 0, null); else mTag = tag; } // // NodeFactory interface // /** * Create a new string node. * @param page The page the node is on. * @param start The beginning position of the string. * @param end The ending position of the string. * @return A text node comprising the indicated characters from the page. */ public Text createStringNode (Page page, int start, int end) { Text ret; try { ret = (Text)(getTextPrototype ().clone ()); ret.setPage (page); ret.setStartPosition (start); ret.setEndPosition (end); } catch (CloneNotSupportedException cnse) { ret = new TextNode (page, start, end); } return (ret); } /** * Create a new remark node. * @param page The page the node is on. * @param start The beginning position of the remark. * @param end The ending positiong of the remark. * @return A remark node comprising the indicated characters from the page. */ public Remark createRemarkNode (Page page, int start, int end) { Remark ret; try { ret = (Remark)(getRemarkPrototype ().clone ()); ret.setPage (page); ret.setStartPosition (start); ret.setEndPosition (end); } catch (CloneNotSupportedException cnse) { ret = new RemarkNode (page, start, end); } return (ret); } /** * Create a new tag node. * Note that the attributes vector contains at least one element, * which is the tag name (standalone attribute) at position zero. * This can be used to decide which type of node to create, or * gate other processing that may be appropriate. * @param page The page the node is on. * @param start The beginning position of the tag. * @param end The ending positiong of the tag. * @param attributes The attributes contained in this tag. * @return A tag node comprising the indicated characters from the page. */ public Tag createTagNode (Page page, int start, int end, Vector attributes) { Attribute attribute; String id; Tag prototype; Tag ret; ret = null; if (0 != attributes.size ()) { attribute = (Attribute)attributes.elementAt (0); id = attribute.getName (); if (null != id) { try { id = id.toUpperCase (Locale.ENGLISH); if (!id.startsWith ("/")) { if (id.endsWith ("/")) id = id.substring (0, id.length () - 1); prototype = (Tag)mBlastocyst.get (id); if (null != prototype) { ret = (Tag)prototype.clone (); ret.setPage (page); ret.setStartPosition (start); ret.setEndPosition (end); ret.setAttributesEx (attributes); } } } catch (CloneNotSupportedException cnse) { // default to creating a generic one } } } if (null == ret) { // generate a generic node try { ret = (Tag)getTagPrototype ().clone (); ret.setPage (page); ret.setStartPosition (start); ret.setEndPosition (end); ret.setAttributesEx (attributes); } catch (CloneNotSupportedException cnse) { ret = new TagNode (page, start, end, attributes); } } return (ret); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -