import lotus.domino.*;
import java.util.*;
import java.io.PrintWriter;
import com.gdcn.admin.*;
import com.gdcn.rmi.*;
import java.rmi.Naming;
import com.gdcn.domino.util.Log;
import java.io.*;
import com.gdcn.domino.*;
import com.gdcn.*;
import java.lang.*;
import org.jdom.Element;
public class JavaAgent extends AgentBase {
HashMap paramsMap;
private PrintWriter pw;
private PubliceFunction pFunc = new PubliceFunction();
private static DominoInt dominoInt = null;
private Session session = null;
private String tmpPath_forWord = null; //临时目录
private AgentContext agentContext;
private Database gz_dict_config = null;
private Vector youxiang= new Vector(); //律师邮箱
private Document tmpDoc=null;
public void NotesMain() {
try {
session = getSession();
agentContext = session.getAgentContext();
pw = getAgentOutput();
dominoInt = pFunc.getRmi(session);
Document doc = agentContext.getDocumentContext();
Database db = agentContext.getCurrentDatabase();
//取业务配置库
String lstrPath = db.getFilePath().toString()
.substring(
0,
(db.getFilePath().length() - db
.getFileName().length()));
gz_dict_config= session.getDatabase(db.getServer(), lstrPath
+ "gz_dict_config.nsf");
View law=null;
Document ywDoc = null;
if(doc.getItemValueString("lxr")!=null && !doc.getItemValueString("lxr").equals("")){
law=gz_dict_config.getView("vw_ShowLSConfigformail");
ywDoc= law.getDocumentByKey(doc.getItemValueString("lxr"));
youxiang=ywDoc.getItemValue("youxiang");
}
for(int i=0;i String platform. = session.getPlatform();
String tempRtfDir=getDbPathWithSepChar(db); //临时文档路径
String tmpAttName = "test1.doc";
tmpPath_forWord = session.getEnvironmentString("Directory", true);
if (platform.equals("UNIX") || platform.equals("LINUX")) {
tmpPath_forWord += "/domino/html/download/";
} else {
tmpPath_forWord += "\\domino\\html\\download\\";
}
String tempRtfFile = tmpPath_forWord+tmpAttName;
tmpDoc = db.createDocument();
Document RcfvTable =db.createDocument();
RcfvTable.replaceItemValue("form","RcfvTable");
RcfvTable.replaceItemValue("user",agentContext.getEffectiveUserName());
RcfvTable.replaceItemValue("zcdh",doc.getFirstItem("bhText").getText());
RcfvTable.replaceItemValue("fadanren",doc.getItemValueString("InitalAuthor_SYS_1"));
RcfvTable.replaceItemValue("jbtime_1", doc.getFirstItem("jbtime").getText());
RcfvTable.replaceItemValue("riqi",doc.getItemValueString("InitalCreated").substring(0,10));
RcfvTable.replaceItemValue("projectname_1", doc.getFirstItem("projectname").getText());
RcfvTable.replaceItemValue("name_1", doc.getFirstItem("name").getText());
RcfvTable.replaceItemValue("lxr_1", doc.getFirstItem("lxr").getText());
// RcfvTable.replaceItemValue("zcdnr_1", doc.getFirstItem("zcdnr").getText());
Vector xinxi=doc.getItemValue("zcdnr");
String neir="";
for(int k=0;k neir+=xinxi.get(k)+"
";
}
RcfvTable.replaceItemValue("zcdnr_1", neir);
RcfvTable.replaceItemValue("yqfksj_1", doc.getFirstItem("yqfksj").getText()+" "+doc.getItemValueString("qjtime1"));
RcfvTable.replaceItemValue("hdnr_1", "");
RcfvTable.replaceItemValue("cljg", "");
RichTextItem tmpItem;
if(tmpDoc.hasItem("rtf_DocAtt")) tmpDoc.removeItem("rtf_DocAtt");
tmpItem=tmpDoc.createRichTextItem("rtf_DocAtt");
RcfvTable.renderToRTItem(tmpItem);
//文档正文内容
String tmp = tmpItem.getText();
FileOutputStream fOut=new FileOutputStream(tempRtfFile);
fOut.write(tmp.getBytes());
if(tmpDoc.hasItem("rtf_DocAtt")) tmpDoc.removeItem("rtf_DocAtt");
tmpItem=tmpDoc.createRichTextItem("rtf_DocAtt");
tmpItem.××Object(××dedObject.××_ATTACHMENT,"",tempRtfFile,"test1.doc");
File tmpFile = new File(tempRtfFile);
tmpFile.delete();
RcfvTable.remove(true);
String direct = session.getEnvironmentString("Directory", true);
String tmpPath = "";
if (platform.toLowerCase().indexOf("windows") > -1) {
tmpPath = direct + "\\domino\\html\\temp\\";
} else {
tmpPath = direct + "/domino/html/temp/";
}
File fileTemp = new File(tmpPath);
if(!fileTemp.isDirectory()){
fileTemp.mkdir();
}
// for(int i=0;i tmpDoc.replaceItemValue("form", "Memo");
//设置当前登陆用户为发件人
tmpDoc.replaceItemValue("Principal",doc.getItemValueString("currentUserNameCommon"));
//邮件标题
tmpDoc.replaceItemValue("Subject", "test1--"+doc.getItemValueString("bhText"));
//邮件内容
RichTextItem wbody = tmpDoc.createRichTextItem("wBody");
// wbody.appendText("");
MIMEEntity body = tmpDoc.createMIMEEntity();
Stream stream = session.createStream();
stream.writeText(wbody.getText());
body.setContentFromText(stream, "text/html;charset=UTF-8",MIMEEntity.ENC_NONE);
wbody.remove();
//========== 把附件加到邮件上 ======
//1、取附件名
String attformular = "@AttachmentNames";
Vector ret = session.evaluate(attformular,doc);
if(!ret.get(0).toString().equals("")){ //如果存在附件
//2、拆除附件
for (int j = 0; j < ret.size(); j++) {
String attName_down = ret.get(j).toString();
try {
××dedObject obj_down = doc.getAttachment(attName_down);
if (obj_down != null) {
obj_down.extractFile(tmpPath + attName_down);
obj_down.recycle();
obj_down = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
//3、上传附件
RichTextItem attFile =tmpDoc.createRichTextItem("Body");
for (int k = 0; k < ret.size(); k++) {
String attName_up = ret.get(k).toString();
File upAttFile = new File(tmpPath + attName_up);
if (upAttFile.exists()) {
attFile.××Object(××dedObject.××_ATTACHMENT, null,
tmpPath + attName_up, attName_up);
try {
upAttFile.delete(); // 删除临时文档
} catch (Exception delErr) {
delErr.printStackTrace();
}
} else {
throw new RuntimeException("NotesMain()出错:服务器文件["+tmpPath + attName_up+"]不存在");
}
}
attFile.recycle();
attFile = null;
}
tmpDoc.send(false,youxiang.get(i).toString());
}
// tmpDoc.send(false,youxiang);
doc.save(true,true);
pw.println("");
ywDoc.recycle();
law.recycle();
} catch(Exception e) {
e.printStackTrace();
}finally{
if(dominoInt != null && (dominoInt instanceof com.gdcn.domino.pool.DominoIntProxy))
((com.gdcn.domino.pool.DominoIntProxy)dominoInt).release();
try {
session.recycle();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 功能:取当前数据库目录(包括分隔符号),与平台不相关
*/
public String getDbPathWithSepChar(Database db) throws Exception {
String path = "";
String dbPath = db.getFilePath();
String filename = db.getFileName();
path = dbPath.substring(0, dbPath.length() - filename.length());
return path;
}
}
有时生成的doc文档格式不对,需要在表单设置里,把所有内容内嵌为HTML,然后用和把它们包起来
同理可以生成 html 文件
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10247040/viewspace-663313/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10247040/viewspace-663313/