1 2 17 18 19 package org.apache.poi.hssf.eventusermodel; 20 21 import java.util.HashMap ; 22 import java.util.List ; 23 import java.util.ArrayList ; 24 25 import org.apache.poi.hssf.record.Record; 26 import org.apache.poi.hssf.record.RecordFactory; 27 28 39 40 public class HSSFRequest 41 { 42 private HashMap records; 43 44 45 46 public HSSFRequest() 47 { 48 records = 49 new HashMap (50); } 51 52 65 66 public void addListener(HSSFListener lsnr, short sid) 67 { 68 List list = null; 69 Object obj = records.get(new Short (sid)); 70 71 if (obj != null) 72 { 73 list = ( List ) obj; 74 } 75 else 76 { 77 list = new ArrayList ( 78 1); list.add(lsnr); 80 records.put(new Short (sid), list); 81 } 82 } 83 84 94 95 public void addListenerForAllRecords(HSSFListener lsnr) 96 { 97 short[] rectypes = RecordFactory.getAllKnownRecordSIDs(); 98 99 for (int k = 0; k < rectypes.length; k++) 100 { 101 addListener(lsnr, rectypes[ k ]); 102 } 103 } 104 105 114 115 protected short processRecord(Record rec) throws HSSFUserException 116 { 117 Object obj = records.get(new Short (rec.getSid())); 118 short userCode = 0; 119 120 if (obj != null) 121 { 122 List listeners = ( List ) obj; 123 124 for (int k = 0; k < listeners.size(); k++) 125 { 126 Object listenObj = listeners.get(k); 127 if (listenObj instanceof AbortableHSSFListener) 128 { 129 AbortableHSSFListener listener = ( AbortableHSSFListener ) listenObj; 130 userCode = listener.abortableProcessRecord(rec); 131 if (userCode!=0) break; 132 } 133 else 134 { 135 HSSFListener listener = ( HSSFListener ) listenObj; 136 listener.processRecord(rec); 137 } 138 } 139 } 140 return userCode; 141 } 142 } 143 | Popular Tags |