I am writing a Notes Agent to do a replace text in the Body for specific incoming email messages.
The problem I’m experiencing is that is seems to be stripping off tabs and/or spaces off the beginning of each line in the Body. So when I keep my message after I make the changes the indents are all gone off the Body.
This is the start of my code and if I do a System.out.println at the end it shows the indents are gone and all rows of text start in the first column.
public class JavaAgent extends AgentBase
{
public void NotesMain()
{
try
{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
Database db = agentContext.getCurrentDatabase();
View view = db.getView("IDDE");
Document doc = view.getFirstDocument();
Document newdoc = db.createDocument();
Item subject = doc.replaceItemValue("Subject", "IDDE Invoice - Redone");
RichTextItem rti = newdoc.createRichTextItem("Body");
RichTextStyle font = session.createRichTextStyle();
font.setFont(RichTextStyle.FONT_COURIER);
rti.appendStyle(font);
String token;
Vector items = doc.getItems();
for (int j=0; j<items.size(); j++) {
Item item = (Item)items.elementAt(j);
System.out.println("\t" +
item.getName() + " = \"" +
item.getValueString() + "\"");
}
Anyone know a way around this problem? I’m thinking it’s because the getValueString method strips off leading spaces and/or tabs.
Subject: Try getFormattedText method of RichTextItem
Subject: RE: Try getFormattedText method of RichTextItem
Thanks for the suggestion. I tried it but sadly the same problem exists. Unless I did the method wrong.
Here’s the changed code.
public class JavaAgent extends AgentBase
{
public void NotesMain()
{
try
{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
Database db = agentContext.getCurrentDatabase();
View view = db.getView("IDDE");
Document doc = view.getFirstDocument();
Document newdoc = db.createDocument();
Item subject = doc.replaceItemValue("Subject", "IDDE Invoice - Redone");
RichTextItem rti = newdoc.createRichTextItem("Body");
RichTextStyle font = session.createRichTextStyle();
font.setFont(RichTextStyle.FONT_COURIER);
rti.appendStyle(font);
String token;
RichTextItem body = (RichTextItem)doc.getFirstItem("Body");
System.out.println("doc: \n" + body.getFormattedText(true, 0, 0));
The println still has all lines of the body starting in column one. So the tabs and/or spaces are still being lost somehow.
Any other thoughts? I’ve wracked my brain trying to figure this one out.
Thanks,
Andrew
Subject: RE: Try getFormattedText method of RichTextItem
Are you sure there are tabs there? First-line-indent and paragraph-indent styles are not tabs.
Subject: RE: Try getFormattedText method of RichTextItem
I’m not positive they are tabs, hence why I said tabs and/or spaces are being dropped off.
How can I identify what they are?
I thought GetFormattedText would keep the format regardless of indents, tabs, spaces, etc.
Subject: RE: Try getFormattedText method of RichTextItem
It will – if the tab-looking things are characters in the rich text. If the indents are the result of a paragraph style, then they aren’t represented by characters in the data, but by mark-up around the data. getFormattedText() can only handle the data in the field, not the markup.