Source:
public static boolean isFoundWebApplication(String filePath, boolean bTarget) throws Exception { if (isFoundTagName(filePath, "webApplication")) return true; boolean bFound = false; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(filePath); NodeList appList = doc.getElementsByTagName("application"); if (isFoundWebAppElement(appList)) return true; if (bTarget) { NodeList incList = doc.getElementsByTagName("include"); if (incList == null) return false; for (int i = 0; i < incList.getLength(); i++) { Node locNode = incList.item(i).getAttributes().getNamedItem("location"); Document incDoc = null; if (locNode != null && locNode.getNodeValue() != null && locNode.getNodeValue().endsWith(".xml")) { if (locNode.getNodeValue().startsWith("http")) { URL url = new URL(locNode.getNodeValue()); URLConnection connection = url.openConnection(); incDoc = builder.parse(connection.getInputStream()); } else { File dir = new File(filePath); File file = new File(dir.getParent(), locNode.getNodeValue()); if (file.exists()) { InputStream inputStream = new FileInputStream(file.getCanonicalPath()); incDoc = builder.parse(inputStream); } } } if (incDoc != null) { NodeList webappNodeList = incDoc.getElementsByTagName("webApplication"); if (webappNodeList != null && webappNodeList.getLength() > 0) return true; else { NodeList apps = incDoc.getElementsByTagName("application"); if (isFoundWebAppElement(apps)) return true; } } } } return bFound; }

Target:
public static boolean isFoundWebApplication(String filePath, boolean bTarget) throws Exception { if (isFoundTagName(filePath, "webApplication")) return true; boolean bFound = false; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(filePath); NodeList appList = doc.getElementsByTagName("application"); if (isFoundWebAppElement(appList)) return true; if (bTarget) { if (isFoundInConfigDropinsDir(filePath)) return true; NodeList incList = doc.getElementsByTagName("include"); if (incList == null) return false; for (int i = 0; i < incList.getLength(); i++) { Node locNode = incList.item(i).getAttributes().getNamedItem("location"); Document incDoc = null; if (locNode != null) { String locValue = locNode.getNodeValue(); if (locValue != null && locValue.endsWith(".xml")) { if (locValue.startsWith("http")) { if (isValidURL(locValue)) { URL url = new URL(locValue); URLConnection connection = url.openConnection(); incDoc = builder.parse(connection.getInputStream()); } } else if (locValue.startsWith("file:")) { if (isValidURL(locValue)) { File locFile = new File(locValue); if (locFile.exists()) { InputStream inputStream = new FileInputStream(locFile.getCanonicalPath()); incDoc = builder.parse(inputStream); } } } else if (!locValue.startsWith("ftp:")){ File serverFile = new File(filePath); File locFile = new File(serverFile.getParent(), locValue); if (locFile.exists()) { InputStream inputStream = new FileInputStream(locFile.getCanonicalPath()); incDoc = builder.parse(inputStream); } } } } if (incDoc != null) { NodeList webappNodeList = incDoc.getElementsByTagName("webApplication"); if (webappNodeList != null && webappNodeList.getLength() > 0) return true; else { NodeList apps = incDoc.getElementsByTagName("application"); if (isFoundWebAppElement(apps)) return true; } } } } return bFound; }