Windows program / tool needed for recursively searching through files referenced from within a file

3

Following scenario: I browse for unsafeMethodCall() in all my web pages. This method is only unsafe in case that there is a reference of doSomeCrazyAjaxStuff()

My web pages are using strong templating (i.e. it was built with JSF)

so a webpage consists out of something like this:

<ui:decorate template="/mypages/editing/someWebPagePart.xhtml">
unsafeMethodCall()

this just copies the contents of the template into the current webpage.

So if I search for unsafeMethodCall() - the problem is I have to manually open someWebPagePart.xhtml to search for crazyAjaxStuff() - but someWebPagePart.xhtml might be using other templates. So from 1 hit of unsafeMethodCalls I can end up with A LOT of pages I have to open.

So I basically want to scan a file named "somefile.xhtml" for any occurrences of a template. If there is a template I want to search in that template as well, and I want to search in the template of the template etc. as well :-)

Is there a program or tool which could solve this problem?

[EDIT]

So basically I have a file with this contents: (this is just an example)

<div> 
<input value="enterusername"/>    
   </div>
[...more random web page contents like above this line....]
<ui:decorate template="/mypages/editing/someWebPagePart.xhtml">
     <my:tag>  unsafeMethodCall()</my:tag> <!-- this is potentially dangerous with another function call  -->
[...more random web page contents like below this line....]
<p></p>
<a href="#Other-Options" accesskey="n" rel="next">Other Options</a>

When I now open d:/dev/workspace/WebContents/mypages/editing/someWebPagePart.xhtml I will be able to see what finally is actually displayed on the page - because the contents of someWebPagePart.xhtml will be automagically copied by the web server to the final web page. What I am looking for in the file someWebPagePart.xhtml is something like this:

<div> 
<input value="enterusername"/>    
   </div>
[...more random web page contents like above this line....]
<ui:decorate template="/mypages/editing/someotherPage.xhtml"> <!-- it could be in there as well -->
     <my:tag2>  crazyAjaxStuff()</my:tag2> <!-- searching this -->
[...more random web page contents like below this line....]
<p></p>
<a href="#Other-Options" accesskey="n" rel="next">Other Options</a>

Since:

 <my:tag2>  crazyAjaxStuff()</my:tag2>

will be copied to the same page where unsafeMethodCall is located, this can lead to a dangerous condition and I'd have to take a close look at the page.

Note: it very well can be possible that the 3rd page someotherPage.xhtml contains the dangerous crazyAjaxStuff()

Toskan

Posted 2012-08-20T15:32:35.713

Reputation: 297

1What do you mean with "there is a reference of"? Can you extend your example to at least include two or three files and actually contains the different calls that you sum up? – Tamara Wijsman – 2012-08-20T16:02:38.400

Edited my answer - see [EDIT] – Toskan – 2012-08-20T16:18:11.623

Since it looks like you're using JSP, you're probably familiar with Java in general. This sounds like something you'd probably be best off just writing a quick command line utility for. It seems pretty isolated of a use-case to be included as a feature in a released program. – corsiKa – 2012-08-20T16:37:02.730

Answers

0

I would use ack from the command line. It's fast, it will show you the line numbers in your code and the files where they are. It will do it recursively and the output will be a bit pretty with colors. You can get really fancy with the regex and you can pipe it to itself to search through the files you find with unsafeMethodCall for crazyAjaxStuff. Just read the documentation and get creative. If you need it for Windows see this

Install ack:

curl http://betterthangrep.com/ack-standalone > ~/bin/ack && chmod 0755 !#:3

Run it, searching all file types, case insensitvely, recursively with literal pattern

ack -airQ "unsafeMethodCall"

Or use the -l switch to just get the file paths, and then pipe that through another ack command or another tool.

ack -larQ "unsafeMethodCall"

Anthony Hatzopoulos

Posted 2012-08-20T15:32:35.713

Reputation: 244