@Override public JspMetadata fileEntryToMeta(FileMetadata entry) { File file = entry.getFilePointer(); LOG.debug("Processing: " + file.getAbsolutePath()); JspMetadata meta = new JspMetadata(); meta.setArchiveMeta(entry.getArchiveMeta()); meta.setFilePointer(file); return meta; }
@Override public void processMeta(JspMetadata meta) { try { String jspContents = FileUtils.readFileToString(meta.getFilePointer()); findImports(jspContents, jspImport, meta); findTaglib(jspContents, jspTagLib, meta); // findDeprecatedJspQuotes(jspContents, jsp2DeprecatedQuotes, meta); } catch (IOException e) { LOG.error("Exception with Regular Expressions.", e); } }
protected void findTaglib(String html, Pattern thePattern, JspMetadata meta) { Matcher matcher = thePattern.matcher(html); while (matcher.find()) { String matched = matcher.group(1); if (StringUtils.isNotBlank(matched)) { if (lineContainsNamespaceBlacklist(matched)) { Line lr = new Line(); lr.setDescription("Blacklist Namespace: " + matched); lr.setLineNumber(NewLineUtil.countNewLine(html, matcher.start())); lr.setPattern(matched); for (ResultProcessor hint : hints) { hint.process(lr); } meta.getDecorations().add(lr); } meta.getTaglibDependencies().add(matched); } } }
protected void findImports(String html, Pattern thePattern, JspMetadata meta) { Matcher matcher = thePattern.matcher(html); while (matcher.find()) { String matched = matcher.group(1); if (StringUtils.isNotBlank(matched)) { String[] imports = StringUtils.split(matched, ","); if (imports != null) { for (String imp : imports) { imp = StringUtils.trim(imp); if (lineContainsClassBlacklist(imp)) { Line lr = new Line(); lr.setDescription("Blacklist: " + imp); lr.setLineNumber(NewLineUtil.countNewLine(html, matcher.start())); lr.setPattern(imp); for (ResultProcessor hint : hints) { hint.process(lr); } meta.getDecorations().add(lr); } meta.getClassDependencies().add(imp); } } } } }
/** * Detects deprecated jsp quote syntax e.g * <tags:tag attr1="<%="hello world"%>" attr2="<%=\"valid\"%>" attr3="<%= print.me("hello world") %>" /> * attr1 and attr3 are invalid syntax * * @param html * The content of the jsp * @param thePattern * The regular expression * @param meta * Meta data for the results */ protected void findDeprecatedJspQuotes(String html, Pattern thePattern, JspMetadata meta) { Matcher matcher = thePattern.matcher(html); while (matcher.find()) { String matched = matcher.group(1); if (StringUtils.isNotBlank(matched)) { Line lr = new Line(); lr.setDescription("Deprecated jsp syntax: " + matched); lr.setLineNumber(NewLineUtil.countNewLine(html, matcher.start())); lr.setPattern(matched); for (ResultProcessor hint : hints) { hint.process(lr); } meta.getDecorations().add(lr); } } }
@Override public JspMetadata archiveEntryToMeta(ZipEntryMetadata archiveEntry) { File file = archiveEntry.getFilePointer(); LOG.debug("Processing: " + file.getAbsolutePath()); JspMetadata meta = new JspMetadata(); meta.setArchiveMeta(archiveEntry.getArchiveMeta()); meta.setFilePointer(file); return meta; } }