例: RichTextRange class

  1. 次のエージェントは、デフォルトの範囲を使用して、アイテム内におけるすべての要素のサイズを設定します。
    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. 次のエージェントは、リッチテキストアイテム内の各要素の範囲プロパティを表示します。これらの要素はタイプ別の順序で取得されています。
    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();
        }
      }
    }