Tuesday, November 22, 2011

Opening another new window

Okay, not on upgrading today ... more of an enhancement.

On most pages there's a link for opening a "New Window".  The newwin servlet can do the same thing, if you have the URL to open.  Over at PeopleSoft Wiki they have a function that takes your current URL and gives you a new URL that will open as a second window with the "_1".  The limitation with the listed code is that if you already have a second window open, it won't work.  So here's an improvement.


/******************************************************
AnotherWinUrl(&strUrl)
This function modifies a URL to return a new window URL. It allows a new state block to be generated in a separate browser instance.
http://servername:port/psp/ps/EMPLOYEE/HRMS/c/...
 or
http://servername:port/psp_1/ps/EMPLOYEE/HRMS/c/...    (or _2, etc)
 becomes
http://servername:port/psp/ps_newwin/EMPLOYEE/HRMS/c/...  
 which the web server turns into  
http://server:port/psp/ps_1/EMPLOYEE/HRMS/c/...        (or _3, etc)
Input parameters: &strUrl - a URL to manipulate Output parameters:
&strUrlModified - New URL with _newwin parameter
************************************************/
Function AnotherWinUrl(&strUrl As string) Returns string;
   Local string &sRegEx, &sReplace, &NewWinURL;
   /* Declare java object */
   Local JavaObject &jUrl;


   &sRegEx =
   "/(ps[cp])/([^\/_]*)?(_[1-9])?/([^\/]*)?/([^\/]*)?/([csehtqwnf]{1})/";
   &sReplace = "/$1/$2_newwin/$4/$5/$6/";

   /* Instantiate objects */
   &jUrl = CreateJavaObject("java.lang.String", &strUrl);
   &NewWinURL = &jUrl.replaceAll(&sRegex, &sReplace);

   /* Return modified URL */
   Return &NewWinURL;
End-Function;

The original second pattern ($2) said it was made of non-slash characters. I added that it should also not be an underscore. Then I added a pattern ($3) of an underscore followed by a number. Then this third pattern is excluded in the replace string.

The PeopleSoft Wiki had a link to this site, http://gskinner.com/RegExr/ which makes testing these much easier.


No comments:

Post a Comment