1 package com.icl.saxon.expr; 2 import com.icl.saxon.*; 3 import com.icl.saxon.om.*; 4 import com.icl.saxon.tinytree.TinyBuilder; 5 import com.icl.saxon.output.*; 6 import javax.xml.transform.TransformerException ; 7 8 9 13 14 public final class TextFragmentValue extends SingletonNodeSet { 15 16 private String text; 17 private String baseURI; 18 private Controller controller; 19 20 24 25 public TextFragmentValue(String value, String systemId, Controller controller) { 26 this.text = value; 27 this.node = null; 28 this.baseURI = systemId; 29 this.controller = controller; 30 generalUseAllowed = false; 31 } 32 33 36 37 public String asString() { 38 return text; 39 } 40 41 47 48 public void outputStringValue(Outputter out, Context context) throws TransformerException { 49 out.writeContent(text); 50 } 51 52 55 56 public double asNumber() { 57 return Value.stringToNumber(text); 58 } 59 60 63 64 public boolean asBoolean() { 65 return true; 66 } 67 68 71 72 public int getCount() { 73 return 1; 74 } 75 76 79 80 public Expression simplify() { 81 return this; 83 } 84 85 89 90 public NodeInfo getFirst() { 91 return getRootNode(); 92 } 93 94 97 98 public NodeEnumeration enumerate() throws XPathException { 99 if (!generalUseAllowed) { 100 throw new XPathException("Cannot process a result tree fragment as a node-set under XSLT 1.0"); 101 } 102 return new SingletonEnumeration(getRootNode()); 103 } 104 105 108 109 public boolean equals(Value other) throws XPathException { 110 if (other instanceof StringValue) { return text.equals(other.asString()); 112 } 113 return new StringValue(text).equals(other); 114 } 115 116 119 120 public boolean notEquals(Value other) throws XPathException { 121 return new StringValue(text).notEquals(other); 122 } 123 124 127 128 public boolean compare(int operator, Value other) throws XPathException { 129 return new StringValue(text).compare(operator, other); 130 } 131 132 136 137 public int getType() { 138 return Value.NODESET; 139 } 140 141 145 146 public int getDataType() { 147 return Value.NODESET; 148 } 149 150 153 154 public DocumentInfo getRootNode() { 155 if (node!=null) { return (DocumentInfo)node; 157 } 158 try { 159 int len = text.length(); 160 char[] chars = new char[len]; 161 text.getChars(0, len, chars, 0); 162 Builder builder = new TinyBuilder(); 163 builder.setSystemId(baseURI); 164 builder.setNamePool(controller.getNamePool()); builder.startDocument(); 166 builder.characters(chars, 0, len); 167 builder.endDocument(); 168 node = builder.getCurrentDocument(); 169 controller.getDocumentPool().add((DocumentInfo)node, null); 170 return (DocumentInfo)node; 171 } catch (TransformerException err) { 172 throw new InternalSaxonError("Error building temporary tree: " + err.getMessage()); 173 } 174 } 175 176 179 180 public void copy(Outputter out) throws TransformerException { 181 out.writeContent(text); 182 } 183 184 187 188 public void display(int level) { 189 System.err.println(indent(level) + "** result tree fragment ** (" + text + ")"); 190 } 191 192 } 193 194 213 | Popular Tags |