1 7 8 package org.dom4j.dtd; 9 10 19 public class InternalEntityDecl { 20 21 private String name; 22 23 24 private String value; 25 26 public InternalEntityDecl() { 27 } 28 29 public InternalEntityDecl(String name, String value) { 30 this.name = name; 31 this.value = value; 32 } 33 34 39 public String getName() { 40 return name; 41 } 42 43 49 public void setName(String name) { 50 this.name = name; 51 } 52 53 58 public String getValue() { 59 return value; 60 } 61 62 68 public void setValue(String value) { 69 this.value = value; 70 } 71 72 public String toString() { 73 StringBuffer buffer = new StringBuffer ("<!ENTITY "); 74 75 if (name.startsWith("%")) { 76 buffer.append("% "); 77 buffer.append(name.substring(1)); 78 } else { 79 buffer.append(name); 80 } 81 82 buffer.append(" \""); 83 buffer.append(escapeEntityValue(value)); 84 buffer.append("\">"); 85 86 return buffer.toString(); 87 } 88 89 private String escapeEntityValue(String text) { 90 StringBuffer result = new StringBuffer (); 91 92 for (int i = 0; i < text.length(); i++) { 93 char c = text.charAt(i); 94 95 switch (c) { 96 case '<': 97 result.append("&#60;"); 98 99 break; 100 101 case '>': 102 result.append(">"); 103 104 break; 105 106 case '&': 107 result.append("&#38;"); 108 109 break; 110 111 case '\'': 112 result.append("'"); 113 114 break; 115 116 case '\"': 117 result.append("""); 118 119 break; 120 121 default: 122 123 if (c < 32) { 124 result.append("&#" + (int) c + ";"); 125 } else { 126 result.append(c); 127 } 128 129 break; 130 } 131 } 132 133 return result.toString(); 134 } 135 } 136 137 173 | Popular Tags |