1 52 53 package com.lowagie.text.rtf.field; 54 55 import java.io.ByteArrayOutputStream ; 56 import java.io.IOException ; 57 import java.io.OutputStream ; 58 59 import com.lowagie.text.Font; 60 61 62 72 public class RtfTOCEntry extends RtfField { 73 74 77 private static final byte[] TEXT_HIDDEN_ON = "\\v".getBytes(); 78 81 private static final byte[] TEXT_HIDDEN_OFF = "\\v0".getBytes(); 82 85 private static final byte[] TOC_ENTRY_PAGE_NUMBER = "\\tc".getBytes(); 86 89 private static final byte[] TOC_ENTRY_NO_PAGE_NUMBER = "\\tcn".getBytes(); 90 91 94 private String entry = ""; 95 98 private boolean showPageNumber = true; 99 100 105 public RtfTOCEntry(String entry) { 106 super(null, new Font()); 107 if(entry != null) { 108 this.entry = entry; 109 } 110 } 111 112 118 public byte[] write() { 119 ByteArrayOutputStream result = new ByteArrayOutputStream (); 120 try { 121 writeContent(result); 122 } catch(IOException ioe) { 123 ioe.printStackTrace(); 124 } 125 return result.toByteArray(); 126 } 127 130 public void writeContent(final OutputStream result) throws IOException 131 { 132 result.write(TEXT_HIDDEN_ON); 133 result.write(OPEN_GROUP); 134 if(this.showPageNumber) { 135 result.write(TOC_ENTRY_PAGE_NUMBER); 136 } else { 137 result.write(TOC_ENTRY_NO_PAGE_NUMBER); 138 } 139 result.write(DELIMITER); 140 this.document.filterSpecialChar(result, this.entry, true, false); 142 result.write(CLOSE_GROUP); 143 result.write(TEXT_HIDDEN_OFF); 144 } 145 146 151 public void setShowPageNumber(boolean showPageNumber) { 152 this.showPageNumber = showPageNumber; 153 } 154 155 161 protected byte[] writeFieldInstContent() throws IOException 162 { 163 return null; 164 } 165 168 protected void writeFieldInstContent(OutputStream out) throws IOException 169 { 170 } 171 172 178 protected byte[] writeFieldResultContent() throws IOException { 179 return null; 180 } 181 182 186 protected void writeFieldResultContent(OutputStream out) throws IOException 187 { 188 } 189 190 } 191 | Popular Tags |