JspAnalyzerPlugin implements AnalyzerPlugin { protected Set<String> getTaglibURIs(String originalContent) { String content = _removeComments(originalContent); int contentX = -1; int contentY = content.length(); Set<String> taglibURis = new HashSet<String>(); while (true) { contentX = content.lastIndexOf("<%@", contentY); if (contentX == -1) { break; } contentY = contentX; int importX = content.indexOf("uri=\"", contentY); int importY = -1; if (importX != -1) { importX = importX + "uri=\"".length(); importY = content.indexOf("\"", importX); } if ((importX != -1) && (importY != -1)) { String s = content.substring(importX, importY); taglibURis.add(s); } contentY -= 3; } return taglibURis; }  @Override boolean analyzeJar(Analyzer analyzer);  }
@Test public void testGetTaglibURIsWithComments() throws Exception { JspAnalyzerPlugin jspAnalyzerPlugin = new JspAnalyzerPlugin(); URL url = getResource("dependencies/imports_with_comments.jsp"); InputStream inputStream = url.openStream(); String content = IO.collect(inputStream); Set<String> taglibURIs = jspAnalyzerPlugin.getTaglibURIs(content); Assert.assertNotNull(taglibURIs); int size = taglibURIs.size(); Assert.assertEquals(3, size); }
@Test public void testGetTaglibURIsWithoutComments() throws Exception { JspAnalyzerPlugin jspAnalyzerPlugin = new JspAnalyzerPlugin(); URL url = getResource("dependencies/imports_without_comments.jsp"); InputStream inputStream = url.openStream(); String content = IO.collect(inputStream); Set<String> taglibURIs = jspAnalyzerPlugin.getTaglibURIs(content); Assert.assertNotNull(taglibURIs); int size = taglibURIs.size(); Assert.assertEquals(8, size); }