1 52 53 package com.lowagie.text.rtf; 54 55 import java.io.IOException ; 56 import java.io.OutputStream ; 57 58 import com.lowagie.text.Chunk; 59 import com.lowagie.text.Font; 60 61 62 74 abstract class AbstractRtfField extends Chunk implements RtfField { 75 private static final byte[] fldDirty = "\\flddirty".getBytes(); 76 private static final byte[] fldPriv = "\\fldpriv".getBytes(); 77 private static final byte[] fldLock = "\\fldlock".getBytes(); 78 private static final byte[] fldEdit = "\\fldedit".getBytes(); 79 private static final byte[] fldAlt = "\\fldalt".getBytes(); 80 81 86 public AbstractRtfField(String content, Font font) { 87 super(content, font); 88 } 89 90 94 private boolean rtfFieldIsLocked = false; 95 96 100 private boolean rtfFieldIsDirty = false; 101 102 107 private boolean rtfFieldWasEdited = false; 108 109 113 private boolean rtfFieldIsPrivate = false; 114 115 118 private boolean rtfFieldIsAlt = false; 119 120 127 public final boolean isLocked() { 128 return this.rtfFieldIsLocked; 129 } 130 131 137 public final void setLocked(final boolean rtfFieldIsLocked) { 138 this.rtfFieldIsLocked = rtfFieldIsLocked; 139 } 140 141 148 public final void setDirty(final boolean rtfFieldIsDirty) { 149 this.rtfFieldIsDirty = rtfFieldIsDirty; 150 } 151 152 158 public final boolean isDirty() { 159 return this.rtfFieldIsDirty; 160 } 161 162 169 public final void setEdited(final boolean rtfFieldWasEdited) { 170 this.rtfFieldWasEdited = rtfFieldWasEdited; 171 } 172 173 180 public final boolean wasEdited() { 181 return this.rtfFieldWasEdited; 182 } 183 184 191 public final void setPrivate(final boolean rtfFieldIsPrivate) { 192 this.rtfFieldIsPrivate = rtfFieldIsPrivate; 193 } 194 195 200 public final boolean isPrivate() { 201 return this.rtfFieldIsPrivate; 202 } 203 204 210 public abstract void writeRtfFieldInitializationStuff(OutputStream out) throws IOException ; 211 212 218 public abstract void writeRtfFieldResultStuff(OutputStream out) throws IOException ; 219 220 225 public final void setAlt(final boolean rtfFieldIsAlt) { 226 this.rtfFieldIsAlt = rtfFieldIsAlt; 227 } 228 229 235 public final boolean isAlt() { 236 return this.rtfFieldIsAlt; 237 } 238 239 244 public final String content() { 245 return getContent(); 246 } 247 248 252 public final String getContent() { 253 return ""; 254 } 255 256 262 public void write( RtfWriter writer, OutputStream out ) throws IOException { 263 writeRtfFieldBegin(out); 264 writeRtfFieldModifiers(out); 265 writeRtfFieldInstBegin(out); 266 writer.writeInitialFontSignature( out, this ); 267 writeRtfFieldInitializationStuff(out); 268 writeRtfFieldInstEnd(out); 269 writeRtfFieldResultBegin(out); 270 writer.writeInitialFontSignature( out, this ); 271 writeRtfFieldResultStuff(out); 272 writeRtfFieldResultEnd(out); 273 writeRtfFieldEnd(out); 274 } 275 276 281 protected final void writeRtfFieldBegin(OutputStream out) throws IOException { 282 out.write(RtfWriter.openGroup); 283 out.write(RtfWriter.escape); 284 out.write(RtfWriter.field); 285 } 286 287 292 protected final void writeRtfFieldModifiers(OutputStream out) throws IOException { 293 if (isDirty()) { 294 out.write(fldDirty); 295 } 296 297 if (wasEdited()) { 298 out.write(fldEdit); 299 } 300 301 if (isLocked()) { 302 out.write(fldLock); 303 } 304 305 if (isPrivate()) { 306 out.write(fldPriv); 307 } 308 } 309 310 315 protected final void writeRtfFieldInstBegin(OutputStream out) throws IOException { 316 out.write( RtfWriter.openGroup ); 317 out.write( RtfWriter.escape ); 318 out.write( RtfWriter.fieldContent ); 319 out.write( RtfWriter.delimiter ); 320 } 321 322 327 protected final void writeRtfFieldInstEnd(OutputStream out) throws IOException { 328 if (isAlt()) { 329 out.write( fldAlt ); 330 out.write( RtfWriter.delimiter ); 331 } 332 333 out.write( RtfWriter.closeGroup ); 334 } 335 336 341 protected final void writeRtfFieldResultBegin(OutputStream out) throws IOException { 342 out.write( RtfWriter.openGroup ); 343 out.write( RtfWriter.escape ); 344 out.write( RtfWriter.fieldDisplay ); 345 out.write( RtfWriter.delimiter ); 346 } 347 348 353 protected final void writeRtfFieldResultEnd(OutputStream out) throws IOException { 354 out.write( RtfWriter.delimiter ); 355 out.write( RtfWriter.closeGroup ); 356 } 357 358 363 protected final void writeRtfFieldEnd(OutputStream out) throws IOException { 364 out.write( RtfWriter.closeGroup ); 365 } 366 } 367 | Popular Tags |