Generate a web.xml in String form that matches the representation stored in this object. @return The complete contents of web.xml as a String
()
| 1360 | * @return The complete contents of web.xml as a String |
| 1361 | */ |
| 1362 | public String toXml() { |
| 1363 | StringBuilder sb = new StringBuilder(2048); |
| 1364 | // TODO - Various, icon, description etc elements are skipped - mainly |
| 1365 | // because they are ignored when web.xml is parsed - see above |
| 1366 | |
| 1367 | // NOTE - Elements need to be written in the order defined in the 2.3 |
| 1368 | // DTD else validation of the merged web.xml will fail |
| 1369 | |
| 1370 | // NOTE - Some elements need to be skipped based on the version of the |
| 1371 | // specification being used. Version is validated and starts at |
| 1372 | // 2.2. The version tests used in this method take advantage of |
| 1373 | // this. |
| 1374 | |
| 1375 | // Declaration |
| 1376 | sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
| 1377 | |
| 1378 | // Root element |
| 1379 | if (publicId != null) { |
| 1380 | sb.append("<!DOCTYPE web-app PUBLIC\n"); |
| 1381 | sb.append(" \""); |
| 1382 | sb.append(publicId); |
| 1383 | sb.append("\"\n"); |
| 1384 | sb.append(" \""); |
| 1385 | if (XmlIdentifiers.WEB_22_PUBLIC.equals(publicId)) { |
| 1386 | sb.append(XmlIdentifiers.WEB_22_SYSTEM); |
| 1387 | } else { |
| 1388 | sb.append(XmlIdentifiers.WEB_23_SYSTEM); |
| 1389 | } |
| 1390 | sb.append("\">\n"); |
| 1391 | sb.append("<web-app>"); |
| 1392 | } else { |
| 1393 | String javaeeNamespace = null; |
| 1394 | String webXmlSchemaLocation = null; |
| 1395 | String version = getVersion(); |
| 1396 | if ("2.4".equals(version)) { |
| 1397 | javaeeNamespace = XmlIdentifiers.JAVAEE_1_4_NS; |
| 1398 | webXmlSchemaLocation = XmlIdentifiers.WEB_24_XSD; |
| 1399 | } else if ("2.5".equals(version)) { |
| 1400 | javaeeNamespace = XmlIdentifiers.JAVAEE_5_NS; |
| 1401 | webXmlSchemaLocation = XmlIdentifiers.WEB_25_XSD; |
| 1402 | } else if ("3.0".equals(version)) { |
| 1403 | javaeeNamespace = XmlIdentifiers.JAVAEE_6_NS; |
| 1404 | webXmlSchemaLocation = XmlIdentifiers.WEB_30_XSD; |
| 1405 | } else if ("3.1".equals(version)) { |
| 1406 | javaeeNamespace = XmlIdentifiers.JAVAEE_7_NS; |
| 1407 | webXmlSchemaLocation = XmlIdentifiers.WEB_31_XSD; |
| 1408 | } else if ("4.0".equals(version)) { |
| 1409 | javaeeNamespace = XmlIdentifiers.JAVAEE_8_NS; |
| 1410 | webXmlSchemaLocation = XmlIdentifiers.WEB_40_XSD; |
| 1411 | } else if ("5.0".equals(version)) { |
| 1412 | javaeeNamespace = XmlIdentifiers.JAKARTAEE_9_NS; |
| 1413 | webXmlSchemaLocation = XmlIdentifiers.WEB_50_XSD; |
| 1414 | } else if ("6.0".equals(version)) { |
| 1415 | javaeeNamespace = XmlIdentifiers.JAKARTAEE_10_NS; |
| 1416 | webXmlSchemaLocation = XmlIdentifiers.WEB_60_XSD; |
| 1417 | } else if ("6.1".equals(version)) { |
| 1418 | javaeeNamespace = XmlIdentifiers.JAKARTAEE_11_NS; |
| 1419 | webXmlSchemaLocation = XmlIdentifiers.WEB_61_XSD; |