具體操作
1、啟動DIIOP服務,還有就是啟動http服務,如果你的機器的Web 80連接埠被佔用,可以制定一個
2、設定管理員文檔:
Under Security:
Under Server Access, fill in "Access server," "Not access server," "Create new databases," and "Create replica databases" as desired.
Under IIOP Restrictions, fill in "Run restricted Java/Javascript/COM" and "Run unrestricted Java/Javascript/COM" as desired.
3、找到Notes.jar和NCSO.JAR,放到Eclipse 項目的Libaraires目錄下
4、Domino Server一定要啟動.
程式碼如下:
import lotus.domino.*;
try {
system.out.println("開始notes資料來源進行串連....");
session s = notesfactory.createsession(noteshost,username,userpassword);
system.out.println("與notes資料來源成功串連,現正在尋找notes登入資料庫 oak.nsf");
//定義全域性變數
database db = null;
database namesdb=null;
view view =null;
document doc = null;
string namesuser="";
db = s.getdatabase(s.getservername(), sysinf.notes_dir +"/oak.nsf");
acl acl = db.getacl();
aclentry entry = acl.getfirstentry();
namesdb=s.getdatabase(s.getservername() ,"names.nsf") ;
view = namesdb.getview("groups");
do
{
//具體分析每一個對象
switch (entry.getusertype()) {
case aclentry.type_mixed_group :
//混合組
system.out.println("混合組 "+entry.getname()) ;break;
case aclentry.type_person :
//個人
namesuser=entry.getname().substring(3,entry.getname().indexof("/") );
addnotesuser(namesuser);
system.out.println("個人 : "+ namesuser) ;
break;
case aclentry.type_person_group :
//個人群組
system.out.println("個人群組: "+entry.getname() ) ;
//names.nsf 中視圖groups 文檔members域有每一個使用者
doc = view.getfirstdocument();
while (doc != null && !doc.getfirstitem("listname").gettext().equals(entry.getname() ) )
{
doc = view.getnextdocument(doc);
}
if (doc!=null){
enumeration values = doc.getfirstitem("members").getvalues().elements();
while (values.hasmoreelements()) {
//將cn=administrator/o=autosoft只取它的名字administrator
namesuser=values.nextelement().tostring() ;
namesuser=namesuser.substring(3,namesuser.indexof("/") ) ;
addnotesuser(namesuser);
}
}
break;
case aclentry.type_server :
//伺服器
system.out.println("伺服器 "+entry.getname()) ;break;
case aclentry.type_server_group :
//伺服器組
system.out.println("伺服器組 "+entry.getname()) ;break;
case aclentry.type_unspecified :
//沒有指定
if(entry.getname().indexof("/")>1 )
{
namesuser=entry.getname().substring(3,entry.getname().indexof("/") );
addnotesuser(namesuser);
system.out.println("找到一個沒有指定類型的使用者 "+entry.getname().substring(3,entry.getname().indexof("/"))) ;
break;
}
else
{
system.out.println("沒有指定 "+entry.getname()) ;
break;
}
}
} while ((entry = acl.getnextentry(entry)) != null);
system.out.println("使用者匯入完成") ;
}
catch (exception ex)
{
ex.printstacktrace() ;
system.out.println("與notes資料來源串連失敗" ) ;
}
=========下面的一個程式===========
import lotus.domino.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class ConnectToDomino
{
Session session = null;
String strServer = null;
String strUserName = null;
String strPassWord = null;
//建構函式
public ConnectToDomino(String Server,String User,String Pass) {
strServer = Server;
strUserName = User;
strPassWord = Pass;
setConnection();
}
//建立串連
public boolean setConnection() {
if(strServer==null || strUserName==null || strPassWord==null) return false;
try {
System.out.println("使用者登入:" + strServer + "/t" + strUserName);
String IOR=GetIOR();
if(IOR!="")
System.out.println("成功取得IOR,開始建立session.....");
else
System.out.println("擷取IOR失敗。");
//session = NotesFactory.createSession(strServer,strUserName,strPassWord);
//session = NotesFactory.createSession(strServer,"","");
//session = NotesFactory.createSessionWithIOR(IOR); //匿名
session = NotesFactory.createSessionWithIOR(IOR,strUserName,strPassWord); //使用者身份
System.out.println("成功登陸,登入資訊:/n伺服器名稱:" + session.getServerName() + "/n登入使用者名稱:" +
session.getUserName() + "/n");
return true;
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}
//擷取IOR
public String GetIOR() {
InputStream bin;
String Result="";
int character;
try{
URL url = new URL("http://"+strServer+"/diiop_ior.txt");
bin = url.openStream();
while((character=bin.read())>0) {
Result += (char)character;
}
}
catch(Exception e){
e.printStackTrace();
}
return Result;
}
//檢索文檔
public void Search(String SearchDB,String SearchFormular) {
try {
Database db = session.getDatabase(session.getServerName(),SearchDB);
System.out.println ("Searching:" + SearchFormular+"...");
DocumentCollection dc = db.search(SearchFormular);
Document docResult = dc.getFirstDocument();
if(docResult==null) return;
int i;
int j=0;
while (docResult != null) {
System.out.println(docResult.getItemValueString("FullName"));
docResult = dc.getNextDocument();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
//建立文檔
public boolean CreateNewDoc(String DBName,String formName,String[] FieldList,String[] ValueList,String AgentName) {
try{
Database db = session.getDatabase(session.getServerName(),DBName);
Document doc = db.createDocument();
Item item = doc.appendItemValue("form",formName);
doc.computeWithForm(true,false);
int i;
for(i=0;i<FieldList.length;i++){
item = doc.replaceItemValue(FieldList[i],ValueList[i]);
}
doc.save();
if(AgentName!=null || AgentName!="") {
Agent agent = db.getAgent(AgentName);
if(agent!=null) {
agent.run(doc.getNoteID());
}
}
return true;
}catch(Exception e)
{
e.printStackTrace();
return false;
}
}
//關閉
public void close() {
try{
session.recycle();
session = null;
}
catch(Exception e)
{
e.printStackTrace();
}
}
}