A brief survey: Server pages and browser pages
When you open a web page with VSW you really view what web server has sent to your browser.
If you request plain HTML pages (without javascript) what you see with VSW is the same sent by web server.
Many times your browser shows the result produced by, so called, server pages, these pages are generated on web server using many programming languages (e.g. PHP, JSP, ASP and many others).
So when you open a web page with VSW from your browser you can't edit the original server page but what you see is only the HTML (or XML or text) result.
How can VSW help web programmers: Editing server pages
Now VSW has the ability to open the server page(s) associated to the URL you are visiting, obviously if you have the access to them!
The first benefit consists to edit (not only view) directly the real pages.
You only need to create a mapping between the URL and the local path where reside the source server pages.
Matching url: Mapping filters and regular expressions
Suppose you point your browser to http://mywebserver/mywebapp/index.php and your PHP files are located on
your hard disk at c:\myprojects\mywebapp\php-pages, you can create a mapping to open index.php not only what you see in your browser application window.
To do this you specify a regular expression matching your URL.
When the URL is matched the source file is "searched" inside the specified local path and if found is open.
So if you want to match any page inside http://mywebserver/mywebapp/ you specify the following regular expression
http://mywebserver/mywebapp/*
More complex regular expressions can be defined based on your needs.
How local page search is done
The default behaviour is very simple (see below how you can change default behaviour).
Every strings following the matched regular expression is appended to local path, this allows to open files inside subdirectories.
| Suppose your regular expression is | http://mywebserver/mywebapp/* |
| you request the page | http://mywebserver/mywebapp/useragent1/hello.php |
| the string following the matched RE is | useragent1/hello.php |
| append it to local path | c:\myprojects\mywebapp\php-pages |
| and finally the c:\myprojects\mywebapp\php-pages\useragent1\hello.php is found and open | |
As you can see extra subdirectories are appended without any special action.
Necessary platform dependant path separators are added automatically.
Now VSW opens two files...
When VSW matches a mapping it opens two files
- the temporary file (server side generated), simply what you ever seen with VSW
- the real server page source file
So you can immediately view what is the page source result produced and edit the origin page.
but somebody says...
"I need to open only server side page, please don't hurt me with the temporary file"
"Hey guy I want to open other files associated to server side source for example log file"
VSW is enough flexible to allow you decide what files open but you need to know a bit (honestly more than a bit) of Javascript.
As you can see in mapping dialog there is a text area where you can insert your own javascript code.
The javascript must follows some constraints.
The best way to start consists to click on JS button and see the code shown.
The code shown is the same executed by default (ie when the text area is left blank).
Look at the end
// Contains the file name(s) to open [1] var arFiles = new Array(); [2] ... [3] ... [4] // comment line below if you don't want [5] // to open the temporary file [6] arFiles.push(data.pageSourcePath); [7] arFiles.push(localPath + dirSep + fileName); [8] [9] //var mylogFileName = "/usr/tmp/mywebapp/log/stuff.log"; [10] //arFiles.push(mylogFileName); [11] [12] return arFiles;
The code returns an array of file names.
At line number 6 the temporary file is added to array, line number 7 instead adds the real page source.
If you hurt the temporary file simply comment (or delete) the line number 6.
Do you want to open log file or whatever you want?
Simply you need to add a new element to array as shown at lines number 9 and 10.
The default search file algorithm doesn't fit my needs
No problem, maybe!
Your javascript code receives the parameter data that contains useful informations passed by the caller.
Take another look to default JS code and see how data parameter is used.
| Parameter name | What it does |
| data.uri | the URI data from which you called VSW (in example above http://mywebserver/mywebapp/useragent1/hello.php) see nsIURL at xulplanet |
| data.localPath | the localPath defined in urlMapper dialog (should be empty or null) |
| data.domainFilter | the regular expression defined in urlMapper dialog |
| data.pageSourcePath | the path to page source retrieved by browser |
You can use these informations to totally rewrite the file open code