mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-08 06:01:22 +00:00
Use StAX to write config XML.
This commit is contained in:
@@ -19,11 +19,13 @@ package net.sourceforge.guacamole.net.basic;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.xml.stream.XMLOutputFactory;
|
||||||
|
import javax.xml.stream.XMLStreamException;
|
||||||
|
import javax.xml.stream.XMLStreamWriter;
|
||||||
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
import net.sourceforge.guacamole.protocol.GuacamoleConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,23 +47,38 @@ public class ConfigurationList extends AuthenticatingHttpServlet {
|
|||||||
|
|
||||||
// Write XML
|
// Write XML
|
||||||
response.setHeader("Content-Type", "text/xml");
|
response.setHeader("Content-Type", "text/xml");
|
||||||
PrintWriter out = response.getWriter();
|
|
||||||
out.println("<configs>");
|
|
||||||
|
|
||||||
for (Entry<String, GuacamoleConfiguration> entry : configs.entrySet()) {
|
try {
|
||||||
|
|
||||||
GuacamoleConfiguration config = entry.getValue();
|
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||||
|
XMLStreamWriter xml = outputFactory.createXMLStreamWriter(response.getWriter());
|
||||||
|
|
||||||
// Write config
|
// Begin document
|
||||||
out.print("<config id=\"");
|
xml.writeStartDocument();
|
||||||
out.print(entry.getKey());
|
xml.writeStartElement("configs");
|
||||||
out.print("\" protocol=\"");
|
|
||||||
out.print(config.getProtocol());
|
// For each entry, write corresponding config element
|
||||||
out.println("\"/>");
|
for (Entry<String, GuacamoleConfiguration> entry : configs.entrySet()) {
|
||||||
|
|
||||||
|
// Get config
|
||||||
|
GuacamoleConfiguration config = entry.getValue();
|
||||||
|
|
||||||
|
// Write config
|
||||||
|
xml.writeEmptyElement("config");
|
||||||
|
xml.writeAttribute("id", entry.getKey());
|
||||||
|
xml.writeAttribute("protocol", config.getProtocol());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// End document
|
||||||
|
xml.writeEndElement();
|
||||||
|
xml.writeEndDocument();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
catch (XMLStreamException e) {
|
||||||
|
throw new IOException("Unable to write configuration list XML.", e);
|
||||||
|
}
|
||||||
|
|
||||||
out.println("</configs>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user