Java Read Notes database __ Database

Source: Internet
Author: User
Tags mixed

Specific operations


1, start the DIIOP service, there is to start the HTTP service, if your machine's Web 80 port is occupied, you can develop a


2. Configure Server Documentation:


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 desire D.


3, find Notes.jar and Ncso.jar, and put them in the Libaraires directory of the Eclipse project.


4, Domino server must be started.

The program code is as follows:
Import lotus.domino.*;

try {

System.out.println ("Start the Notes data source to connect ...");
Session s = notesfactory.createsession (Noteshost,username,userpassword);
System.out.println ("Successfully connected to the Notes data source, now looking for notes login database Oak.nsf");
Defining Global Variables
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");
Todo
{
Specific analysis of each object
Switch (Entry.getusertype ()) {
Case Aclentry.type_mixed_group:
Mixed group
System.out.println ("Mixed Group" +entry.getname ());
Case Aclentry.type_person:
Personal
Namesuser=entry.getname (). substring (3,entry.getname (). indexof ("/"));
Addnotesuser (Namesuser);
System.out.println ("Individual:" + Namesuser);
Break
Case Aclentry.type_person_group:
Personal groups
System.out.println ("Individual group:" +entry.getname ());
Names.nsf view groups document members domain has every user
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 ()) {
Will cn=administrator/o=autosoft only take its name to the administrator
Namesuser=values.nextelement (). ToString ();
Namesuser=namesuser.substring (3,namesuser.indexof ("/"));
Addnotesuser (Namesuser);
}
}
Break
Case Aclentry.type_server:
Server
System.out.println ("Server" +entry.getname ());
Case Aclentry.type_server_group:
Server Groups
System.out.println ("server Group" +entry.getname ());
Case Aclentry.type_unspecified:
Not specified
if (Entry.getname (). indexof ("/") >1)
{
Namesuser=entry.getname (). substring (3,entry.getname (). indexof ("/"));
Addnotesuser (Namesuser);
System.out.println ("Find a user with no specified type" +entry.getname (). substring (3,entry.getname (). indexof ("/"));
Break
}
Else
{
System.out.println ("Not Specified" +entry.getname ());
Break
}
}
while ((Entry = Acl.getnextentry (entry))!= null);
System.out.println ("User import complete");
}

catch (Exception ex)
{
Ex.printstacktrace ();
System.out.println ("Connection failed with notes data source");
}

========= one of the following programs ===========
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;
Constructors
Public Connecttodomino (String server,string user,string pass) {
strserver = Server;
strUserName = User;
strpassword = pass;
SetConnection ();
}
Establish a connection
public Boolean setconnection () {
if (Strserver==null | |   Strusername==null | | Strpassword==null) return false;
try {
SYSTEM.OUT.PRINTLN ("User login:" + strserver + "/t" + strusername);
String Ior=getior ();
if (ior!= "")
System.out.println ("Successfully get IOR, begin to create session ...");
Else
System.out.println ("Get IOR failed.") ");
Session = Notesfactory.createsession (Strserver,strusername,strpassword);
Session = Notesfactory.createsession (Strserver, "", "");
Session = Notesfactory.createsessionwithior (IOR); Anonymous
Session = Notesfactory.createsessionwithior (Ior,strusername,strpassword); User identity

SYSTEM.OUT.PRINTLN ("Login information:/n Server Name:" + session.getservername () + "N/a login username:" +

Session.getusername () + "/n");
return true;
}
catch (Exception e)
{
E.printstacktrace ();
return false;
}
}

Get 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;
}

Retrieving documents
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 ();
}
}
Create a document
public boolean Createnewdoc (String dbname,string formname,string[] fieldlist,string[) valuelist,string age Ntname) {
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;
}

}
Shut down
public void Close () {
try{
Session.recycle ();
session = NULL;
}
catch (Exception e)
{
E.printstacktrace ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.