Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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()

share|improve this question
1  
What 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? –  Tom Wijsman Aug 20 '12 at 16:02
    
Edited my answer - see EDIT –  Toskan Aug 20 '12 at 16:18
    
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 Aug 20 '12 at 16:37
add comment

1 Answer

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"

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.