1 13 14 package org.ejbca.core.model.log; 15 16 import java.io.ByteArrayOutputStream ; 17 import java.io.IOException ; 18 import java.io.PrintWriter ; 19 import java.util.Collection ; 20 import java.util.Iterator ; 21 22 import org.apache.log4j.Logger; 23 24 public class CsvLogExporter implements ILogExporter { 25 26 27 private static final Logger log = Logger.getLogger(CsvLogExporter.class); 28 29 private Collection logentries = null; 30 private String signingCA = null; 31 32 35 public void setEntries(Collection logentries) { 36 this.logentries = logentries; 37 } 38 39 42 public int getNoOfEntries() { 43 if (logentries == null) { 44 return 0; 45 } 46 return logentries.size(); 47 } 48 49 public String getSigningCA() { 50 return signingCA; 51 } 52 53 public void setSigningCA(String ca) { 54 this.signingCA = ca; 55 } 56 57 60 public byte[] export() { 61 log.debug(">export"); 62 byte[] ret = null; 63 if (logentries != null) { 64 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 65 PrintWriter pw = new PrintWriter (baos); 66 try { 67 Iterator i = logentries.iterator(); 68 while (i.hasNext()) { 69 LogEntry next = (LogEntry)i.next(); 70 pw.print(next.getTime()); 71 pw.print("\t"); 72 pw.print(next.getAdminType()); 73 pw.print("\t"); 74 pw.print(next.getAdminData()); 75 pw.print("\t"); 76 pw.print(next.getCAId()); 77 pw.print("\t"); 78 pw.print(next.getModule()); 79 pw.print("\t"); 80 pw.print(next.getEvent()); 81 pw.print("\t"); 82 pw.print(next.getEventName()); 83 pw.print("\t"); 84 pw.print(next.getUsername()); 85 pw.print("\t"); 86 pw.print(next.getCertificateSNR()); 87 pw.print("\t"); 88 pw.print(next.getComment()); 89 pw.print("\t"); 90 pw.print(next.getVerifyResult()); 91 pw.print("\n"); 92 } 93 pw.close(); 94 if (baos.size() > 0) { 95 ret = baos.toByteArray(); 96 } 97 } finally { 98 try { 99 pw.close(); 100 baos.close(); 101 } catch (IOException e) { 102 log.error("Error closing ByteArrayOutputStream: ", e); 103 } 104 } 105 } 106 int no = getNoOfEntries(); 107 log.debug("<export: "+no+" entries"); 108 return ret; 109 } 110 111 } 112 | Popular Tags |