/** * A hook, for operations, preceeding call to handleText. * Handle text in a string buffer. * In non - preformatted mode, all line breaks immediately following the * start tag and immediately before an end tag is discarded, * \r, \n and \t are replaced by spaces, multiple space are replaced * by the single one and the result is moved into array, * passing it to handleText(). */ protected void _handleText() { char[] text; if (preformatted > 0) text = textProcessor.preprocessPreformatted(buffer); else text = textProcessor.preprocess(buffer); if (text != null && text.length > 0 // According to the specs we need to discard whitespace immediately // before a closing tag. && (text.length > 1 || text[0] != ' ' || ! TAG_CLOSE.matches(this))) { TagElement pcdata = new TagElement(dtd.getElement("#pcdata")); attributes = htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET; _handleEmptyTag(pcdata); handleText(text); if (titleOpen) title.append(text); } }
/** * Handle a complete element, when the tag content is already present in the * buffer and both starting and heading tags behind. This is called * in the case when the tag text must not be parsed for the nested * elements (elements STYLE and SCRIPT). */ private void _handleCompleteElement(TagElement tag) { _handleStartTag(tag); // Suppress inclusion of the SCRIPT ans STYLE texts into the title. HTML.Tag h = tag.getHTMLTag(); if (h == HTML.Tag.SCRIPT || h == HTML.Tag.STYLE) { boolean tmp = titleOpen; titleOpen = false; _handleText(); titleOpen = tmp; } else _handleText(); _handleEndTag(tag); }
/** * A hooks for operations, preceeding call to handleEmptyTag(). * Handle the tag with no content, like <br>. As no any * nested tags are expected, the tag validator is not involved. * @param tag The tag being handled. */ private void _handleEmptyTag(TagElement tag) { try { validator.validateTag(tag, attributes); handleEmptyTag(tag); HTML.Tag h = tag.getHTMLTag(); // When a block tag is closed, consume whitespace that follows after // it. // For some unknown reason a FRAME tag is not treated as block element. // However in this case it should be treated as such. if (isBlock(h)) optional(WS); } catch (ChangedCharSetException ex) { error("Changed charset exception:", ex.getMessage()); } }
/** * A hooks for operations, preceeding call to handleStartTag(). * The method is called when the HTML opening tag ((like <table>) * is found. * Package-private to avoid an accessor method. * @param tag The tag */ void _handleStartTag(TagElement tag) { validator.openTag(tag, attributes); startingTag(tag); handleStartTag(tag); HTML.Tag h = tag.getHTMLTag(); if (isBlock(h)) optional(WS); if (h.isPreformatted()) preformatted++; if (h == HTML.Tag.TITLE) { if (titleHandled) error("Repetetive <TITLE> tag"); titleOpen = true; titleHandled = false; } }
private TagElement makeTagElement(String name, boolean isSupposed) { Element e = dtd.elementHash.get(name.toLowerCase()); if (e == null) { error("Unknown tag <" + name + ">"); e = dtd.getElement(name); e.name = name.toUpperCase(); e.index = -1; } if (!documentTags.contains(e.name)) { markFirstTime(e); documentTags.add(e.name); } return makeTag(e, isSupposed); }
@Override protected void handleEmptyTag(TagElement tag) { if (parserState == ParserState.METHOD && HTML.Tag.CODE.equals(tag.getHTMLTag())) { if (methodWithTypes != null) { // process collected method data methods.add(methodWithTypes); this.methodText.put(methodWithTypes, getArgSignature()); // clear the text builder for next method methodTextBuilder.delete(0, methodTextBuilder.length()); methodWithTypes = null; } parserState = ParserState.METHOD_SUMMARY; } else if (parserState == ParserState.METHOD_SUMMARY && !methods.isEmpty() && HTML.Tag.TABLE.equals(tag.getHTMLTag())) { // end of method summary table parserState = ParserState.INIT; } }
protected final void handleEmptyTag(TagElement tag) throws javax.swing.text.ChangedCharSetException { callBack.handleSimpleTag(tag.getHTMLTag(), getAttributes(), hTag.where.startPosition ); }
protected final void handleStartTag(TagElement tag) { SimpleAttributeSet attributes = gnu.getAttributes(); if (tag.fictional()) attributes.addAttribute(ParserCallback.IMPLIED, Boolean.TRUE); callBack.handleStartTag(tag.getHTMLTag(), attributes, hTag.where.startPosition ); }
/** * Actions that are also required if the closing action was * initiated by the tag validator. * Package-private to avoid an accessor method. */ void _handleEndTag_remaining(TagElement tag) { HTML.Tag h = tag.getHTMLTag(); handleEndTag(tag); endTag(tag.fictional()); if (h.isPreformatted()) preformatted--; if (preformatted < 0) preformatted = 0; // When a block tag is closed, consume whitespace that follows after // it. if (isBlock(h)) optional(WS); if (h == HTML.Tag.TITLE) { titleOpen = false; titleHandled = true; char[] a = new char[ title.length() ]; title.getChars(0, a.length, a, 0); handleTitle(a); } }
/** * This should fire additional actions in response to the * ChangedCharSetException. The current implementation * does nothing. * @param tag */ private void startingTag(TagElement tag) { try { startTag(tag); } catch (ChangedCharSetException cax) { error("Invalid change of charset"); } }
/** * Handle the tag with no content. * @param tag the tag to handle. */ protected void handleEmptyTag(TagElement tag) { String name = tag.getHTMLTag().toString(); if (name.equalsIgnoreCase("#pcdata")) return; Node c = createNode(name); cursor.appendChild(c); }
/** * Close the given tag. Close and reopen all nested tags. * @param tag the tag to close. */ protected void handleEndTag(TagElement tag) { String name = tag.getHTMLTag().toString(); String nname = cursor.getNodeName(); // Closing the current tag. if (nname != null && nname.equalsIgnoreCase(name)) { cursor = cursor.getParentNode(); } else { Node nCursor = cursor.getParentNode(); // Remember the opened nodes. LinkedList open = new LinkedList(); Node close = cursor; while (close != null && !close.getNodeName().equalsIgnoreCase(name)) { if (close != document) open.addFirst(close); close = close.getParentNode(); } if (close == null) cursor = document; else cursor = close.getParentNode(); // Insert the copies of the opened nodes. Iterator iter = open.iterator(); while (iter.hasNext()) { Node item = (Node) iter.next(); cursor.appendChild(item); cursor = item; } } }
/** * Handle the start tag by inserting the HTML element. * @param tag the tag to handle. */ protected void handleStartTag(TagElement tag) { HTML.Tag h = tag.getHTMLTag(); Node c = createNode(h.toString()); cursor.appendChild(c); cursor = c; }
@Override protected void handleStartTag(TagElement tag) { if (tag == null) return; HTML.Tag htmlTag = tag.getHTMLTag(); if (htmlTag == HTML.Tag.APPLET || htmlTag == HTML.Tag.OBJECT) { if (startElement != null) { throw new RuntimeException(htmlTag+" inside "+startElement); } startElement = htmlTag; appletInfo = new AppletInfo(); appletInfo.setTag(htmlTag.toString()); list.add(appletInfo); appletInfo.setDocumentBase(documentBase); SimpleAttributeSet attributes = getAttributes(); appletInfo.setParameter("WIDTH", (String)attributes.getAttribute(HTML.Attribute.WIDTH)); appletInfo.setParameter("HEIGHT", (String)attributes.getAttribute(HTML.Attribute.HEIGHT)); appletInfo.setParameter("CODE", (String)attributes.getAttribute(HTML.Attribute.CODE)); appletInfo.setParameter("ARCHIVE", (String)attributes.getAttribute(HTML.Attribute.ARCHIVE)); if (htmlTag != HTML.Tag.OBJECT) { appletInfo.setParameter("CODEBASE", (String)attributes.getAttribute(HTML.Attribute.CODEBASE)); } } }
@Override protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException { HTML.Tag htmlTag = tag.getHTMLTag(); if (appletInfo != null && htmlTag == HTML.Tag.PARAM) { SimpleAttributeSet attributes = getAttributes(); appletInfo.setParameter((String)attributes.getAttribute(HTML.Attribute.NAME), (String)attributes.getAttribute(HTML.Attribute.VALUE)); } }