1 50 51 package com.lowagie.text.rtf.list; 52 53 import java.io.ByteArrayOutputStream ; 54 import java.io.IOException ; 55 import java.io.OutputStream ; 56 import java.util.ArrayList ; 57 58 import com.lowagie.text.rtf.RtfElement; 59 import com.lowagie.text.rtf.RtfExtendedElement; 60 import com.lowagie.text.rtf.document.RtfDocument; 61 62 63 71 public class RtfListTable extends RtfElement implements RtfExtendedElement { 72 73 76 protected static final byte[] LIST_NUMBER = "\\ls".getBytes(); 77 80 private static final byte[] LIST_TABLE = "\\*\\listtable".getBytes(); 81 84 private static final byte[] LIST = "\\list".getBytes(); 85 88 private static final byte[] LIST_TEMPLATE_ID = "\\listtemplateid".getBytes(); 89 92 private static final byte[] LIST_HYBRID = "\\hybrid".getBytes(); 93 96 private static final byte[] LIST_ID = "\\listid".getBytes(); 97 100 private static final byte[] LIST_OVERRIDE_TABLE = "\\*\\listoverridetable".getBytes(); 101 104 private static final byte[] LIST_OVERRIDE = "\\listoverride".getBytes(); 105 108 private static final byte[] LIST_OVERRIDE_COUNT = "\\listoverridecount".getBytes(); 109 110 113 private ArrayList lists; 114 115 120 public RtfListTable(RtfDocument doc) { 121 super(doc); 122 123 this.lists = new ArrayList (); 124 } 125 126 130 public byte[] write() 131 { 132 return(new byte[0]); 133 } 134 137 public void writeContent(final OutputStream out) throws IOException 138 { 139 } 140 141 147 public byte[] writeDefinition() { 148 ByteArrayOutputStream result = new ByteArrayOutputStream (); 149 try { 150 writeDefinition(result); 151 } catch(IOException ioe) { 152 ioe.printStackTrace(); 153 } 154 return result.toByteArray(); 155 } 156 157 160 public void writeDefinition(final OutputStream result) throws IOException 161 { 162 final int[] listIds = new int[lists.size()]; 163 result.write(OPEN_GROUP); 164 result.write(LIST_TABLE); 165 result.write("\n".getBytes()); 166 for(int i = 0; i < lists.size(); i++) { 167 result.write(OPEN_GROUP); 168 result.write(LIST); 169 result.write(LIST_TEMPLATE_ID); 170 result.write(intToByteArray(document.getRandomInt())); 171 result.write(LIST_HYBRID); 172 result.write("\n".getBytes()); 173 final RtfList rList = (RtfList) lists.get(i); 174 rList.writeDefinition(result); 176 result.write(LIST_ID); 177 listIds[i] = document.getRandomInt(); 178 result.write(intToByteArray(listIds[i])); 179 result.write(CLOSE_GROUP); 180 result.write("\n".getBytes()); 181 } 182 result.write(CLOSE_GROUP); 183 result.write("\n".getBytes()); 184 result.write(OPEN_GROUP); 185 result.write(LIST_OVERRIDE_TABLE); 186 result.write("\n".getBytes()); 187 for(int i = 0; i < lists.size(); i++) { 188 result.write(OPEN_GROUP); 189 result.write(LIST_OVERRIDE); 190 result.write(LIST_ID); 191 result.write(intToByteArray(listIds[i])); 192 result.write(LIST_OVERRIDE_COUNT); 193 result.write(intToByteArray(0)); 194 result.write(LIST_NUMBER); 195 result.write(intToByteArray(((RtfList) lists.get(i)).getListNumber())); 196 result.write(CLOSE_GROUP); 197 result.write("\n".getBytes()); 198 } 199 result.write(CLOSE_GROUP); 200 result.write("\n".getBytes()); 201 } 202 203 210 public int getListNumber(RtfList list) { 211 if(lists.contains(list)) { 212 return lists.indexOf(list); 213 } else { 214 lists.add(list); 215 return lists.size(); 216 } 217 } 218 219 224 public void freeListNumber(RtfList list) { 225 int i = lists.indexOf(list); 226 if(i >= 0) { 227 lists.remove(i); 228 } 229 } 230 } 231 | Popular Tags |