2 |
|
|
3 |
package org.fenfire.swamp.impl; |
package org.fenfire.swamp.impl; |
4 |
import org.fenfire.swamp.*; |
import org.fenfire.swamp.*; |
5 |
|
import org.xml.sax.*; |
6 |
|
import org.xml.sax.helpers.*; |
7 |
|
import java.io.*; |
8 |
|
|
9 |
public class StdLiteral implements Literal { |
public class StdLiteral implements Literal { |
10 |
String content; |
String xmlcontent; |
11 |
|
String txtcontent; |
12 |
|
|
13 |
|
static javax.xml.parsers.SAXParser saxParser; |
14 |
|
static { |
15 |
|
try { |
16 |
|
saxParser = javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser(); |
17 |
|
} catch(Exception e) { |
18 |
|
throw new Error(e); |
19 |
|
} |
20 |
|
} |
21 |
|
|
22 |
public StdLiteral(String c, boolean isXml) { |
public StdLiteral(String c, boolean isXml) { |
23 |
if(!isXml) |
if(c == null) throw new NullPointerException(); |
24 |
c = org.nongnu.alph.util.XMLUtil.escapeXML(c); |
if(isXml) |
25 |
this.content = c; |
this.xmlcontent = c; |
26 |
|
else |
27 |
|
this.txtcontent = c; |
28 |
} |
} |
29 |
public String getRawXMLString() { |
public String getRawXMLString() { |
30 |
return content; |
if(xmlcontent == null) |
31 |
|
xmlcontent = org.nongnu.alph.util.XMLUtil.escapeXML(txtcontent); |
32 |
|
return xmlcontent; |
33 |
} |
} |
34 |
public String getTextString() { |
public String getTextString() { |
35 |
throw new Error("Not implemented"); |
if(txtcontent == null) { |
36 |
|
final StringBuffer buf = new StringBuffer(); |
37 |
|
try { |
38 |
|
saxParser.parse( |
39 |
|
new StringBufferInputStream("<c>"+xmlcontent+"</c>"), |
40 |
|
new DefaultHandler() { |
41 |
|
public void characters(char[] ch, int start, int length){ |
42 |
|
buf.append(ch, start, length); |
43 |
|
} |
44 |
|
} |
45 |
|
); |
46 |
|
} catch(Exception e) { |
47 |
|
e.printStackTrace(); |
48 |
|
throw new Error("!!!!" + e); |
49 |
|
} |
50 |
|
txtcontent = buf.toString(); |
51 |
|
} |
52 |
|
return txtcontent; |
53 |
} |
} |
54 |
} |
} |