• Welcome to OS2World OLD-STATIC-BACKUP Forum.
 

News:

This is an old OS2World backup forum for reference only. IT IS READ ONLY!!!

If you need help with OS/2 - eComStation visit http://www.os2world.com/forum

Main Menu

Create a URL object that is supported by Warp 3 as well

Started by jep, 2008.04.28, 21:41:27

Previous topic - Next topic

jep

Marked as: Normal
Hello,

this example show you how to create URL objects in Warp 3 and Warp 4 (end eComStation) but also how you can interpret %20 and %28, %29 etc. often found in URLs.

//Jan-Erik

/* Create a URL object that is supported by Warp 3 as well */
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

call CreateURL 'http://www.os2world.com', '<WP_DESKTOP>', 'OS2WORLD'

Return rc

CreateURL: PROCEDURE
/* URL, save_in_folder¹, object_identification_name² */
/* ¹) This can be specified as either an object ID ( for example, <WP_DESKTOP> ) */
/*     or a file system path ( for example, C:\Desktop ) */
/* ²) This can be specified as <my_ul_object_id_1234>, with or without "<" and ">" */

url = ARG(1)
objid = ARG(3)
IF LENGTH( objid ) = 0 THEN
   objid = SysTempFileName( '???????.???' )
objid = '<'||translate( objid,, '<>' )||'>'

/* Remove characters from object name, */
/* and add them back, just to ensure that */
/* we can handle object id names not in the form '<...>' */

object = SysTempFileName( 'add!????' )
title = GetFileFromURL( url )

IF SysOs2Ver() > "2.30" THEN
  rc = SysCreateObject( 'WPUrl', object, ARG(2), 'OBJECTID='||objid||';TITLE='||title||';URL='||url, 'U')
ELSE
  rc = SysCreateObject('WebExplorer_Url', title, url, 'OBJECTID='||objid||';LOCATOR='||url||';', 'U')
RETURN rc

DecodeURL: PROCEDURE
PARSE ARG url
DO WHILE POS( '%', url ) > 0
  i = POS( '%', url )
  url = SUBSTR( url, 1, i-1 )||X2C(SUBSTR( url, i+1, 2 ))||SUBSTR( url, i+3 )
END
RETURN url

GetFileFromURL: PROCEDURE
/* URL syntax consists of six components: */
/* <scheme>://<net_loc_and_path>/<fname>;<params>?<query>#<fragment> */

PARSE VALUE FILESPEC( 'N', ARG(1) ) WITH url'#'.
PARSE VALUE retval WITH url'?'.
PARSE VALUE retval WITH url';'.
RETURN DecodeURL( url )

Saijin_Naib

I wonder jep, if you could do something that would parse favorites (internet shortcuts) as stored by Windows? Here is a text-file dump of an internet shortcut object generated in Windows XP.

[DEFAULT]
BASEURL=http://www.lacrosseforums.com/showthread.php?p=497727
[InternetShortcut]
URL=http://www.lacrosseforums.com/showthread.php?p=497727#post497727
IDList=
IconFile=http://www.lacrosseforums.com/favicon.ico
IconIndex=1
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2

Maybe direct support for this could be added to eCS so that firefox can launch these directly? I have a whole TON of sites bookmarked/organized under IE7 in WXP that I wouldn't mind having access to under eCS.

Thanks!

jep

Hello,

Thank you for your suggestion/question, don't hesitate to ask for more scripts.

Someone with the skills would have to make it accept the format Win use. OS/2-eCS list the first line as the url, while the Win version place [Internetshortcut] there.

Here's the code for you, it'll create folder ( My Internet Links ) on your desktop where it place your internet urls converted to OS/2-eCS style.

Note: It doesn't work with Shortcuts though

Usage: Drag & drop folder with links on the rexx script and it'll create the URLs, I haven't added any progressbar, but you may do that if you want.

//Jan-Erik

/* Create URL objects in a folder named 'My Internet Links' on the desktop */
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

obj_id = '<MYURLS>'
rc = SysFileTree( ARG(1)'\*.url', 'file', 'SOF' )
If \rc then
    If SysCreateObject( 'WPURLFolder', 'My Internet Links', '<WP_DESKTOP>', 'OBJECTID='obj_id';', 'U' ) then
    do
        call SysSetObjectData obj_id, 'OPEN=DEFAULT;'
        do i = 1 to file.0
            parse value FILESPEC( 'N', file.i ) with url_fname'.url'
            input = linein( file.i )
            do while pos( 'URL=', input ) = 0 & lines( file.i ) > 0 then
                input = linein( file.i )
            end
            parse value input with 'URL='url
            call CreateURL url, obj_id,, url_fname
        end
    end
call SysDropFuncs
Return rc

CreateURL: PROCEDURE
/* URL, save_in_folder¹, object_identification_name², <title> */
/* ¹) This can be specified as either an object ID ( for example, <WP_DESKTOP> ) */
/*    or a file system path ( for example, C:\Desktop ) */
/* ²) This can be specified as <my_ul_object_id_1234>, with or without "<" and ">" */
/*    Optional: Title */

url = ARG(1)
objid = ARG(3)
title = ARG(4)

IF LENGTH( objid ) = 0 THEN
   objid = SysTempFileName( '???????.???' )
objid = '<'||translate( objid,, '<>' )||'>'

/* Remove characters from object name, */
/* and add them back, just to ensure that */
/* we can handle object id names not in the form '<...>' */

object = SysTempFileName( 'add!????' )
if length( title ) = 0 then
   title = GetFileFromURL( url )

IF SysOs2Ver() > "2.30" THEN
  rc = SysCreateObject( 'WPUrl', object, ARG(2), 'OBJECTID='||objid||';TITLE='||title||';URL='||url, 'U')
ELSE
  rc = SysCreateObject('WebExplorer_Url', title, url, 'OBJECTID='||objid||';LOCATOR='||url||';', 'U')
RETURN rc

DecodeURL: PROCEDURE
PARSE ARG url
DO WHILE POS( '%', url ) > 0
  i = POS( '%', url )
  url = SUBSTR( url, 1, i-1 )||X2C(SUBSTR( url, i+1, 2 ))||SUBSTR( url, i+3 )
END
RETURN url

GetFileFromURL: PROCEDURE
/* URL syntax consists of six components: */
/* <scheme>://<net_loc_and_path>/<fname>;<params>?<query>#<fragment> */

PARSE VALUE FILESPEC( 'N', ARG(1) ) WITH url'#'.
PARSE VALUE retval WITH url'?'.
PARSE VALUE retval WITH url';'.
RETURN DecodeURL( url )

Saijin_Naib

Awesome! I can't wait to try this out later :D

Thank you thank you.

Saijin_Naib

#4
Thanks Jep, it worked brilliantly except for one URL which contained a special character that OS/2 did not like, and it would cause the WPS to not be able to copy my URL objects from my Windows drive to OS/2. Other than that, it works great :)

D:\Documents and Settings\Brett Carlock\Favorites\motivator Create your own customized motivational poster  Inspire! Motivate! Mock!.url

Thanks!

Saijin_Naib

Hey Jep, I was wondering if you could modify this script to retain folder structure when you drag/drop the folder or Favorite object onto the script.

Thanks!

jep

Hello,

Of course...

Only tested briefly, but should still behave well.

//Jan-Erik

/* Create URL objects in a folder named 'My Internet Links' on the desktop */
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

call GetURLS ARG(1), '<MYURLS>'
call SysDropFuncs
Return rc

GetURLS: PROCEDURE
rc = SysFileTree( ARG(1)'\*.url', 'file', 'OF' )
If \rc then do
    If SysCreateObject( 'WPURLFolder', 'My Internet Links', '<WP_DESKTOP>', 'OBJECTID='ARG(2)';', 'U' ) then
    do
        if length( obj_id ) > 0 then
          call SysSetObjectData obj_id, 'OPEN=DEFAULT;'
        do i = 1 to file.0
            parse value FILESPEC( 'N', file.i ) with url_fname'.url'
            input = linein( file.i )
            do while pos( 'URL=', input ) = 0 & lines( file.i ) > 0 then
                input = linein( file.i )
            end
            parse value input with 'URL='url
            call CreateURL url, ARG(2),, url_fname
        end
    end
end
rc = SysFileTree( ARG(1)'\*', 'folder', 'DO' )
If \rc then
    do i = 1 to folder.0
      objid = '<'||translate( SysTempFileName( 'url????fld' ),, '<>' )||'>'
      If SysCreateObject( 'WPURLFolder', FILESPEC( 'N', folder.i ), ARG(2), 'OBJECTID='objid';', 'U' ) then
        call GetURLS folder.i, objid
    end
Return rc

CreateURL: PROCEDURE
/* URL, save_in_folder¹, object_identification_name², <title> */
/* ¹) This can be specified as either an object ID ( for example, <WP_DESKTOP> ) */
/*    or a file system path ( for example, C:\Desktop ) */
/* ²) This can be specified as <my_ul_object_id_1234>, with or without "<" and ">" */
/*    Optional: Title */

url = ARG(1)
objid = ARG(3)
title = ARG(4)

IF LENGTH( objid ) = 0 THEN
   objid = SysTempFileName( '???????.???' )
objid = '<'||translate( objid,, '<>' )||'>'

/* Remove characters from object name, */
/* and add them back, just to ensure that */
/* we can handle object id names not in the form '<...>' */

object = SysTempFileName( 'add!????' )
if length( title ) = 0 then
   title = GetFileFromURL( url )

IF SysOs2Ver() > "2.30" THEN
  rc = SysCreateObject( 'WPUrl', object, ARG(2), 'OBJECTID='||objid||';TITLE='||title||';URL='||url, 'U')
ELSE
  rc = SysCreateObject('WebExplorer_Url', title, url, 'OBJECTID='||objid||';LOCATOR='||url||';', 'U')
RETURN rc

DecodeURL: PROCEDURE
PARSE ARG url
DO WHILE POS( '%', url ) > 0
  i = POS( '%', url )
  url = SUBSTR( url, 1, i-1 )||X2C(SUBSTR( url, i+1, 2 ))||SUBSTR( url, i+3 )
END
RETURN url

GetFileFromURL: PROCEDURE
/* URL syntax consists of six components: */
/* <scheme>://<net_loc_and_path>/<fname>;<params>?<query>#<fragment> */

PARSE VALUE FILESPEC( 'N', ARG(1) ) WITH url'#'.
PARSE VALUE retval WITH url'?'.
PARSE VALUE retval WITH url';'.
RETURN DecodeURL( url )