The RtfDocument stores all document related data and also the main data stream.
INTERNAL CLASS - NOT TO BE USED DIRECTLY
| Method from com.lowagie.text.rtf.document.RtfDocument Detail: |
public void add(RtfBasicElement element) {
try {
if(element instanceof RtfInfoElement) {
this.documentHeader.addInfoElement((RtfInfoElement) element);
} else {
if(element instanceof RtfImage) {
((RtfImage) element).setTopLevelElement(true);
}
element.writeContent( this.data.getOutputStream() );
this.lastElementWritten = element;
}
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
Adds an element to the rtf document |
public void filterSpecialChar(OutputStream out,
String str,
boolean useHex,
boolean softLineBreaks) throws IOException {
if(out == null) {
throw new NullPointerException("null OutpuStream");
}
final boolean alwaysUseUniCode = this.documentSettings.isAlwaysUseUnicode();
if(str == null) {
return;
}
final int len = str.length();
if(len == 0) {
return;
}
for(int k = 0; k < len; k++) {
final char c = str.charAt(k);
if(c < 0x20) {
//allow return and tab only
if(c == '\n') {
out.write(softLineBreaks ? FSC_LINE : FSC_PAR);
} else if(c == '\t') {
out.write(FSC_TAB);
} else {
out.write('?');
}
} else if((c == '\\') || (c == '{') || (c == '}')) {
//escape
out.write(FSC_BACKSLASH);
out.write(c);
} else if((c == '$') && (len-k >= FSC_NEWPAGE.length) && subMatch(str, k, FSC_NEWPAGE)) {
out.write(FSC_PAGE_PAR);
k += FSC_NEWPAGE.length-1;
} else {
if((c > 0xff) || ((c > 'z') && alwaysUseUniCode)) {
if(useHex && (c < = 0xff)) {
//encode as 2 char hex string
out.write(FSC_HEX_PREFIX);
out.write(RtfImage.byte2charLUT, c*2, 2);
} else {
//encode as decimal, signed short value
out.write(FSC_UNI_PREFIX);
String s = Short.toString((short)c);
for(int x = 0; x < s.length(); x++) {
out.write(s.charAt(x));
}
out.write('?');
}
} else {
out.write(c);
}
}
}
}
Writes the given string to the given OutputStream encoding the string characters. |
public boolean getAutogenerateTOCEntries() {
return this.autogenerateTOCEntries;
}
Get whether to automatically generate table of contents entries |
public RtfDocumentHeader getDocumentHeader() {
return this.documentHeader;
}
Gets the RtfDocumentHeader of this RtfDocument |
public RtfDocumentSettings getDocumentSettings() {
return this.documentSettings;
}
Gets the RtfDocumentSettings that specify how the rtf document is generated. |
public RtfBasicElement getLastElementWritten() {
return this.lastElementWritten;
}
Gets the last RtfBasicElement that was directly added to the RtfDocument. |
public RtfMapper getMapper() {
return this.mapper;
}
Gets the RtfMapper object of this RtfDocument |
public int getRandomInt() {
Integer newInt = null;
do {
// do {
newInt = new Integer((int) (Math.random() * Integer.MAX_VALUE));
// } while(newInt.intValue() < = -1 && newInt.intValue() >= -5);
} while(this.previousRandomInts.contains(newInt));
this.previousRandomInts.add(newInt);
return newInt.intValue();
}
Generates a random integer that is unique with respect to the document.
Will not return a number between -1 and -5 because some values in that range are invalid. |
public void open() {
try {
switch(this.documentSettings.getDataCacheStyle()) {
case RtfDataCache.CACHE_MEMORY_EFFICIENT:
this.data = new RtfEfficientMemoryCache();
break;
case RtfDataCache.CACHE_MEMORY:
this.data = new RtfMemoryCache();
break;
case RtfDataCache.CACHE_DISK:
this.data = new RtfDiskCache();
break;
default:
throw new RuntimeException("unknown");
}
} catch(IOException ioe) {
System.err.println("Could not initialize disk cache. Using memory cache.");
ioe.printStackTrace();
this.data = new RtfMemoryCache();
}
}
Opens the RtfDocument and initializes the data cache. If the data cache is
set to CACHE_DISK, but the cache cannot be initialized then the memory cache
is used. |
public final void outputDebugLinebreak(OutputStream result) throws IOException {
if(this.getDocumentSettings().isOutputDebugLineBreaks())
{
result.write('\n');
}
}
Helper method outputs linebreak in document if debugging is turned on. |
public void setAutogenerateTOCEntries(boolean autogenerate) {
this.autogenerateTOCEntries = autogenerate;
}
Whether to automagically generate table of contents entries when
adding Chapters or Sections. |
public void writeContent(OutputStream out) throws IOException {
}
|
public void writeDocument(OutputStream out) {
try {
out.write(OPEN_GROUP);
out.write(RtfDocument.RTF_DOCUMENT);
this.documentHeader.writeContent(out);
this.data.writeTo(out);
out.write(CLOSE_GROUP);
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
|