JSPImportParser { public static Collection<String> getImports (InputStream is) throws IOException { Collection<String> importedPackages = new LinkedList<String>(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line = null; do { line = reader.readLine(); if (line != null) { Matcher hasJSPimport = lineWithJSPimport.matcher(line); if (hasJSPimport.find()) { Collection<String> foundImports = searchMatchedGroupForImports (hasJSPimport.group()); for (String found : foundImports) { if (!importedPackages.contains(found)) { importedPackages.add(found); } } } } } while (line != null); return importedPackages; }  static Collection<String> getImports(InputStream is);  }
@Test public void testJSPImportParser () throws Exception { InputStream helloImport = getClass().getClassLoader().getResourceAsStream("JSPs/helloImport.jsp"); Collection<String> imports = JSPImportParser.getImports(helloImport); assertTrue("Four imports expected", imports.size() == 4); assertTrue(imports.contains("javax.jms")); assertTrue(imports.contains("javax.mystuff")); assertTrue(imports.contains("javax.transaction")); assertTrue(imports.contains("a.b")); assertFalse(imports.contains("java.util")); }