#!/usr/bin/env rexx /* Gets the title text of URLs, made operating system independent by using Java to fetch the HTML data. */ use arg slotArg /* fetch the "slotArg", a java.util.Hashtable object which contains invocation information from OpenOffice.org, will always be the very last argument */ scriptContext=uno.getScriptContext(slotArg) /* get the xScriptContext object, if any */ if scriptContext<>.nil then /* o.k., we are invoked as a macro from OOo */ do xDesktop=scriptContext~getDesktop /* get the desktop (a XDesktop) object */ xContext=scriptContext~getComponentContext /* get the context (a XComponentContext) object */ end else /* this program was called from outside of OOo, e.g. from the commandline */ do xContext = UNO.connect() /* get a connection to OOo server */ xDesktop = UNO.createDesktop(xContext) /* create the XDesktop from xContext */ end xComponentLoader=xDesktop~XComponentLoader /* get componentLoader interface */ /* create a blank writer file */ url = "private:factory/swriter" writerComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0,.UNO~noProps) /* create the TextObject and the TextCursor */ xTextDocument = writerComponent~XTextDocument xText = XTextDocument~getText xTextCursor = xText~createTextCursor /* create and insert TextTable */ xDMsf = xTextDocument~XMultiServiceFactory xTextTable = xDMsf~createInstance("com.sun.star.text.TextTable")~XTextTable xTextTable~initialize(1,3) xText~insertTextContent(xTextCursor, xTextTable, .false) /* colorize header row, create header text */ xTextTable~getRows~getbyIndex(0)~xPropertySet~setPropertyValue("BackColor", box("int", "e6e6fa"x ~c2d)) xTextTable~getCellByName("A1")~XText~setString("URL") xTextTable~getCellByName("B1")~XText~setString("Title") xTextTable~getCellByName("C1")~XText~setString("Loading Speed") arr=.array~of("https://de.wikipedia.org/wiki/The_Whale", "https://learn.wu.ac.at/dotlrn/", "https://www.google.com/", "https://wi.wu-wien.ac.at/rgf/wu/lehre/autojava/material/foils/") loop i=1 to arr~items /* loop over all URLs in the ooRexx array */ call processURL xTextTable, i, arr[i] end writerComponent~XModifiable~setModified(.false) /* allow to close (abort) document without saving-dialog */ ::requires UNO.CLS -- load UNO support for OpenOffice.org ::routine processURL use arg xTextTable, rowNr, url xTextRows = xTextTable~getRows /* get the Row collection */ xTextRows~insertByIndex(rowNr, 1) /* insert one new row */ newRowNr = rowNr + 1 /* new row index number */ /* It is for us just to change the color id, not the variable name: light red */ lightBlue=box("int", "f67b7b"x ~c2d) xCell = xTextTable~getCellByName("A" || newRowNr) xCell~xPropertySet~setPropertyValue("BackColor", lightBlue) xCell~XText~setString(url) xTextTable~getCellByName("B" || newRowNr)~XPropertySet~setPropertyValue("BackColor", lightBlue) /* give user a hint that we are loading data from the web */ xCell = xTextTable~getCellByName("C" || newRowNr) xCell~xPropertySet~setPropertyValue("BackColor", box("int", "ff0000"x ~c2d)) xCellText = xCell~XText xCellText~setString("loading...") call time "reset" htmlData=getWebPageData(url) /* go and fetch the HTML text */ elapsed=time("elapsed") green = box("int", "7af3ea"x ~c2d) xCell = xTextTable~getCellByName("C" || newRowNr) xCell ~ Xtext~setString("done ("elapsed "secs).") xCell~xPropertySet~setPropertyValue("BackColor", green) parse caseless var htmlData "" title "" /* extract title */ xCell = xTextTable~getCellByName("B" || newRowNr) xCell ~XText~setString(title) xCell~xPropertySet~setPropertyValue("BackColor", lightBlue) /* take URL, fetch and return line oriented data, 2010-07-08, Rony G. Flatscher and now Group 4 :D*/ ::routine getWebPageData use arg url url = .bsf~new("java.net.URL", url) /* create a Java URL object */ conn = url~openConnection iRdr = .bsf~new("java.io.InputStreamReader", conn~getInputStream) bRdr = .bsf~new("java.io.BufferedReader", iRdr) data = "" line = bRdr~readLine do while line<>.nil /* read all lines */ if data="" then data = line else data = data || "0d0a"x || line line = bRdr~readLine end bRdr~close /* close BufferedReader object */ return data