summaryrefslogtreecommitdiff
path: root/java/src/IceGridGUI/XMLWriter.java
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2006-03-29 21:21:02 +0000
committerBernard Normier <bernard@zeroc.com>2006-03-29 21:21:02 +0000
commit20744ae1f1182d08e26b175f59d14041aabaf754 (patch)
tree937d125b80663966b3a61e13e744e28daf1f22da /java/src/IceGridGUI/XMLWriter.java
parentJava metadata (diff)
downloadice-20744ae1f1182d08e26b175f59d14041aabaf754.tar.bz2
ice-20744ae1f1182d08e26b175f59d14041aabaf754.tar.xz
ice-20744ae1f1182d08e26b175f59d14041aabaf754.zip
IceGrid GUI refactoring
Diffstat (limited to 'java/src/IceGridGUI/XMLWriter.java')
-rwxr-xr-xjava/src/IceGridGUI/XMLWriter.java117
1 files changed, 117 insertions, 0 deletions
diff --git a/java/src/IceGridGUI/XMLWriter.java b/java/src/IceGridGUI/XMLWriter.java
new file mode 100755
index 00000000000..d3e44aa2681
--- /dev/null
+++ b/java/src/IceGridGUI/XMLWriter.java
@@ -0,0 +1,117 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI;
+
+import java.io.*;
+
+//
+// Helper class to write XML files
+//
+public class XMLWriter
+{
+ public XMLWriter(File file) throws FileNotFoundException, IOException
+ {
+ try
+ {
+ _writer = new BufferedWriter(
+ new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
+ }
+ catch(UnsupportedEncodingException e)
+ {
+ assert false;
+ }
+ _writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + _newline);
+ _writer.write("<!-- This file was written by IceGrid Admin -->" + _newline);
+ }
+
+ public void writeElement(String name, java.util.List attributes)
+ throws IOException
+ {
+ _writer.write(_indent);
+ _writer.write("<" + name);
+ writeAttributes(attributes);
+ _writer.write("/>" + _newline);
+ }
+
+ public void writeElement(String name) throws IOException
+ {
+ writeElement(name, (java.util.List)null);
+ }
+
+ public void writeElement(String name, String content) throws IOException
+ {
+ //
+ // TODO: deal with ]]> content
+ //
+ _writer.write(_indent);
+ _writer.write("<" + name + "><![CDATA[" + content
+ + "]]></" + name + ">" + _newline);
+ }
+
+ public void writeStartTag(String name, java.util.List attributes)
+ throws IOException
+ {
+ _writer.write(_indent);
+ _writer.write("<" + name);
+ writeAttributes(attributes);
+ _writer.write(">");
+ _writer.write(_newline);
+ increaseIndent();
+ }
+
+ public void writeStartTag(String name) throws IOException
+ {
+ writeStartTag(name, null);
+ }
+
+ public void writeEndTag(String name) throws IOException
+ {
+ decreaseIndent();
+ _writer.write(_indent);
+ _writer.write("</" + name + ">" + _newline);
+ }
+
+ public void close() throws IOException
+ {
+ _writer.close();
+ }
+
+ public void flush() throws IOException
+ {
+ _writer.flush();
+ }
+
+ private void writeAttributes(java.util.List attributes)
+ throws IOException
+ {
+ if(attributes != null)
+ {
+ java.util.Iterator p = attributes.iterator();
+ while(p.hasNext())
+ {
+ String[] pair = (String[])p.next();
+ _writer.write(" " + pair[0] + "=\"" + pair[1] + "\"");
+ }
+ }
+ }
+
+ private void increaseIndent()
+ {
+ _indent += " ";
+ }
+
+ private void decreaseIndent()
+ {
+ _indent = _indent.substring(3);
+ }
+
+ private Writer _writer;
+ private String _indent = "";
+ private static String _newline = System.getProperty("line.separator");
+}