1 4 5 package com.etymon.pjx; 6 7 import java.io.*; 8 import java.util.*; 9 10 14 public class PdfDictionary 15 extends PdfObject { 16 17 20 protected Map _m; 21 22 26 protected PdfDictionary() { 27 } 28 29 35 public PdfDictionary(Map m) { 36 _m = Collections.unmodifiableMap(new HashMap(m)); 37 } 38 39 protected PdfObject filterContents(PdfObjectFilter f) throws PdfFormatException { 40 Map newMap = new HashMap(_m.size()); 41 for (Iterator t = _m.keySet().iterator(); t.hasNext(); ) { 42 43 Object obj = t.next(); 44 if ( !(obj instanceof PdfObject) ) { 45 throw new PdfFormatException("Dictionary key is not a PDF object."); 46 } 47 PdfObject key = (PdfObject)obj; 48 PdfObject keyF = key.filter(f); 49 50 if (keyF != null) { 51 obj = _m.get(key); 52 if ( !(obj instanceof PdfObject) ) { 53 throw new PdfFormatException("Dictionary value is not a PDF object."); 54 } 55 PdfObject valueF = ((PdfObject)obj).filter(f); 56 57 if (valueF != null) { 58 newMap.put(key, ((PdfObject)obj).filter(f)); 59 } 60 } 61 62 } 63 return f.postFilter(new PdfDictionary(newMap)); 64 } 65 66 public boolean equals(Object obj) { 67 68 if ( (obj == null) || ( !(obj instanceof PdfDictionary) ) ) { 69 return false; 70 } 71 72 return _m.equals( ((PdfDictionary)obj)._m ); 73 } 74 75 81 public Map getMap() { 82 return _m; 83 } 84 85 public int hashCode() { 86 return _m.hashCode(); 87 } 88 89 100 protected static PdfDictionary wrap(Map m) { 101 PdfDictionary pd = new PdfDictionary(); 102 pd._m = Collections.unmodifiableMap(m); 103 return pd; 104 } 105 106 protected int writePdf(PdfWriter w, boolean spacing) throws IOException { 107 108 DataOutputStream dos = w.getDataOutputStream(); 109 110 int count = 4; 112 dos.writeBytes("<<"); 113 114 boolean first = true; 115 for (Iterator p = _m.keySet().iterator(); p.hasNext(); ) { 116 PdfName key = (PdfName)p.next(); 117 PdfObject value = (PdfObject)_m.get(key); 118 if (first) { 119 count += key.writePdf(w, false); 120 first = false; 121 } else { 122 count += key.writePdf(w, true); 123 } 124 count += value.writePdf(w, true); 125 } 126 127 dos.writeBytes(">>"); 128 129 return count; 130 131 } 132 133 } 134 | Popular Tags |