IBM Support

Is there an alternative to using the LotusScript GetDocumentByURL method

Technote (FAQ)


Question

In Lotus Domino Designer, you use the LotusScript method GetDocumentByURL to create a document in the Web Navigator database on either the local client or the server, and you populate this document with the results of a URL. However, in some cases, issues can occur using this method because of various configuration complications, such as proxy servers, firewalls, and so on.

Additionally, if an agent is used to retrieve this information on a short schedule (for rapidly updated information), the documents created in the Web Navigator database can quickly expand. Finally, the GetDocumentByURL method does not return the raw HTML code of the URL, but returns a representation of that URL in a rich text field.

Is there a better alternative to using the GetDocumentByURL LotusScript method?


Answer

An alternative to using the GetDocumentbyURL functionality is to use a Java agent to access the documents that are needed. Using the URL class of Java, it's possible to create a direct connection to access the URL. The URL class has additional options for proxies and authentication. The URL connection returns the full HTML code (or other content) of the page as a string that can be easily parsed. This method is preferable to use for XML parsing.

Example:
An example of this functionality is an agent that checks the current stock price of the company to display on an intranet site. The agent written below is an example of that functionality. In order to run this agent on the server, the runtime security level must be set to "2. Allow restricted operations."

NOTE: The following is a sample script, provided to illustrate one way to approach this issue. In order for this example to perform as intended, the script must be laid out exactly as indicated below. Notes Support cannot customize this script for a customer's own configuration.

The agent requires a form to be available, called IBMForm. That form has two fields on it. One is WebPageUS which is an editable text field. The second is QuoteUS which is a computed text field with the following formula:

temp:=@Middle( WebPageUS ; "Last Trade" ; "Change" );
@Trim(@Left(@Right(temp;"<b>");"</b>"))

The code for the Java Agent is:

    import lotus.domino.*;
    import java.net.*;
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import java.math.*;

    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();

          Database db = agentContext.getCurrentDatabase();
          URL ibmURL = new URL(" http://finance.yahoo.com/q?s=IBM&d=t");
          BufferedReader bin = new BufferedReader ( new InputStreamReader(ibmURL.openStream( ) ));
          String line;
          StringBuffer sb = new StringBuffer();

          while ( (line = bin.readLine( )) != null )
            {
              sb.append(line);
            }
              String ibmString = sb.toString();

              Document newNotesDoc = db.createDocument();
              newNotesDoc.replaceItemValue ("Form", "IBMForm");
              newNotesDoc.replaceItemValue ("WebPageUS", ibmString);
              newNotesDoc.computeWithForm( true , false);
              newNotesDoc.save( true, true );

              String ibms = newNotesDoc.getItemValueString("QuoteUS");
              System.out.println( "IBM Raw String is " + ibms);
              newNotesDoc.recycle();

              NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US);
              BigDecimal d = new BigDecimal(ibms);
              double ibmd = d.doubleValue();
              String ibm = n.format(ibmd);
              System.out.println( "IBM Currency is " + ibm);

              SimpleDateFormat formatter = new SimpleDateFormat ("EEEE, MMMM dd, yyyy hh:mm:ss a");
              Date currentTime_1 = new Date();
              String dateString = formatter.format(currentTime_1);
              System.out.println( "Formatted date is " + dateString);
              String displayText = "IBM stock price as of " + dateString + " NYSE US " + ibm;
              System.out.println( "Display text is " + displayText);
              db.recycle();
            } catch(Exception e) {
              e.printStackTrace();
            }
          }
        }

This example can be extended to place the display text in a document that will be on the intranet or in other contexts.

Cross reference information
Segment Product Component Platform Version Edition
Messaging Applications Lotus End of Support Products Lotus Notes Platform Independent 6.5, 6.0, 5.0

Product Alias/Synonym

Lotus Domino Designer
Lotus Domino
Lotus Notes

Document information

More support for: Lotus End of Support Products
Lotus Domino Designer

Software version: 5.0, 6.0, 6.5

Operating system(s): AIX, IBM i, Linux, Solaris, Windows, z/OS

Reference #: 1105866

Modified date: 23 November 2004


Translate this page: