Examples: RichTextRange class

  1. This agent uses the default range to set the size of all elements in an item.
    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here) 
          DocumentCollection dc = agentContext.getUnprocessedDocuments();
          Document doc = dc.getFirstDocument();
          RichTextItem body = (RichTextItem)doc.getFirstItem("Body");
          RichTextRange rtrange = body.createRange();
          RichTextStyle rts = session.createRichTextStyle();
          rts.setFontSize(14);
          rtrange.setStyle(rts);
          doc.save(true, true);
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This agent displays the range properties for each element in a rich text item, getting the elements in order by type.
    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
      
      RichTextNavigator rtnav = null;
      RichTextRange rtrange = null;
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here) 
          DocumentCollection dc = agentContext.getUnprocessedDocuments();
          Document doc = dc.getFirstDocument();
          RichTextItem body = (RichTextItem)doc.getFirstItem("Body");
          rtnav = body.createNavigator();
          rtrange = body.createRange();
          displayRange(RichTextItem.RTELEM_TYPE_DOCLINK,
            "Doc link");
          displayRange(RichTextItem.RTELEM_TYPE_FILEATTACHMENT,
            "File attachment");
          displayRange(RichTextItem.RTELEM_TYPE_OLE,
            "OLE object");
          displayRange(RichTextItem.RTELEM_TYPE_SECTION,
            "Section");
          displayRange(RichTextItem.RTELEM_TYPE_TABLE,
            "Table");
          displayRange(RichTextItem.RTELEM_TYPE_TABLECELL,
            "Table cell");
          displayRange(RichTextItem.RTELEM_TYPE_TEXTPARAGRAPH,
            "Text paragraph");
          displayRange(RichTextItem.RTELEM_TYPE_TEXTRUN,
            "Text run");
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
      
      void displayRange(int elemType, String elemTypeStr) {
        try {
          if (rtnav.findFirstElement(elemType)) {
            int count = 0;
            do {
              count++;
              System.out.println("\n" + elemTypeStr + " " + count);
              rtrange.setBegin(rtnav);
              System.out.println(
              "Element type = " + rtrange.getType());
              switch (elemType) {
                case RichTextItem.RTELEM_TYPE_TABLECELL:
                case RichTextItem.RTELEM_TYPE_TEXTPARAGRAPH:
                case RichTextItem.RTELEM_TYPE_TEXTRUN:
                  System.out.println(
                  "Text run: " + rtrange.getTextRun());
                  System.out.println(
                  "Text paragraph: " + rtrange.getTextParagraph());
              }
            } while (rtnav.findNextElement());
          }
          else
            System.out.println("\nNo " + elemTypeStr + " in Body");
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }