8265167: Richer Text Editors
Reviewed-by: prr, rhalade, mschoene, azvegint
This commit is contained in:
parent
a48251cb4a
commit
fde3839c0c
@ -233,25 +233,52 @@ abstract class RTFParser extends AbstractFilter
|
|||||||
currentCharacters.append(ch);
|
currentCharacters.append(ch);
|
||||||
} else {
|
} else {
|
||||||
/* TODO: Test correct behavior of \bin keyword */
|
/* TODO: Test correct behavior of \bin keyword */
|
||||||
|
|
||||||
if (pendingKeyword.equals("bin")) { /* magic layer-breaking kwd */
|
if (pendingKeyword.equals("bin")) { /* magic layer-breaking kwd */
|
||||||
long parameter = Long.parseLong(currentCharacters.toString());
|
long parameter = 0L;
|
||||||
|
try {
|
||||||
|
parameter = Long.parseLong(currentCharacters.toString());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
warning("Illegal number format " + currentCharacters.toString()
|
||||||
|
+ " in \bin tag");
|
||||||
|
pendingKeyword = null;
|
||||||
|
currentCharacters = new StringBuffer();
|
||||||
|
state = S_text;
|
||||||
|
// Delimiters here are interpreted as text too
|
||||||
|
if (!Character.isWhitespace(ch))
|
||||||
|
write(ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
pendingKeyword = null;
|
pendingKeyword = null;
|
||||||
state = S_inblob;
|
state = S_inblob;
|
||||||
|
int maxBytes = 4 * 1024 * 1024;
|
||||||
binaryBytesLeft = parameter;
|
binaryBytesLeft = parameter;
|
||||||
if (binaryBytesLeft > Integer.MAX_VALUE)
|
|
||||||
binaryBuf = new ByteArrayOutputStream(Integer.MAX_VALUE);
|
if (binaryBytesLeft > maxBytes) {
|
||||||
else
|
binaryBuf = new ByteArrayOutputStream(maxBytes);
|
||||||
binaryBuf = new ByteArrayOutputStream((int)binaryBytesLeft);
|
} else if (binaryBytesLeft < 0) {
|
||||||
|
binaryBytesLeft = 0;
|
||||||
|
binaryBuf = new ByteArrayOutputStream((int)binaryBytesLeft);
|
||||||
|
} else {
|
||||||
|
binaryBuf = new ByteArrayOutputStream((int) binaryBytesLeft);
|
||||||
|
}
|
||||||
savedSpecials = specialsTable;
|
savedSpecials = specialsTable;
|
||||||
specialsTable = allSpecialsTable;
|
specialsTable = allSpecialsTable;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parameter = Integer.parseInt(currentCharacters.toString());
|
int parameter = 0;
|
||||||
ok = handleKeyword(pendingKeyword, parameter);
|
try {
|
||||||
if (!ok)
|
parameter = Integer.parseInt(currentCharacters.toString());
|
||||||
warning("Unknown keyword: " + pendingKeyword +
|
ok = handleKeyword(pendingKeyword, parameter);
|
||||||
" (param " + currentCharacters + ")");
|
if (!ok) {
|
||||||
|
warning("Unknown keyword: " + pendingKeyword +
|
||||||
|
" (param " + currentCharacters + ")");
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
warning("Illegal number format " + currentCharacters.toString()
|
||||||
|
+ " in " + pendingKeyword + " tag");
|
||||||
|
}
|
||||||
pendingKeyword = null;
|
pendingKeyword = null;
|
||||||
currentCharacters = new StringBuffer();
|
currentCharacters = new StringBuffer();
|
||||||
state = S_text;
|
state = S_text;
|
||||||
@ -280,14 +307,15 @@ abstract class RTFParser extends AbstractFilter
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case S_inblob:
|
case S_inblob:
|
||||||
binaryBuf.write(ch);
|
if (binaryBytesLeft > 0) {
|
||||||
binaryBytesLeft --;
|
binaryBuf.write(ch);
|
||||||
if (binaryBytesLeft == 0) {
|
binaryBytesLeft--;
|
||||||
state = S_text;
|
} else {
|
||||||
specialsTable = savedSpecials;
|
state = S_text;
|
||||||
savedSpecials = null;
|
specialsTable = savedSpecials;
|
||||||
handleBinaryBlob(binaryBuf.toByteArray());
|
savedSpecials = null;
|
||||||
binaryBuf = null;
|
handleBinaryBlob(binaryBuf.toByteArray());
|
||||||
|
binaryBuf = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user