< prev index next >

src/java.desktop/share/classes/javax/swing/text/html/parser/Parser.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 76,91 **** * @author Sunita Mani */ public class Parser implements DTDConstants { ! private char text[] = new char[1024]; private int textpos = 0; private TagElement last; private boolean space; ! private char str[] = new char[128]; private int strpos = 0; /** * The dtd. */ --- 76,91 ---- * @author Sunita Mani */ public class Parser implements DTDConstants { ! private char[] text = new char[1024]; private int textpos = 0; private TagElement last; private boolean space; ! private char[] str = new char[128]; private int strpos = 0; /** * The dtd. */
*** 271,300 **** /** * Called when PCDATA is encountered. * * @param text the section text */ ! protected void handleText(char text[]) { } /** * Called when an HTML title tag is encountered. * * @param text the title text */ ! protected void handleTitle(char text[]) { // default behavior is to call handleText. Subclasses // can override if necessary. handleText(text); } /** * Called when an HTML comment is encountered. * * @param text the comment being handled */ ! protected void handleComment(char text[]) { } /** * Called when the content terminates without closing the HTML comment. */ --- 271,300 ---- /** * Called when PCDATA is encountered. * * @param text the section text */ ! protected void handleText(char[] text) { } /** * Called when an HTML title tag is encountered. * * @param text the title text */ ! protected void handleTitle(char[] text) { // default behavior is to call handleText. Subclasses // can override if necessary. handleText(text); } /** * Called when an HTML comment is encountered. * * @param text the comment being handled */ ! protected void handleComment(char[] text) { } /** * Called when the content terminates without closing the HTML comment. */
*** 384,394 **** } if (space) { if (!ignoreSpace) { // enlarge buffer if needed if (textpos + 1 > text.length) { ! char newtext[] = new char[text.length + 200]; System.arraycopy(text, 0, newtext, 0, text.length); text = newtext; } // output pending space --- 384,394 ---- } if (space) { if (!ignoreSpace) { // enlarge buffer if needed if (textpos + 1 > text.length) { ! char[] newtext = new char[text.length + 200]; System.arraycopy(text, 0, newtext, 0, text.length); text = newtext; } // output pending space
*** 397,407 **** ignoreSpace = true; } } space = false; } ! char newtext[] = new char[textpos]; System.arraycopy(text, 0, newtext, 0, textpos); // Handles cases of bad html where the title tag // was getting lost when we did error recovery. if (tag.getElement().getName().equals("title")) { handleTitle(newtext); --- 397,407 ---- ignoreSpace = true; } } space = false; } ! char[] newtext = new char[textpos]; System.arraycopy(text, 0, newtext, 0, textpos); // Handles cases of bad html where the title tag // was getting lost when we did error recovery. if (tag.getElement().getName().equals("title")) { handleTitle(newtext);
*** 835,870 **** /** * Add a char to the string buffer. */ void addString(int c) { if (strpos == str.length) { ! char newstr[] = new char[str.length + 128]; System.arraycopy(str, 0, newstr, 0, str.length); str = newstr; } str[strpos++] = (char)c; } /** * Get the string that's been accumulated. */ String getString(int pos) { ! char newStr[] = new char[strpos - pos]; System.arraycopy(str, pos, newStr, 0, strpos - pos); strpos = pos; return new String(newStr); } char[] getChars(int pos) { ! char newStr[] = new char[strpos - pos]; System.arraycopy(str, pos, newStr, 0, strpos - pos); strpos = pos; return newStr; } char[] getChars(int pos, int endPos) { ! char newStr[] = new char[endPos - pos]; System.arraycopy(str, pos, newStr, 0, endPos - pos); // REMIND: it's not clear whether this version should set strpos or not // strpos = pos; return newStr; } --- 835,870 ---- /** * Add a char to the string buffer. */ void addString(int c) { if (strpos == str.length) { ! char[] newstr = new char[str.length + 128]; System.arraycopy(str, 0, newstr, 0, str.length); str = newstr; } str[strpos++] = (char)c; } /** * Get the string that's been accumulated. */ String getString(int pos) { ! char[] newStr = new char[strpos - pos]; System.arraycopy(str, pos, newStr, 0, strpos - pos); strpos = pos; return new String(newStr); } char[] getChars(int pos) { ! char[] newStr = new char[strpos - pos]; System.arraycopy(str, pos, newStr, 0, strpos - pos); strpos = pos; return newStr; } char[] getChars(int pos, int endPos) { ! char[] newStr = new char[endPos - pos]; System.arraycopy(str, pos, newStr, 0, endPos - pos); // REMIND: it's not clear whether this version should set strpos or not // strpos = pos; return newStr; }
*** 1032,1053 **** case ';': ch = readCh(); break; } ! char data[] = mapNumericReference(n); return data; } addString('#'); if (!parseIdentifier(false)) { error("ident.expected"); strpos = pos; ! char data[] = {'&', '#'}; return data; } } else if (!parseIdentifier(false)) { ! char data[] = {'&'}; return data; } boolean semicolon = false; --- 1032,1053 ---- case ';': ch = readCh(); break; } ! char[] data = mapNumericReference(n); return data; } addString('#'); if (!parseIdentifier(false)) { error("ident.expected"); strpos = pos; ! char[] data = {'&', '#'}; return data; } } else if (!parseIdentifier(false)) { ! char[] data = {'&'}; return data; } boolean semicolon = false;
*** 1093,1103 **** return new char[0]; } /* given that there is not a match restore the entity reference */ String str = "&" + nm + (semicolon ? ";" : ""); ! char b[] = new char[str.length()]; str.getChars(0, b.length, b, 0); return b; } return ent.getData(); } --- 1093,1103 ---- return new char[0]; } /* given that there is not a match restore the entity reference */ String str = "&" + nm + (semicolon ? ";" : ""); ! char[] b = new char[str.length()]; str.getChars(0, b.length, b, 0); return b; } return ent.getData(); }
*** 1249,1261 **** } } break; case '&': ! char data[] = parseEntityReference(); if (textpos + data.length > text.length) { ! char newtext[] = new char[Math.max(textpos + data.length + 128, text.length * 2)]; System.arraycopy(text, 0, newtext, 0, text.length); text = newtext; } System.arraycopy(data, 0, text, textpos, data.length); textpos += data.length; --- 1249,1261 ---- } } break; case '&': ! char[] data = parseEntityReference(); if (textpos + data.length > text.length) { ! char[] newtext = new char[Math.max(textpos + data.length + 128, text.length * 2)]; System.arraycopy(text, 0, newtext, 0, text.length); text = newtext; } System.arraycopy(data, 0, text, textpos, data.length); textpos += data.length;
*** 1283,1293 **** break; } // output character if (textpos == text.length) { ! char newtext[] = new char[text.length + 128]; System.arraycopy(text, 0, newtext, 0, text.length); text = newtext; } text[textpos++] = (char)c; } --- 1283,1293 ---- break; } // output character if (textpos == text.length) { ! char[] newtext = new char[text.length + 128]; System.arraycopy(text, 0, newtext, 0, text.length); text = newtext; } text[textpos++] = (char)c; }
*** 1393,1403 **** if (strict && delim < 0) { ch = readCh(); break; } ! char data[] = parseEntityReference(); for (int i = 0 ; i < data.length ; i++) { c = data[i]; addString((lower && (c >= 'A') && (c <= 'Z')) ? 'a' + c - 'A' : c); } continue; --- 1393,1403 ---- if (strict && delim < 0) { ch = readCh(); break; } ! char[] data = parseEntityReference(); for (int i = 0 ; i < data.length ; i++) { c = data[i]; addString((lower && (c >= 'A') && (c <= 'Z')) ? 'a' + c - 'A' : c); } continue;
*** 1504,1514 **** attvalue = att.getValue(); } } } } else { ! char str[] = {(char)ch}; error("invalid.tagchar", new String(str), elem.getName()); ch = readCh(); continue; } } else if (!strict && (attributes.isEmpty()) && (ch == '=')) { --- 1504,1514 ---- attvalue = att.getValue(); } } } } else { ! char[] str = {(char)ch}; error("invalid.tagchar", new String(str), elem.getName()); ch = readCh(); continue; } } else if (!strict && (attributes.isEmpty()) && (ch == '=')) {
*** 1524,1534 **** skipSpace(); attvalue = parseAttributeValue(true); error("attvalerr"); return; } else { ! char str[] = {(char)ch}; error("invalid.tagchar", new String(str), elem.getName()); if (!strict) { ch = readCh(); continue; } else { --- 1524,1534 ---- skipSpace(); attvalue = parseAttributeValue(true); error("attvalerr"); return; } else { ! char[] str = {(char)ch}; error("invalid.tagchar", new String(str), elem.getName()); if (!strict) { ch = readCh(); continue; } else {
*** 1672,1682 **** } // send over any text you might see // before parsing and sending the // comment if (textpos != 0) { ! char newtext[] = new char[textpos]; System.arraycopy(text, 0, newtext, 0, textpos); handleText(newtext); lastBlockStartPos = currentBlockStartPos; textpos = 0; } --- 1672,1682 ---- } // send over any text you might see // before parsing and sending the // comment if (textpos != 0) { ! char[] newtext = new char[textpos]; System.arraycopy(text, 0, newtext, 0, textpos); handleText(newtext); lastBlockStartPos = currentBlockStartPos; textpos = 0; }
*** 2222,2234 **** } if (last.breaksFlow()) { space = false; } } ! char data[] = parseEntityReference(); if (textpos + data.length + 1 > text.length) { ! char newtext[] = new char[Math.max(textpos + data.length + 128, text.length * 2)]; System.arraycopy(text, 0, newtext, 0, text.length); text = newtext; } if (space) { space = false; --- 2222,2234 ---- } if (last.breaksFlow()) { space = false; } } ! char[] data = parseEntityReference(); if (textpos + data.length + 1 > text.length) { ! char[] newtext = new char[Math.max(textpos + data.length + 128, text.length * 2)]; System.arraycopy(text, 0, newtext, 0, text.length); text = newtext; } if (space) { space = false;
*** 2304,2314 **** } } // enlarge buffer if needed if (textpos + 2 > text.length) { ! char newtext[] = new char[text.length + 128]; System.arraycopy(text, 0, newtext, 0, text.length); text = newtext; } // output pending space --- 2304,2314 ---- } } // enlarge buffer if needed if (textpos + 2 > text.length) { ! char[] newtext = new char[text.length + 128]; System.arraycopy(text, 0, newtext, 0, text.length); text = newtext; } // output pending space
*** 2410,2420 **** * NOTE: If the current encoding is bogus, and we read too much * (past the content-type) we may suffer a MalformedInputException. For * this reason the initial size is 1 and when the body is encountered the * size is adjusted to 256. */ ! private char buf[] = new char[1]; private int pos; private int len; /* tracks position relative to the beginning of the document. --- 2410,2420 ---- * NOTE: If the current encoding is bogus, and we read too much * (past the content-type) we may suffer a MalformedInputException. For * this reason the initial size is 1 and when the body is encountered the * size is adjusted to 256. */ ! private char[] buf = new char[1]; private int pos; private int len; /* tracks position relative to the beginning of the document.
< prev index next >