?? newcopy.txt
字號:
import lotus.domino.*;
import java.io.*;
import java.util.Vector;
/**
* 實現Louts domino 數據庫文件批量 自動“新建拷貝” 、授權、文件簽名
*
*
*/
public class JavaAgent extends AgentBase {
//數據服務器名稱/組織名稱
private String serverName="xtserver/xtoa";
//請將要新建拷貝的數據文件拷貝到 Louts 客戶端的 x:\Lotus\notes 下,執行完成后,會自動在服務器 ..\data目錄創建xtdl 目錄
private String dbPath="xtdl";
//組織名稱
private String org="xtoa";
//運行產生的日志文件
private String logPath="c:\\debug.log";
public void NotesMain() {
try
{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
DbDirectory dir = session.getDbDirectory(null);
Database localdb =null;
Database newdb=null;
Database cdb = dir.getFirstDatabase(DbDirectory.TEMPLATE_CANDIDATE);
String localPath="";
while (cdb!=null)
{
localPath=cdb.getFilePath();
debug("all db: "+localPath);
if (localPath.startsWith(dbPath) && localPath.indexOf("\\")!=-1)
{
debug("sync db: "+localPath);
localdb = session.getDatabase(null, localPath);
newdb = localdb.createCopy(serverName, localPath);
DocumentCollection dc = localdb.getAllDocuments();
Document doc = dc.getFirstDocument();
while (doc != null)
{
try
{
doc.copyToDatabase(newdb);
}
catch(Exception e)
{
debug(e);
}
doc = dc.getNextDocument();
}
//acl
ACL acl = newdb.getACL();
Vector roles = acl.getRoles();
ACLEntry entty = acl.getFirstEntry();
ACLEntry tmp=null;
do
{
debug(entty.getName()+"\n");
if (!"-Default-".equalsIgnoreCase(entty.getName()))
{
tmp= acl.getNextEntry(entty);
if (entty.getName()!=null) acl.removeACLEntry(entty.getName());
entty=tmp;
}
else
{
entty= acl.getNextEntry(entty);
}
} while (entty!= null);
acl.createACLEntry("admin/"+org,ACL.LEVEL_MANAGER);
ACLEntry admin = acl.getEntry("admin/"+org);
admin.setUserType(ACLEntry.TYPE_PERSON);
String role="";
for (int i=0; i<roles.size(); i++)
{
role= (String)roles.elementAt(i);
admin.enableRole(role);
}
acl.createACLEntry("Anonymous",ACL.LEVEL_NOACCESS);
ACLEntry anonymous = acl.getEntry("Anonymous");
anonymous.setUserType(ACLEntry.TYPE_PERSON);
acl.createACLEntry(serverName,ACL.LEVEL_MANAGER);
ACLEntry server = acl.getEntry(serverName);
server.setUserType(ACLEntry.TYPE_SERVER);
acl.setInternetLevel(ACL.LEVEL_MANAGER);
acl.setAdministrationServer(serverName);
acl.save();
newdb.sign();
if (entty!=null) entty.recycle();
if (tmp!=null) tmp.recycle();
if (admin!=null) admin.recycle();
if (anonymous!=null) anonymous.recycle();
if (server!=null) server.recycle();
if (acl!=null) acl.recycle();
if (doc!=null) doc.recycle();
if (dc!=null) dc.recycle();
} //if
cdb = dir.getNextDatabase();
debug("cdb db: "+cdb);
} //while
} catch(Exception e) {
debug(e);
e.printStackTrace();
}
}
public void debug(String log)
{
try
{
PrintWriter out=new PrintWriter(new FileOutputStream("c:\\debug.log",true));
out.println(log);
out.flush();
out.close();
}
catch(Exception e)
{
}
}
public void debug(Exception log)
{
try
{
PrintWriter out=new PrintWriter(new FileOutputStream(logPath,true));
log.printStackTrace(out);
out.flush();
out.close();
}
catch(Exception e)
{
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -