1 17 18 19 20 package org.apache.fop.render.rtf.rtflib.rtfdoc; 21 22 28 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 import org.xml.sax.Attributes ; 32 import org.xml.sax.helpers.AttributesImpl ; 33 34 35 38 39 public class RtfAttributes 40 implements java.lang.Cloneable { 41 private HashMap values = new HashMap (); 42 43 49 public RtfAttributes set (RtfAttributes attrs) { 50 if (attrs != null) { 51 Iterator it = attrs.nameIterator (); 52 while (it.hasNext ()) { 53 String name = (String ) it.next (); 54 if (attrs.getValue(name) instanceof Integer ) { 55 Integer value = (Integer )attrs.getValue (name); 56 if (value == null) { 57 set (name); 58 } else { 59 set (name, value.intValue ()); 60 } 61 } else if (attrs.getValue(name) instanceof String ) { 62 String value = (String )attrs.getValue (name); 63 if (value == null) { 64 set (name); 65 } else { 66 set (name, value); 67 } 68 } else { 69 set (name); 70 } 71 72 73 } 74 setXslAttributes(attrs.getXslAttributes()); 76 } 77 return this; 78 } 79 80 85 public RtfAttributes set(String name) { 86 values.put(name, null); 87 return this; 88 } 89 90 95 public RtfAttributes unset(String name) { 96 values.remove(name); 97 return this; 98 } 99 100 104 public String toString() { 105 return values.toString() + "(" + super.toString() + ")"; 106 } 107 108 112 public Object clone() { 113 final RtfAttributes result = new RtfAttributes(); 114 result.values = (HashMap )values.clone(); 115 116 if (xslAttributes != null) { 119 result.xslAttributes = new org.xml.sax.helpers.AttributesImpl (xslAttributes); 120 } 121 122 return result; 123 } 124 125 131 public RtfAttributes set(String name, int value) { 132 values.put(name, new Integer (value)); 133 return this; 134 } 135 136 142 public RtfAttributes set(String name, String type) { 143 values.put(name, type); 144 return this; 145 } 146 147 153 public RtfAttributes set(String name, RtfAttributes value) { 154 values.put(name, value); 155 return this; 156 } 157 158 162 public Object getValue(String name) { 163 return values.get(name); 164 } 165 166 170 public boolean isSet(String name) { 171 return values.containsKey(name); 172 } 173 174 175 public Iterator nameIterator() { 176 return values.keySet().iterator(); 177 } 178 179 private Attributes xslAttributes = null; 180 181 186 public Attributes getXslAttributes() { 187 return xslAttributes; 188 } 189 190 195 public void setXslAttributes(Attributes pAttribs) { 196 if (pAttribs == null) { 197 return; 198 } 199 if (xslAttributes != null) { 201 for (int i = 0; i < pAttribs.getLength(); i++) { 202 String wKey = pAttribs.getQName(i); 203 int wPos = xslAttributes.getIndex(wKey); 204 if (wPos == -1) { 205 ((AttributesImpl )xslAttributes).addAttribute(pAttribs.getURI(i), 206 pAttribs.getLocalName(i), pAttribs.getQName(i), 207 pAttribs.getType(i), pAttribs.getValue(i)); 208 } else { 209 ((AttributesImpl )xslAttributes).setAttribute(wPos, pAttribs.getURI(i), 210 pAttribs.getLocalName(i), pAttribs.getQName(i), 211 pAttribs.getType(i), pAttribs.getValue(i)); 212 } 213 } 214 } else { 215 xslAttributes = new org.xml.sax.helpers.AttributesImpl (pAttribs); 216 } 217 } 218 219 226 public void addIntegerValue(int addValue, String name) { 227 Integer value = (Integer ) getValue(name); 228 int v = (value != null) ? value.intValue() : 0; 229 set(name, v + addValue); 230 } 231 } 232 | Popular Tags |