1 package com
.google
.apphosting
.utils
.config
;
3 import org
.mortbay
.xml
.XmlParser
;
4 import org
.mortbay
.xml
.XmlParser
.Node
;
5 import org
.xml
.sax
.SAXException
;
7 import java
.io
.IOException
;
8 import java
.io
.InputStream
;
9 import java
.util
.logging
.Level
;
10 import java
.util
.logging
.Logger
;
13 * Utility functions for processing XML.
15 public class XmlUtils
{
16 private static final Logger logger
= Logger
.getLogger(XmlUtils
.class.getName());
18 static String
getText(XmlParser
.Node node
) throws AppEngineConfigException
{
19 Object child
= node
.get(0);
24 if (!(child
instanceof String
)) {
25 String msg
= "Invalid XML: String content expected in node '" + node
.getTag() + "'.";
26 logger
.log(Level
.SEVERE
, msg
);
27 throw new AppEngineConfigException(msg
);
29 value
= (String
) child
;
36 * Parses the input stream and returns the {@link Node} for the root element.
38 * @throws AppEngineConfigException If the input stream cannot be parsed.
40 static Node
parse(InputStream is
) {
41 XmlParser xmlParser
= new XmlParser();
43 return xmlParser
.parse(is
);
44 } catch (IOException e
) {
45 String msg
= "Received IOException parsing the input stream.";
46 logger
.log(Level
.SEVERE
, msg
, e
);
47 throw new AppEngineConfigException(msg
, e
);
48 } catch (SAXException e
) {
49 String msg
= "Received SAXException parsing the input stream.";
50 logger
.log(Level
.SEVERE
, msg
, e
);
51 throw new AppEngineConfigException(msg
, e
);