* Add write() and writeToString() variants that take an additional boolean argument
to write node in shallow/internal database mode. Fixes bug http://helma.org/bugs/show_bug.cgi?id=404 * Some code and javadoc cleanup.
This commit is contained in:
parent
ff20cddcda
commit
e9e11ddb9a
1 changed files with 38 additions and 38 deletions
|
@ -47,10 +47,23 @@ public class XmlObject {
|
||||||
*
|
*
|
||||||
* @param node the HopObject to encode
|
* @param node the HopObject to encode
|
||||||
* @param file the file to write to
|
* @param file the file to write to
|
||||||
*
|
* @return true
|
||||||
* @throws IOException if something went wrong along the way
|
* @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 {
|
throws IOException {
|
||||||
// we definitly need a node
|
// we definitly need a node
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
|
@ -64,12 +77,9 @@ public class XmlObject {
|
||||||
File tmpFile = new File(file + ".tmp." + XmlWriter.generateID());
|
File tmpFile = new File(file + ".tmp." + XmlWriter.generateID());
|
||||||
XmlWriter writer = new XmlWriter(tmpFile, "UTF-8");
|
XmlWriter writer = new XmlWriter(tmpFile, "UTF-8");
|
||||||
|
|
||||||
writer.setDatabaseMode(false);
|
writer.setDatabaseMode(dbmode);
|
||||||
|
|
||||||
writer.write(node);
|
writer.write(node);
|
||||||
|
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
File finalFile = new File(file);
|
File finalFile = new File(file);
|
||||||
|
|
||||||
if (finalFile.exists()) {
|
if (finalFile.exists()) {
|
||||||
|
@ -85,12 +95,23 @@ 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
|
* @param node the HopObject to encode
|
||||||
*
|
|
||||||
* @return the XML representing the HopObject
|
* @return the XML representing the HopObject
|
||||||
*
|
* @throws IOException if something went wrong along the way
|
||||||
* @throws IOException if something went wrong
|
|
||||||
*/
|
*/
|
||||||
public String writeToString(INode node) throws IOException {
|
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
|
// we definitly need a node
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
throw new RuntimeException("First argument in Xml.write() is not an hopobject");
|
throw new RuntimeException("First argument in Xml.write() is not an hopobject");
|
||||||
|
@ -102,12 +123,9 @@ public class XmlObject {
|
||||||
// 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)
|
// if (arguments.length > 1 && arguments[1] instanceof ESNumber)
|
||||||
// writer.setMaxLevels(arguments[1].toInt32());
|
// writer.setMaxLevels(arguments[1].toInt32());
|
||||||
writer.setDatabaseMode(false);
|
writer.setDatabaseMode(dbmode);
|
||||||
|
|
||||||
writer.write(node);
|
writer.write(node);
|
||||||
|
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
|
||||||
return out.toString("UTF-8");
|
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
|
* Reads an XML document from a file and creates a HopObject out of it
|
||||||
*
|
*
|
||||||
* @param file the file name
|
* @param file the file name
|
||||||
*
|
|
||||||
* @return the HopObject
|
* @return the HopObject
|
||||||
*
|
|
||||||
* @throws RuntimeException ...
|
* @throws RuntimeException ...
|
||||||
*/
|
*/
|
||||||
public Object read(String file) throws RuntimeException {
|
public Object read(String file) throws RuntimeException {
|
||||||
|
@ -129,7 +145,6 @@ public class XmlObject {
|
||||||
*
|
*
|
||||||
* @param file the file name
|
* @param file the file name
|
||||||
* @param node the HopObject to use for conversion
|
* @param node the HopObject to use for conversion
|
||||||
*
|
|
||||||
* @return the HopObject
|
* @return the HopObject
|
||||||
*/
|
*/
|
||||||
public Object read(String file, INode node) throws RuntimeException {
|
public Object read(String file, INode node) throws RuntimeException {
|
||||||
|
@ -139,8 +154,7 @@ public class XmlObject {
|
||||||
|
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
// make sure we have a node, even if 2nd arg doesn't exist or is not a node
|
// 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,
|
node = new Node(null, null, core.getApplication().getWrappedNodeManager());
|
||||||
core.getApplication().getWrappedNodeManager());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -159,9 +173,7 @@ public class XmlObject {
|
||||||
* Reads an XML document from an XML literal and creates a HopObject out of it
|
* Reads an XML document from an XML literal and creates a HopObject out of it
|
||||||
*
|
*
|
||||||
* @param str the XML string
|
* @param str the XML string
|
||||||
*
|
|
||||||
* @return the HopObject
|
* @return the HopObject
|
||||||
*
|
|
||||||
* @throws RuntimeException ...
|
* @throws RuntimeException ...
|
||||||
*/
|
*/
|
||||||
public Object readFromString(String str) throws RuntimeException {
|
public Object readFromString(String str) throws RuntimeException {
|
||||||
|
@ -173,9 +185,7 @@ public class XmlObject {
|
||||||
*
|
*
|
||||||
* @param str the XML string
|
* @param str the XML string
|
||||||
* @param node the HopObject to use for conversion
|
* @param node the HopObject to use for conversion
|
||||||
*
|
|
||||||
* @return ...
|
* @return ...
|
||||||
*
|
|
||||||
* @throws RuntimeException ...
|
* @throws RuntimeException ...
|
||||||
*/
|
*/
|
||||||
public Object readFromString(String str, INode node)
|
public Object readFromString(String str, INode node)
|
||||||
|
@ -186,8 +196,7 @@ public class XmlObject {
|
||||||
|
|
||||||
if (node == null) {
|
if (node == null) {
|
||||||
// make sure we have a node, even if 2nd arg doesn't exist or is not a node
|
// 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,
|
node = new Node(null, null, core.getApplication().getWrappedNodeManager());
|
||||||
core.getApplication().getWrappedNodeManager());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -208,7 +217,6 @@ public class XmlObject {
|
||||||
* Retrieves an XML document from a given URL and transforms it into a HopObject
|
* Retrieves an XML document from a given URL and transforms it into a HopObject
|
||||||
*
|
*
|
||||||
* @param url the URL containing the XML to be parsed
|
* @param url the URL containing the XML to be parsed
|
||||||
*
|
|
||||||
* @return a HopObject obtained from parsing the XML
|
* @return a HopObject obtained from parsing the XML
|
||||||
*/
|
*/
|
||||||
public Object get(String url) {
|
public Object get(String url) {
|
||||||
|
@ -221,9 +229,7 @@ public class XmlObject {
|
||||||
*
|
*
|
||||||
* @param url the URL containing the XML to be parsed
|
* @param url the URL containing the XML to be parsed
|
||||||
* @param conversionRules a file name pointing to the conversion rules
|
* @param conversionRules a file name pointing to the conversion rules
|
||||||
*
|
|
||||||
* @return a HopObject obtained from parsing the XML
|
* @return a HopObject obtained from parsing the XML
|
||||||
*
|
|
||||||
* @see <http://helma.org/development/rfc/xmlconversion/>
|
* @see <http://helma.org/development/rfc/xmlconversion/>
|
||||||
*/
|
*/
|
||||||
public Object get(String url, String conversionRules) {
|
public Object get(String url, String conversionRules) {
|
||||||
|
@ -240,10 +246,8 @@ public class XmlObject {
|
||||||
converter = new XmlConverter();
|
converter = new XmlConverter();
|
||||||
}
|
}
|
||||||
|
|
||||||
INode node = new helma.objectmodel.db.Node((String) null,
|
INode node = new helma.objectmodel.db.Node(null, null,
|
||||||
(String) null,
|
core.getApplication().getWrappedNodeManager());
|
||||||
core.getApplication()
|
|
||||||
.getWrappedNodeManager());
|
|
||||||
INode result = converter.convert(url, node);
|
INode result = converter.convert(url, node);
|
||||||
|
|
||||||
return core.getNodeWrapper(result);
|
return core.getNodeWrapper(result);
|
||||||
|
@ -256,7 +260,6 @@ public class XmlObject {
|
||||||
* Transforms a XML literal into a HopObject
|
* Transforms a XML literal into a HopObject
|
||||||
*
|
*
|
||||||
* @param str an XML literal
|
* @param str an XML literal
|
||||||
*
|
|
||||||
* @return a HopObject obtained from parsing the XML
|
* @return a HopObject obtained from parsing the XML
|
||||||
*/
|
*/
|
||||||
public Object getFromString(String str) {
|
public Object getFromString(String str) {
|
||||||
|
@ -270,9 +273,7 @@ public class XmlObject {
|
||||||
*
|
*
|
||||||
* @param str an XML literal
|
* @param str an XML literal
|
||||||
* @param conversionRules a file name pointing to the conversion rules
|
* @param conversionRules a file name pointing to the conversion rules
|
||||||
*
|
|
||||||
* @return a HopObject obtained from parsing the XML
|
* @return a HopObject obtained from parsing the XML
|
||||||
*
|
|
||||||
* @see <http://helma.org/development/rfc/xmlconversion/>
|
* @see <http://helma.org/development/rfc/xmlconversion/>
|
||||||
*/
|
*/
|
||||||
public Object getFromString(String str, String conversionRules) {
|
public Object getFromString(String str, String conversionRules) {
|
||||||
|
@ -289,8 +290,7 @@ public class XmlObject {
|
||||||
converter = new XmlConverter();
|
converter = new XmlConverter();
|
||||||
}
|
}
|
||||||
|
|
||||||
INode node = new Node((String) null, (String) null,
|
INode node = new Node(null, null, core.getApplication().getWrappedNodeManager());
|
||||||
core.getApplication().getWrappedNodeManager());
|
|
||||||
INode result = converter.convertFromString(str, node);
|
INode result = converter.convertFromString(str, node);
|
||||||
|
|
||||||
return core.getNodeWrapper(result);
|
return core.getNodeWrapper(result);
|
||||||
|
|
Loading…
Add table
Reference in a new issue