public class HOLDValues
{
public static final String strCompanyName = "<Company Name>";
public static final String strFormName = "ActionLetter";
public static final float[] widths1C = {1.75f};
public static final float[] widths2C = {1.83f, 4.0f};
public static final float cellW1 = 1.0f;
public static final float cellW2 = 4.0f;
public static final float fTextFontSize = 14;
public static final float fSpaceFontSize = 10;
}
import lotus.domino.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.math.*;
import java.text.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import com.lowagie.text.*;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.DefaultFontMapper;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Chunk;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Phrase;
import com.lowagie.text.Image;
import com.lowagie.text.html.HtmlWriter;
import com.lowagie.text.Element;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.Font;
import com.lowagie.text.Table;
import com.lowagie.text.rtf.table.*;
import com.lowagie.text.rtf.RtfWriter2;
import com.lowagie.text.rtf.field.RtfTableOfContents;
import com.lowagie.text.rtf.field.RtfTOCEntry;
import com.lowagie.text.rtf.table.RtfCell;
import com.lowagie.text.rtf.table.RtfBorder;
import com.lowagie.text.rtf.table.RtfBorderGroup;
import com.lowagie.text.rtf.headerfooter.RtfHeaderFooter;
import com.lowagie.text.rtf.headerfooter.RtfHeaderFooterGroup;
import com.lowagie.text.rtf.field.RtfPageNumber;
import com.lowagie.text.rtf.field.RtfTotalPageNumber;
public class createRTFAgent extends AgentBase {
Frame frame;
Label l;
Cell cell;
Paragraph p1;
String tiff_file;
String imTiff_file;
String pdf_file;
String strInPutXMLData;
String strOutPutImage;
String PdfWriteDirBase;
String PdfWriteDir;
String path;
Locale locale = Locale.US;
String strGetLNServer = "";
String strGetMemorandum = null;
String strGetFrom = null;
String strGetSubject = null;
String strGetOpening = null;
String strGetClosing = null;
String strGetEmpName = null;
String strGetEmpTitle = null;
String strGetEmpOrg = null;
String strGetEmpBus = null;
String strGetEmpPhone = null;
String strGetMgrName = null;
String strGetMgrTitle = null;
String strGetMgrOrg = null;
String strGetMgrBus = null;
String strGetMgrPhone = null;
String strGetLoggedInUser = null;
String strGetCreatedFrom = null;
String strFilterSubject = null;
public void NotesMain ()
{
String richTextField = null;
lotus.domino.Document lnDoc = null;
int imageId = 1;
String docUNID = null;
try
{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db = agentContext.getCurrentDatabase();
lnDoc = agentContext.getDocumentContext();
NoteCollection nc = db.createNoteCollection(false);
nc.buildCollection();
if(lnDoc != null)
{
nc.add(lnDoc);
}
strGetLoggedInUser = session.getCommonUserName();
// Create a frame to show progress
frame = new Frame();
l = new Label("Starting Data Collection....");
frame.add(l, "Center");
frame.setSize(400, 100);
frame.show();
l.setText("Starting Data Collection....");
addButton();
//Get Data from Lotus Notes doc and/or Other source
docUNID = lnDoc.getItemValueString("UNID");
String strForm = lnDoc.getItemValueString("Form");
strGetMemorandum = lnDoc.getItemValueString("Memorandum");
strGetFrom = lnDoc.getItemValueString("From");
strGetSubject = lnDoc.getItemValueString("Subject");
strGetOpening = lnDoc.getItemValueString("Opening");
strGetClosing = lnDoc.getItemValueString("Closing");
strGetEmpName = lnDoc.getItemValueString("empName");
strGetEmpTitle = lnDoc.getItemValueString("empTitle");
strGetEmpOrg = lnDoc.getItemValueString("empOrg");
strGetEmpBus = lnDoc.getItemValueString("empBus");
strGetEmpPhone = lnDoc.getItemValueString("empPhone");
strGetMgrName = lnDoc.getItemValueString("mgrName");
strGetMgrTitle = lnDoc.getItemValueString("mgrTitle");
strGetMgrOrg = lnDoc.getItemValueString("mgrOrg");
strGetMgrBus = lnDoc.getItemValueString("mgrBus");
strGetMgrPhone = lnDoc.getItemValueString("mgrPhone");
String strGetBody0 = String.valueOf(lnDoc.getItemValue("Body"));
String strGetBody = HOLDValues.replace(HOLDValues.replace(strGetBody0, "[", ""), "]", "");
strGetCreatedFrom = lnDoc.getItemValueString("CreatedFrom");
l.setText("Starting MS Word Creation....");
addButton();
//Create directory structure
PdfWriteDirBase = "C:\\Temp\\";
PdfWriteDir = "\\PDF\\";
String strPDFDirectory = PdfWriteDirBase + PdfWriteDir;
boolean exists = (new File(strPDFDirectory)).exists();
if (exists)
{
System.out.println("Directory: Does esist");
}
else
{
System.out.println("Directory: Does not esist");
boolean success = (new File(strPDFDirectory)).mkdirs();
if (!success)
{
System.out.println("Directory: Not able to create directory " + strPDFDirectory);
}
}
//MS Word Creation
strFilterSubject = HOLDValues.ReplaceSubString(HOLDValues.ReplaceSubString(strGetSubject, " ", ""), ":", "");
session.setEnvironmentVar("POPDFDirectory", "", true);
path = PdfWriteDirBase + PdfWriteDir + "\\" + strGetCreatedFrom + "_" + strFilterSubject + HOLDValues.getCurrentDateString2() + ".rtf";
session.setEnvironmentVar("POPDFDirectory", path, true);
File PdfAtt = new File(path);
com.lowagie.text.Document rtfDoc = new com.lowagie.text.Document(PageSize.A4, 72, 72, 72, 72);
RtfWriter2.getInstance(rtfDoc, new FileOutputStream(path));
//Set MS Word Properties
rtfDoc.addTitle("GSA: Disciplinary Letter");
rtfDoc.addSubject("Created from the " + HOLDValues.strCompanyName + " Agent");
rtfDoc.addKeywords(HOLDValues.strCompanyName);
rtfDoc.addCreator(HOLDValues.strCompanyName + " Agent");
rtfDoc.addAuthor(HOLDValues.strCompanyName + ": " + session.getCommonUserName());
//Add Footer
Paragraph p = new Paragraph();
p = new Paragraph("", FontFactory.getFont(FontFactory.HELVETICA, HOLDValues.fSpaceFontSize));
p.add(new Chunk("Page "));
p.add(new RtfPageNumber());
p.add(new Chunk(" of "));
p.add(new RtfTotalPageNumber());
p.setAlignment(Element.ALIGN_RIGHT);
Table footerTable = new Table(1);
footerTable.setWidth(100);
Cell pageNumberCell = new Cell();
pageNumberCell.setBorder(Rectangle.NO_BORDER);
pageNumberCell.add(p);
footerTable.addCell(pageNumberCell);
HeaderFooter footer = new RtfHeaderFooter(footerTable);
rtfDoc.setFooter(footer);
//Start MS Word Document
rtfDoc.open();
//Opening Data
String txtDateData1 = HOLDValues.getCurrentDateString();
Chunk cDateData1 = new Chunk(txtDateData1, new Font(Font.TIMES_ROMAN, HOLDValues.fTextFontSize));
rtfDoc.add(cDateData1);
//Adds 3 Blank lines
p1 = new Paragraph(new Chunk(" ", FontFactory.getFont(FontFactory.HELVETICA, HOLDValues.fSpaceFontSize)));
rtfDoc.add(p1);
rtfDoc.add(p1);
rtfDoc.add(p1);
rtfDoc.add(p1);
//Employee Data
String txtEmployeeData1 = "MEMORANDUM FOR " + strGetEmpName.toUpperCase();
String txtEmployeeData2 = " " + strGetEmpTitle.toUpperCase();
String txtEmployeeData3 = " " + strGetEmpOrg.toUpperCase();
Chunk cEmployeeData1 = new Chunk(txtEmployeeData1, new Font(Font.TIMES_ROMAN, HOLDValues.fTextFontSize));
Chunk cEmployeeData2 = new Chunk(txtEmployeeData2, new Font(Font.TIMES_ROMAN, HOLDValues.fTextFontSize));
Chunk cEmployeeData3 = new Chunk(txtEmployeeData3, new Font(Font.TIMES_ROMAN, HOLDValues.fTextFontSize));
rtfDoc.add(cEmployeeData1);
rtfDoc.add(p1);
rtfDoc.add(cEmployeeData2);
rtfDoc.add(p1);
rtfDoc.add(cEmployeeData3);
//Adds 2 Blank lines
rtfDoc.add(p1);
rtfDoc.add(p1);
//Manager Data
String txtMGRData1 = "FROM: " + strGetMgrName.toUpperCase();
String txtMGRData2 = " " + strGetMgrTitle.toUpperCase();
String txtMGRData3 = " " + strGetMgrOrg.toUpperCase();
Chunk cMGRData1 = new Chunk(txtMGRData1, new Font(Font.TIMES_ROMAN, HOLDValues.fTextFontSize));
Chunk cMGRData2 = new Chunk(txtMGRData2, new Font(Font.TIMES_ROMAN, HOLDValues.fTextFontSize));
Chunk cMGRData3 = new Chunk(txtMGRData3, new Font(Font.TIMES_ROMAN, HOLDValues.fTextFontSize));
rtfDoc.add(cMGRData1);
rtfDoc.add(p1);
rtfDoc.add(cMGRData2);
rtfDoc.add(p1);
rtfDoc.add(cMGRData3);
//Adds 2 Blank lines
rtfDoc.add(p1);
rtfDoc.add(p1);
//Subject Data
String txtSubjectData1 = "SUBJECT: " + strGetSubject;
Chunk cSubjectData1 = new Chunk(txtSubjectData1, new Font(Font.TIMES_ROMAN, HOLDValues.fTextFontSize));
rtfDoc.add(cSubjectData1);
//Adds 2 Blank lines
rtfDoc.add(p1);
rtfDoc.add(p1);
//Opening Data
Chunk cOpenData;
String txtOpenData = strGetOpening;
cOpenData = new Chunk(txtOpenData, new Font(Font.TIMES_ROMAN, HOLDValues.fTextFontSize));
rtfDoc.add(cOpenData);
//Adds Blank line
rtfDoc.add(p1);
rtfDoc.add(p1);
//Body Data
Chunk cBodyData;
String txtBodyData = strGetBody;
cBodyData = new Chunk(txtBodyData, new Font(Font.TIMES_ROMAN, HOLDValues.fTextFontSize));
rtfDoc.add(cBodyData);
//Adds Blank line
rtfDoc.add(p1);
rtfDoc.add(p1);
//Closing Data
Chunk cClosingData;
String txtClosingData = strGetClosing;
cClosingData = new Chunk(txtClosingData, new Font(Font.TIMES_ROMAN, HOLDValues.fTextFontSize));
rtfDoc.add(cClosingData);
//Adds Blank line
rtfDoc.add(p1);
//Close Doc creation
rtfDoc.close();
l.setText("Completed MS Word Creation....");
addButton();
//Attaches File to Notes Document
String filepath = PdfAtt.getAbsolutePath();
lnDoc.replaceItemValue("PDFCreateFlag", "");
lnDoc.replaceItemValue("PDFLocation", path);
lnDoc.replaceItemValue("PDFCreatedOn", HOLDValues.getCurrentDate());
lnDoc.replaceItemValue("PDFCreatedBy", session.getCommonUserName());
lnDoc.save(true, false);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void addButton()
{
Button b = new Button("OK");
b.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
}
}
);
frame.add(b, "South");
frame.show();
}
}