summaryrefslogtreecommitdiff
path: root/java/src/IceGridGUI/XMLWriter.java
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2014-10-20 11:40:05 -0230
committerMatthew Newhook <matthew@zeroc.com>2014-10-20 11:40:05 -0230
commitb51469b41167fb86ae2059a15cf0475c53fdda7b (patch)
treefc85d6ca2efd89c67e1e4e7438f437c3e08313f4 /java/src/IceGridGUI/XMLWriter.java
parentFixed (ICE-5695) - IceSSL: misleading exception (diff)
downloadice-b51469b41167fb86ae2059a15cf0475c53fdda7b.tar.bz2
ice-b51469b41167fb86ae2059a15cf0475c53fdda7b.tar.xz
ice-b51469b41167fb86ae2059a15cf0475c53fdda7b.zip
Down with ant. From the gradle to the grave.
Diffstat (limited to 'java/src/IceGridGUI/XMLWriter.java')
-rw-r--r--java/src/IceGridGUI/XMLWriter.java169
1 files changed, 0 insertions, 169 deletions
diff --git a/java/src/IceGridGUI/XMLWriter.java b/java/src/IceGridGUI/XMLWriter.java
deleted file mode 100644
index 17304dc895c..00000000000
--- a/java/src/IceGridGUI/XMLWriter.java
+++ /dev/null
@@ -1,169 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2014 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<String[]> 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<String[]>)null);
- }
-
- public void writeElement(String name, String content) throws IOException
- {
- _writer.write(_indent);
- _writer.write("<" + name + ">" + escape(content) + "</" + name + ">" + _newline);
- }
-
- public void writeStartTag(String name, java.util.List<String[]> 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<String[]> attributes)
- throws IOException
- {
- if(attributes != null)
- {
- for(String[] p : attributes)
- {
- _writer.write(" " + p[0] + "=\"" + escape(p[1]) + "\"");
- }
- }
- }
-
- private void increaseIndent()
- {
- _indent += " ";
- }
-
- private void decreaseIndent()
- {
- if(_indent.length() > 0)
- {
- _indent = _indent.substring(3);
- }
- }
-
- private String
- escape(String input)
- {
- String v = input;
-
- //
- // Find out whether there is a reserved character to avoid
- // conversion if not necessary.
- //
- final String allReserved = "<>'\"&";
- boolean hasReserved = false;
- char[] arr = input.toCharArray();
- for(char c : arr)
- {
- if(allReserved.indexOf(c) != -1)
- {
- hasReserved = true;
- break;
- }
- }
- if(hasReserved)
- {
- //
- // First convert all & to &amp;
- //
- if(v.indexOf('&') != -1)
- {
- v = v.replaceAll("&", "&amp;");
- }
-
- //
- // Next convert remaining reserved characters.
- //
- if(v.indexOf('>') != -1)
- {
- v = v.replaceAll(">", "&gt;");
- }
- if(v.indexOf('<') != -1)
- {
- v = v.replaceAll("<", "&lt;");
- }
- if(v.indexOf('\'') != -1)
- {
- v = v.replaceAll("'", "&apos;");
- }
- if(v.indexOf('"') != -1)
- {
- v = v.replaceAll("\"", "&quot;");
- }
- }
- return v;
- }
-
- private Writer _writer;
- private String _indent = "";
- private static String _newline = System.getProperty("line.separator");
-}