/** * 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()); } }
void read(InputStream in, Document doc) throws IOException { EditorKit kit = getEditorKit(); try { kit.read(in, doc, 0); } catch (ChangedCharSetException ccse) { // ignored, may be in the future will be processed throw ccse; } catch (BadLocationException ble) { throw new IOException(ble); } }
protected void handleEmptyTag(final TagElement tag) throws ChangedCharSetException { if (!ignoreCharSet && (tag.getHTMLTag() == HTML.Tag.META)) { String httpEquivValue = (String) getAttributes().getAttribute(HTTP_EQUIV); String contentValue = (String) getAttributes().getAttribute(CONTENT); if (httpEquivValue != null && contentValue != null && httpEquivValue.equalsIgnoreCase(CONTENT_TYPE) && contentValue.toLowerCase().contains(CHARSET)) { // notice that always here ignoreCharSet will be false throw new ChangedCharSetException(contentValue, ignoreCharSet); } } callback.handleSimpleTag( tag.getHTMLTag(), getAttributes(), getCurrentPos()); }
private void openDocument(File whatFile, HTMLEditorKit.ParserCallback cb) throws IOException, BadLocationException { if (whatFile == null) { whatFile = getFileFromChooser(".", JFileChooser.OPEN_DIALOG, extsHTML, Translatrix.getTranslationString("FiletypeHTML")); } if (whatFile != null) { try { loadDocument(whatFile, null, cb); } catch (ChangedCharSetException ccse) { String charsetType = ccse.getCharSetSpec().toLowerCase(); int pos = charsetType.indexOf("charset"); if (pos == -1) { throw ccse; } while (pos < charsetType.length() && charsetType.charAt(pos) != '=') { pos++; } pos++; // Places file cursor past the equals sign (=) String whatEncoding = charsetType.substring(pos).trim(); loadDocument(whatFile, whatEncoding, cb); } } refreshOnUpdate(); }
/** * Create a legal context for a tag. */ void legalTagContext(TagElement tag) throws ChangedCharSetException { if (legalElementContext(tag.getElement())) { markFirstTime(tag.getElement()); return; } // Avoid putting a block tag in a flow tag. if (tag.breaksFlow() && (stack != null) && !stack.tag.breaksFlow()) { endTag(true); legalTagContext(tag); return; } // Avoid putting something wierd in the head of the document. for (TagStack s = stack ; s != null ; s = s.next) { if (s.tag.getElement() == dtd.head) { while (stack != s) { endTag(true); } endTag(true); legalTagContext(tag); return; } } // Everything failed error("tag.unexpected", tag.getElement().getName()); }
/** * Error context. Something went wrong, make sure we are in * the document's body context */ void errorContext() throws ChangedCharSetException { for (; (stack != null) && (stack.tag.getElement() != dtd.body) ; stack = stack.next) { handleEndTag(stack.tag); } if (stack == null) { legalElementContext(dtd.body); startTag(makeTag(dtd.body, true)); } }
/** * 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"); } }
void m() throws IOException { Collection c = null; for (Object object : c) { try{ throw new IOException(); }catch(ChangedCharSetException e){ } } }
@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)); } }
protected void startTag(final TagElement tag) throws ChangedCharSetException { if (isCurrentTagSimple) { handleEmptyTag(tag); } else { handleStartTag(tag); } }
/** * This method is called by the lexer, when a token that looks like * a closing tag is found in the parsed stream. * * @param htmlTag a {@link HTMLTag} element that contains all the * information related to the closing tag, that was found in the parsed * stream. * */ public void iHaveNewEndTag(final HTMLTag htmlTag) { currentLine = htmlTag.getLine() + 1; String tagName = htmlTag.getName(); Element element = dtd.elementHash.get(tagName); TagElement currentTag; if (element != null) { currentTag = new TagElement(element); flushHtmlText(currentTag.breaksFlow()); } else { handleUnrecognizedError(htmlTag); element = new Element( -1, tagName, false, false, null, null, -1, null, null, null); currentTag = new TagElement(element); flushHtmlText(currentTag.breaksFlow()); try { attributes.addAttribute("endtag", Boolean.TRUE); handleEmptyTag(currentTag); } catch (ChangedCharSetException e) { // this shouldn't happen throw new AssertionError(); } } currentStartPos = htmlTag.getOffset(); currentEndPos = htmlTag.getEndPos(); boolean mustBeReported = manageEndElement(element); if (mustBeReported) { handleEndTag(currentTag); } }