1 50 51 package com.lowagie.text.xml.xmp; 52 53 import java.util.Enumeration ; 54 import java.util.Properties ; 55 56 59 public abstract class XmpSchema extends Properties { 60 61 62 protected String xmlns; 63 64 67 public XmpSchema(String xmlns) { 68 super(); 69 this.xmlns = xmlns; 70 } 71 75 public String toString() { 76 StringBuffer buf = new StringBuffer (); 77 for (Enumeration e = this.propertyNames(); e.hasMoreElements(); ) { 78 process(buf, e.nextElement()); 79 } 80 return buf.toString(); 81 } 82 87 protected void process(StringBuffer buf, Object p) { 88 buf.append('<'); 89 buf.append(p); 90 buf.append('>'); 91 buf.append(this.get(p)); 92 buf.append("</"); 93 buf.append(p); 94 buf.append('>'); 95 } 96 99 public String getXmlns() { 100 return xmlns; 101 } 102 103 108 public synchronized Object addProperty(String key, String value) { 109 return this.setProperty(key, value); 110 } 111 112 115 public synchronized Object setProperty(String key, String value) { 116 return super.setProperty(key, escape(value)); 117 } 118 119 126 public synchronized Object setProperty(String key, XmpArray value) { 127 return super.setProperty(key, value.toString()); 128 } 129 130 137 public synchronized Object setProperty(String key, LangAlt value) { 138 return super.setProperty(key, value.toString()); 139 } 140 141 145 public static String escape(String content) { 146 StringBuffer buf = new StringBuffer (); 147 for (int i = 0; i < content.length(); i++) { 148 switch(content.charAt(i)) { 149 case '<': 150 buf.append("<"); 151 break; 152 case '>': 153 buf.append(">"); 154 break; 155 case '\'': 156 buf.append("'"); 157 break; 158 case '\"': 159 buf.append("""); 160 break; 161 case '&': 162 buf.append("&"); 163 break; 164 default: 165 buf.append(content.charAt(i)); 166 } 167 } 168 return buf.toString(); 169 } 170 } 171 | Popular Tags |