1 package com
.google
.apphosting
.utils
.config
;
3 import org
.mortbay
.xml
.XmlParser
;
5 import java
.io
.InputStream
;
8 * Constructs an {@link AppEngineApplicationXml} from an xml document
9 * corresponding to appengine-application.xsd.
11 * <p>We use Jetty's {@link XmlParser} utility to match other Appengine XML
15 public class AppEngineApplicationXmlReader
{
16 private static final String EMPTY_STRING
= "";
19 * Construct an {@link AppEngineApplicationXml} from the xml document
20 * within the provided {@link InputStream}.
22 * @param is The InputStream containing the xml we want to parse and process
24 * @return Object representation of the xml document
25 * @throws AppEngineConfigException If the input stream cannot be parsed
27 public AppEngineApplicationXml
processXml(InputStream is
) throws AppEngineConfigException
{
28 AppEngineApplicationXml
.Builder builder
= new AppEngineApplicationXml
.Builder();
29 String applicationId
= EMPTY_STRING
;
30 for (Object o
: XmlUtils
.parse(is
)) {
31 if (!(o
instanceof XmlParser
.Node
)) {
34 XmlParser
.Node node
= (XmlParser
.Node
) o
;
35 if (node
.getTag().equals("application")) {
36 applicationId
= XmlUtils
.getText(node
);
38 throw new AppEngineConfigException("Unrecognized element <" + node
.getTag()
39 + "> in appengine-application.xml.");
42 if (applicationId
.equals(EMPTY_STRING
)) {
43 throw new AppEngineConfigException(
44 "Missing or empty <application> element in appengine-application.xml.");
46 return builder
.setApplicationId(applicationId
).build();