1 50 51 package com.lowagie.text.xml; 52 53 import java.util.Properties ; 54 55 import org.xml.sax.Attributes ; 56 57 import com.lowagie.text.ElementTags; 58 59 62 63 public class XmlPeer { 64 65 66 protected String tagname; 67 68 69 protected String customTagname; 70 71 72 protected Properties attributeAliases = new Properties (); 73 74 75 protected Properties attributeValues = new Properties (); 76 77 78 protected String defaultContent = null; 79 80 85 86 public XmlPeer(String name, String alias) { 87 this.tagname = name; 88 this.customTagname = alias; 89 } 90 91 95 96 public String getTag() { 97 return tagname; 98 } 99 100 104 105 public String getAlias() { 106 return customTagname; 107 } 108 109 113 public Properties getAttributes(Attributes attrs) { 114 Properties attributes = new Properties (); 115 attributes.putAll(attributeValues); 116 if (defaultContent != null) { 117 attributes.put(ElementTags.ITEXT, defaultContent); 118 } 119 if (attrs != null) { 120 for (int i = 0; i < attrs.getLength(); i++) { 121 String attribute = getName(attrs.getQName(i)); 122 attributes.setProperty(attribute, attrs.getValue(i)); 123 } 124 } 125 return attributes; 126 } 127 128 134 135 public void addAlias(String name, String alias) { 136 attributeAliases.put(alias, name); 137 } 138 139 145 146 public void addValue(String name, String value) { 147 attributeValues.put(name, value); 148 } 149 150 155 156 public void setContent(String content) { 157 this.defaultContent = content; 158 } 159 160 166 167 public String getName(String name) { 168 String value; 169 if ((value = attributeAliases.getProperty(name)) != null) { 170 return value; 171 } 172 return name; 173 } 174 175 179 180 public Properties getDefaultValues() { 181 return attributeValues; 182 } 183 } | Popular Tags |