diff --git a/src/helma/scripting/rhino/extensions/XmlObject.java b/src/helma/scripting/rhino/extensions/XmlObject.java
index 1311cfb9..860bc2b1 100644
--- a/src/helma/scripting/rhino/extensions/XmlObject.java
+++ b/src/helma/scripting/rhino/extensions/XmlObject.java
@@ -47,10 +47,23 @@ public class XmlObject {
*
* @param node the HopObject to encode
* @param file the file to write to
- *
+ * @return true
* @throws IOException if something went wrong along the way
*/
- public boolean write(INode node, String file)
+ public boolean write(INode node, String file) throws IOException {
+ return write(node, file, false);
+ }
+
+ /**
+ * Writes a HopObject to an XML file, optionally using shallow/db mode
+ *
+ * @param node the HopObject to encode
+ * @param file the file to write to
+ * @param dbmode whether to write a shallow copy
+ * @return true
+ * @throws IOException if something went wrong along the way
+ */
+ public boolean write(INode node, String file, boolean dbmode)
throws IOException {
// we definitly need a node
if (node == null) {
@@ -64,12 +77,9 @@ public class XmlObject {
File tmpFile = new File(file + ".tmp." + XmlWriter.generateID());
XmlWriter writer = new XmlWriter(tmpFile, "UTF-8");
- writer.setDatabaseMode(false);
-
+ writer.setDatabaseMode(dbmode);
writer.write(node);
-
writer.close();
-
File finalFile = new File(file);
if (finalFile.exists()) {
@@ -82,15 +92,26 @@ public class XmlObject {
}
/**
- * Transforms a HopObject to XML and returns the result as string
+ * Transforms a HopObject to XML and returns the result as string
*
* @param node the HopObject to encode
- *
* @return the XML representing the HopObject
- *
- * @throws IOException if something went wrong
+ * @throws IOException if something went wrong along the way
*/
public String writeToString(INode node) throws IOException {
+ return writeToString(node, false);
+ }
+
+ /**
+ * Transforms a HopObject to XML and returns the result as string,
+ * optionally using shallow/db mode
+ *
+ * @param node the HopObject to encode
+ * @return the XML representing the HopObject
+ * @param dbmode whether to write a shallow copy
+ * @throws IOException if something went wrong
+ */
+ public String writeToString(INode node, boolean dbmode) throws IOException {
// we definitly need a node
if (node == null) {
throw new RuntimeException("First argument in Xml.write() is not an hopobject");
@@ -99,15 +120,12 @@ public class XmlObject {
ByteArrayOutputStream out = new ByteArrayOutputStream();
XmlWriter writer = new XmlWriter(out, "UTF-8");
- // in case we ever want to limit serialization depth...
+ // in case we ever want to limit serialization depth...
// if (arguments.length > 1 && arguments[1] instanceof ESNumber)
// writer.setMaxLevels(arguments[1].toInt32());
- writer.setDatabaseMode(false);
-
+ writer.setDatabaseMode(dbmode);
writer.write(node);
-
writer.flush();
-
return out.toString("UTF-8");
}
@@ -115,9 +133,7 @@ public class XmlObject {
* Reads an XML document from a file and creates a HopObject out of it
*
* @param file the file name
- *
* @return the HopObject
- *
* @throws RuntimeException ...
*/
public Object read(String file) throws RuntimeException {
@@ -129,7 +145,6 @@ public class XmlObject {
*
* @param file the file name
* @param node the HopObject to use for conversion
- *
* @return the HopObject
*/
public Object read(String file, INode node) throws RuntimeException {
@@ -139,8 +154,7 @@ public class XmlObject {
if (node == null) {
// make sure we have a node, even if 2nd arg doesn't exist or is not a node
- node = new Node((String) null, (String) null,
- core.getApplication().getWrappedNodeManager());
+ node = new Node(null, null, core.getApplication().getWrappedNodeManager());
}
try {
@@ -159,9 +173,7 @@ public class XmlObject {
* Reads an XML document from an XML literal and creates a HopObject out of it
*
* @param str the XML string
- *
* @return the HopObject
- *
* @throws RuntimeException ...
*/
public Object readFromString(String str) throws RuntimeException {
@@ -173,9 +185,7 @@ public class XmlObject {
*
* @param str the XML string
* @param node the HopObject to use for conversion
- *
* @return ...
- *
* @throws RuntimeException ...
*/
public Object readFromString(String str, INode node)
@@ -186,8 +196,7 @@ public class XmlObject {
if (node == null) {
// make sure we have a node, even if 2nd arg doesn't exist or is not a node
- node = new Node((String) null, (String) null,
- core.getApplication().getWrappedNodeManager());
+ node = new Node(null, null, core.getApplication().getWrappedNodeManager());
}
try {
@@ -208,7 +217,6 @@ public class XmlObject {
* Retrieves an XML document from a given URL and transforms it into a HopObject
*
* @param url the URL containing the XML to be parsed
- *
* @return a HopObject obtained from parsing the XML
*/
public Object get(String url) {
@@ -221,9 +229,7 @@ public class XmlObject {
*
* @param url the URL containing the XML to be parsed
* @param conversionRules a file name pointing to the conversion rules
- *
* @return a HopObject obtained from parsing the XML
- *
* @see
*/
public Object get(String url, String conversionRules) {
@@ -240,10 +246,8 @@ public class XmlObject {
converter = new XmlConverter();
}
- INode node = new helma.objectmodel.db.Node((String) null,
- (String) null,
- core.getApplication()
- .getWrappedNodeManager());
+ INode node = new helma.objectmodel.db.Node(null, null,
+ core.getApplication().getWrappedNodeManager());
INode result = converter.convert(url, node);
return core.getNodeWrapper(result);
@@ -256,7 +260,6 @@ public class XmlObject {
* Transforms a XML literal into a HopObject
*
* @param str an XML literal
- *
* @return a HopObject obtained from parsing the XML
*/
public Object getFromString(String str) {
@@ -270,9 +273,7 @@ public class XmlObject {
*
* @param str an XML literal
* @param conversionRules a file name pointing to the conversion rules
- *
* @return a HopObject obtained from parsing the XML
- *
* @see
*/
public Object getFromString(String str, String conversionRules) {
@@ -289,8 +290,7 @@ public class XmlObject {
converter = new XmlConverter();
}
- INode node = new Node((String) null, (String) null,
- core.getApplication().getWrappedNodeManager());
+ INode node = new Node(null, null, core.getApplication().getWrappedNodeManager());
INode result = converter.convertFromString(str, node);
return core.getNodeWrapper(result);