Example #1
0
  /**
   * First an instance of text content is created using relation and inserted into text. Then the
   * number of contents is checked using the relation. Second a <code>null</code> content is tried
   * to insert.
   *
   * <p>Has <b> OK </b> status if in the first case after inserting number of content objects is
   * greater than zero and in the second case <code>IllegalArgumentException</code> is thrown.
   *
   * <p>
   */
  public void _insertTextContent() {
    boolean result = false;
    info = (XInstCreator) tEnv.getObjRelation("XTEXTINFO");
    oInt = info.createInstance();

    // write to log what we try next
    log.println("test for createTextCursor()");
    oCursor = oObj.createTextCursor();

    // write to log what we try next
    log.println("test for insertTextContent()");
    try {
      oObj.insertTextContent(oCursor, (XTextContent) oInt, false);
    } catch (com.sun.star.lang.IllegalArgumentException iaE) {
      throw new StatusException("Couldn't insert textcontent", iaE);
      // Status.failed(iaE.toString());
      // return;
    }

    // get indexaccess to the tablecollection
    XIndexAccess xIA = info.getCollection();

    // this comparison works just because it has to be at least one
    // table at this point regardless which thread inserted it
    // there is although the possibility that the first threads call
    // failed, the second not and comparison happens after second threads
    // otherwise if something fails it should have thrown an exception
    // tRes.tested("insertTextContent()",    xIA.getCount() > 0 );

    if (xIA != null) {
      result = (xIA.getCount() > 0);
    } else {
      result = true;
    }

    if (!result) log.println("The TextContent wasn't inserted");

    // try to insert an invalid TextContent
    log.println("test for insertTextContent");
    try {
      oObj.insertTextContent(oCursor, null, false);
      log.println("The expected Exception doesn't occurred");
      result &= false;
    } catch (com.sun.star.lang.IllegalArgumentException iaE) {
      // Some exception.FAILED
      log.println("Expected Exception occurred");
      String msg = iaE.getMessage();
      if (msg.equals("")) {
        log.println("But there is not detailed message");
      } else {
        log.println("Detailed message: " + msg);
      }

      result &= true;
    }

    tRes.tested("insertTextContent()", result);
  }
 /**
  * An instance of text content is created using relation and inserted before the paragraph which
  * was added into text in <code>insertTextContentAfter</code> method test.
  *
  * <p>Has <b>OK</b> status if no exceptions occurred.
  *
  * <p>The following method tests are to be completed successfully before :
  *
  * <ul>
  *   <li><code> insertTextContentAfter() </code> : here the <code>Paragraph</code> instance is
  *       inserted.
  * </ul>
  */
 public void _insertTextContentBefore() {
   requiredMethod("insertTextContentAfter()");
   try {
     XInstCreator para = (XInstCreator) tEnv.getObjRelation("PARA");
     XInterface oInt = para.createInstance();
     XTextContent new_content = (XTextContent) oInt;
     oObj.insertTextContentBefore(new_content, content);
     tRes.tested("insertTextContentBefore()", true);
   } catch (com.sun.star.lang.IllegalArgumentException ex) {
     log.println("Exception occurred while checking " + "insertTextContentBefore()");
     ex.printStackTrace(log);
     tRes.tested("insertTextContentBefore()", false);
   }
 } // end _insertTextContentBefore()
  /**
   * First an instance of <code>Paragraph</code> service created using relation and inserted into
   * text. Then an instance of text content is created and inserted after the paragraph.
   *
   * <p>Has <b>OK</b> status if no exceptions occurred.
   */
  public void _insertTextContentAfter() {

    try {
      XInstCreator para = (XInstCreator) tEnv.getObjRelation("PARA");
      XInterface oInt = para.createInstance();
      XTextContent new_content = (XTextContent) oInt;
      XText theText = UnoRuntime.queryInterface(XText.class, oObj);
      XTextCursor oCursor = theText.createTextCursor();
      XInstCreator info = (XInstCreator) tEnv.getObjRelation("XTEXTINFO");
      oInt = info.createInstance();
      content = (XTextContent) oInt;
      theText.insertTextContent(oCursor, content, false);
      oObj.insertTextContentAfter(new_content, content);
      tRes.tested("insertTextContentAfter()", true);
    } catch (com.sun.star.lang.IllegalArgumentException ex) {
      log.println("Exception occurred while checking " + "insertTextContentAfter()");
      ex.printStackTrace(log);
      tRes.tested("insertTextContentAfter()", false);
    }
  } // end _insertTextContentAfter()