[编辑] 示例来自打破标准杆 http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256DC80053681B
要放置在名为 GetHTML 的 Java 库中的 java 代码:
import java.io.*;
import java.net.*;
public class GetHTML {
public String getHTML(String urlToRead) {
URL url; // The URL to read
HttpURLConnection conn; // The actual connection to the web page
BufferedReader rd; // Used to read results from the web page
String line; // An individual line of the web page HTML
String result = ""; // A long string containing all the HTML
try {
url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
result += line;
}
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
并在 Lotusscript 中使用它:
Uselsx "*javacon"
Use "GetHTML" ' Java library
Const myURL = "http://www.breakingpar.com"
Dim js As JAVASESSION
Dim getHTMLClass As JAVACLASS
Dim getHTMLObject As JavaObject
Dim html As String
Set js = New JAVASESSION
Set getHTMLClass = js.GetClass("GetHTML")
Set getHTMLObject = getHTMLClass.CreateObject
html = getHTMLObject.getHTML(myURL)
我使用它通过此服务填充 Lotus 中的国家/地区下拉列表:http://ws.geonames.org/countryInfo http://ws.geonames.org/countryInfo?
您可以使用 Java 代理来使用其余服务:
下面的代码是从技术说明中复制的。如果请求是更大脚本的一部分,则可以将 HTTP 请求包装在LS2J http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=/com.ibm.designer.domino.main.doc/LSAZ_USING_LS2J.html
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();
}
}
}