Implement getXmlDocument() and getHtmlDocument()

This commit is contained in:
hns 2003-08-06 16:28:01 +00:00
parent 2e9be2b71e
commit 8c080a5da3

View file

@ -66,6 +66,7 @@ public class GlobalObject extends ScriptableObject {
"renderSkin", "renderSkinAsString", "getProperty", "renderSkin", "renderSkinAsString", "getProperty",
"authenticate", "createSkin", "format", "encode", "authenticate", "createSkin", "format", "encode",
"encodeXml", "encodeForm", "stripTags", "encodeXml", "encodeForm", "stripTags",
"getXmlDocument", "getHtmlDocument",
"getDBConnection", "getURL", "write", "writeln" "getDBConnection", "getURL", "write", "writeln"
}; };
@ -287,6 +288,46 @@ public class GlobalObject extends ScriptableObject {
return null; return null;
} }
/**
* Try to parse an object to a XML DOM tree. The argument must be
* either a URL, a piece of XML, an InputStream or a Reader.
*/
public Object getXmlDocument(Object src) {
try {
Object p = src;
if (p instanceof NativeJavaObject) {
p = ((NativeJavaObject) p).unwrap();
}
Object doc = XmlUtils.parseXml(p);
return Context.toObject(doc, this);
} catch (Exception noluck) {
app.logEvent("Error creating XML document: " + noluck);
}
return null;
}
/**
* Try to parse an object to a XML DOM tree. The argument must be
* either a URL, a piece of XML, an InputStream or a Reader.
*/
public Object getHtmlDocument(Object src) {
try {
Object p = src;
if (p instanceof NativeJavaObject) {
p = ((NativeJavaObject) p).unwrap();
}
Object doc = helma.util.XmlUtils.parseHtml(p);
return Context.toObject(doc, this);
} catch (Exception noluck) {
app.logEvent("Error creating HTML document: " + noluck);
}
return null;
}
/** /**
* *
* *