public static WebAppDocument convertToServletSchema(XmlObject xmlObject) throws XmlException {
if (WebAppDocument.type.equals(xmlObject.schemaType())) {
validateDD(xmlObject);
return (WebAppDocument) xmlObject;
}
XmlCursor cursor = xmlObject.newCursor();
try {
cursor.toStartDoc();
cursor.toFirstChild();
if ("http://java.sun.com/xml/ns/j2ee".equals(cursor.getName().getNamespaceURI())) {
XmlObject result = xmlObject.changeType(WebAppDocument.type);
validateDD(result);
return (WebAppDocument) result;
}
XmlDocumentProperties xmlDocumentProperties = cursor.documentProperties();
String publicId = xmlDocumentProperties.getDoctypePublicId();
if ("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN".equals(publicId) ||
"-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN".equals(publicId)) {
XmlCursor moveable = xmlObject.newCursor();
try {
moveable.toStartDoc();
moveable.toFirstChild();
String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
String version = "2.4";
convertToSchema(cursor, J2EE_NAMESPACE, schemaLocationURL, version);
cursor.toStartDoc();
cursor.toChild(J2EE_NAMESPACE, "web-app");
cursor.toFirstChild();
convertToDescriptionGroup(cursor, moveable);
convertToJNDIEnvironmentRefsGroup(cursor, moveable);
cursor.push();
if (cursor.toNextSibling(TAGLIB)) {
cursor.toPrevSibling();
moveable.toCursor(cursor);
cursor.beginElement("jsp-config", J2EE_NAMESPACE);
while (moveable.toNextSibling(TAGLIB)) {
moveable.moveXml(cursor);
}
}
cursor.pop();
do {
String name = cursor.getName().getLocalPart();
if ("filter".equals(name) || "servlet".equals(name)) {
cursor.push();
cursor.toFirstChild();
convertToDescriptionGroup(cursor, moveable);
if (cursor.toNextSibling(J2EE_NAMESPACE, "init-param")) {
cursor.toFirstChild();
convertToDescriptionGroup(cursor, moveable);
}
cursor.pop();
}
} while (cursor.toNextSibling());
} finally {
moveable.dispose();
}
}
} finally {
cursor.dispose();
}