java/trunk/conditions/src/main/java/org/hps/conditions/svt
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConfiguration.java 2014-08-14 22:53:25 UTC (rev 859)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConfiguration.java 2014-08-14 23:25:21 UTC (rev 860)
@@ -1,6 +1,7 @@
package org.hps.conditions.svt;
import java.io.ByteArrayInputStream;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
@@ -9,6 +10,8 @@
import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
/**
* This is a simple class for getting an SVT XML configuration file.
@@ -39,4 +42,32 @@
builder.setValidation(false);
return builder.build(inputStream);
}
-}
+
+ /**
+ * Save this configuration to a local file on disk.
+ * @param filename The name of the local file.
+ */
+ public void writeToFile(String filename) {
+ XMLOutputter out = new XMLOutputter();
+ out.setFormat(Format.getPrettyFormat());
+ try {
+ out.output(createDocument(), new FileWriter(filename));
+ } catch (IOException | JDOMException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Save this configuration to a local file on disk using its name from the database.
+ * @param filename The name of the local file.
+ */
+ public void writeToFile() {
+ XMLOutputter out = new XMLOutputter();
+ out.setFormat(Format.getPrettyFormat());
+ try {
+ out.output(createDocument(), new FileWriter(getFileName()));
+ } catch (IOException | JDOMException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
\ No newline at end of file