| 1 9 10 package org.ozoneDB.xml.dom4j.o3impl; 11 12 import org.dom4j.Element; 13 import org.dom4j.ProcessingInstruction; 14 import org.dom4j.Visitor; 15 16 import java.io.IOException ; 17 import java.io.Writer ; 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 import java.util.StringTokenizer ; 22 23 29 public abstract class AbstractProcessingInstruction extends AbstractNode implements ProcessingInstruction { 30 31 public AbstractProcessingInstruction() { 32 } 33 34 public short getNodeType() { 35 return PROCESSING_INSTRUCTION_NODE; 36 } 37 38 public String getPath(Element context) { 39 Element parent = getParent(); 40 return (parent != null && parent != context) 41 ? parent.getPath(context) + "/processing-instruction()" 42 : "processing-instruction()"; 43 } 44 45 public String getUniquePath(Element context) { 46 Element parent = getParent(); 47 return (parent != null && parent != context) 48 ? parent.getUniquePath(context) + "/processing-instruction()" 49 : "processing-instruction()"; 50 } 51 52 public String toString() { 53 return super.toString() + " [ProcessingInstruction: &" + getName() + ";]"; 54 } 55 56 public String asXML() { 57 return "<?" + getName() + " " + getText() + "?>"; 58 } 59 60 public void write(Writer writer) throws IOException { 61 writer.write("<?"); 62 writer.write(getName()); 63 writer.write(" "); 64 writer.write(getText()); 65 writer.write("?>"); 66 } 67 68 public void accept(Visitor visitor) { 69 visitor.visit(this); 70 } 71 72 public void setValue(String name, String value) { 73 throw new UnsupportedOperationException ( 74 "This PI is read-only and cannot be modified" 75 ); 76 } 77 78 public void setValues(Map data) { 79 throw new UnsupportedOperationException ( 80 "This PI is read-only and cannot be modified" 81 ); 82 } 83 84 public String getName() { 85 return getTarget(); 86 } 87 88 public void setName(String name) { 89 setTarget(name); 90 } 91 92 public boolean removeValue(String name) { 93 return false; 94 } 95 96 97 99 103 protected String toString(Map values) { 104 StringBuffer buffer = new StringBuffer (); 105 106 for (Iterator iter = values.entrySet().iterator(); iter.hasNext();) { 107 Map.Entry entry = (Map.Entry ) iter.next(); 108 String name = (String ) entry.getKey(); 109 String value = (String ) entry.getValue(); 110 111 buffer.append(name); 112 buffer.append("=\""); 113 buffer.append(value); 114 buffer.append("\" "); 115 } 116 buffer.setLength(buffer.length() - 1); 118 return buffer.toString(); 119 } 120 121 125 protected Map parseValues(String text) { 126 Map data = new HashMap (); 127 128 StringTokenizer s = 130 new StringTokenizer (text); 131 132 while (s.hasMoreTokens()) { 134 StringTokenizer t = 136 new StringTokenizer (s.nextToken(), "='\""); 137 138 if (t.countTokens() >= 2) { 139 String name = t.nextToken(); 140 String value = t.nextToken(); 141 142 data.put(name, value); 143 } 144 } 145 return data; 146 } 147 } 148 149 150 194 | Popular Tags |