📄 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 + -