/**
   * Retrieves the start range and sets its context to 'Start' string.
   *
   * <p>Has <b>OK</b> status if the whole range string starts with 'Start' substring.
   *
   * <p>The following method tests are to be completed successfully before :
   *
   * <ul>
   *   <li><code> setString </code>
   * </ul>
   */
  public void _getStart() {

    XText the_text = (XText) tEnv.getObjRelation("XTEXT");

    if (the_text != null) {
      the_text.setString("");
    }

    String exp = "";

    oObj.setString("MiddleEnd");

    oStartRange = oObj.getStart();
    oStartRange.setString("Start");

    if (the_text != null) {
      exp = the_text.getString();
    } else exp = oObj.getText().getString();

    log.println("Start: " + exp);

    tRes.tested("getStart()", oStartRange != null && exp.startsWith("Start"));

    oStartRange.setString("");
  }
  /**
   * Creating a TestEnvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.text.Endnote</code>. Then created endnote is inserted to the text document,
   * and finally endnote settings are gotten from text document using <code>XEndnotesSupplier</code>
   * interface.
   */
  @Override
  public TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws Exception {
    XEndnotesSupplier oInterface = null;
    XInterface oObj = null;
    XInterface oEndnote;

    log.println("Creating a test environment");
    XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
    log.println("creating a endnote");
    oEndnote =
        UnoRuntime.queryInterface(
            XInterface.class, msf.createInstance("com.sun.star.text.Endnote"));

    XText oText = xTextDoc.getText();
    XTextCursor oCursor = oText.createTextCursor();

    log.println("inserting the footnote into text document");
    XTextContent xTC = UnoRuntime.queryInterface(XTextContent.class, oEndnote);
    oText.insertTextContent(oCursor, xTC, false);

    oInterface = UnoRuntime.queryInterface(XEndnotesSupplier.class, xTextDoc);
    oObj = oInterface.getEndnoteSettings();
    dbg.printPropertiesNames((XPropertySet) oObj);

    TestEnvironment tEnv = new TestEnvironment(oObj);
    return tEnv;
  }
Exemple #3
0
  protected void fillCell(BandData band, XCell xCell)
      throws NoSuchElementException, WrappedTargetException {
    XText xText = as(XText.class, xCell);
    String cellText = xText.getString();
    cellText = cellText.replace("\r\n", "\n"); // just a workaround for Windows \r\n break symbol
    List<String> parametersToInsert = new ArrayList<String>();
    Matcher matcher = UNIVERSAL_ALIAS_PATTERN.matcher(cellText);
    while (matcher.find()) {
      parametersToInsert.add(unwrapParameterName(matcher.group()));
    }
    for (String parameterName : parametersToInsert) {
      XTextCursor xTextCursor = xText.createTextCursor();

      String paramStr = "${" + parameterName + "}";
      int index = cellText.indexOf(paramStr);
      while (index >= 0) {
        xTextCursor.gotoStart(false);
        xTextCursor.goRight((short) (index + paramStr.length()), false);
        xTextCursor.goLeft((short) paramStr.length(), true);

        insertValue(xText, xTextCursor, band, parameterName);
        cellText = formatCellText(xText.getString());

        index = cellText.indexOf(paramStr);
      }
    }
  }
Exemple #4
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);
  }
  /**
   * Gets the text of the range and retrieves its String content.
   *
   * <p>Has <b>OK</b> status if the string returned equals to 'StartMiddleEnd' value.
   *
   * <p>The following method tests are to be completed successfully before :
   *
   * <ul>
   *   <li><code> setString </code> to get finally the string expected.
   *   <li><code> getStart </code> to get finally the string expected.
   *   <li><code> getEnd </code> to get finally the string expected.
   * </ul>
   */
  public void _getText() {
    requiredMethod("setString()");
    requiredMethod("getStart()");
    requiredMethod("getEnd()");

    XText txt = oObj.getText();

    tRes.tested("getText()", txt != null && txt.getString().equals("StartMiddle"));
  }
Exemple #6
0
 private void insertLinebreaks(long seed) {
   XText xText = m_xDoc.getText();
   java.util.Random rnd = new java.util.Random(seed);
   XTextCursor xCursor = m_xDoc.getText().createTextCursor();
   for (int i = 0; i < 30; i++) {
     xCursor.goRight((short) rnd.nextInt(300), false);
     XTextRange xCursorAsRange = UnoRuntime.queryInterface(XTextRange.class, xCursor);
     xText.insertControlCharacter(
         xCursorAsRange, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
   }
 }
  public void addTextArea(Object documentObj, String text, int x, int y, int width, int height)
      throws Exception {
    XTextDocument document = (XTextDocument) documentObj;
    XMultiServiceFactory factory = query(XMultiServiceFactory.class, document);

    XTextFrame xFrame = create(XTextFrame.class, factory, X_TEXTFRAME);

    setPositionAndSize(xFrame, x, y, width, height);

    XText xText = document.getText();
    xText.insertTextContent(xText.getEnd(), xFrame, false);

    appendText(xFrame.getText(), text);
  }
 private boolean action_removeSectionWithoutContents(OOComponentHelper ooDoc, String sectionName) {
   boolean bResult = false;
   try {
     XTextSection theSection = ooDocument.getSection(sectionName);
     XText docText = ooDocument.getTextDocument().getText();
     docText.removeTextContent(theSection);
     bResult = true;
   } catch (NoSuchElementException ex) {
     log.error("in removeSectionWIthoutContents : " + ex.getLocalizedMessage(), ex);
     bResult = false;
   } finally {
     return bResult;
   }
 }
 private boolean action_createSystemContainerFromSelection(
     OOComponentHelper ooDoc, String systemContainerName) {
   boolean bResult = false;
   try {
     XTextViewCursor xCursor = ooDocument.getViewCursor();
     XText xText = xCursor.getText();
     XTextContent xSectionContent = ooDocument.createTextSection(systemContainerName, (short) 1);
     xText.insertTextContent(xCursor, xSectionContent, true);
     bResult = true;
   } catch (com.sun.star.lang.IllegalArgumentException ex) {
     bResult = false;
     log.error("in addTextSection : " + ex.getLocalizedMessage(), ex);
   } finally {
     return bResult;
   }
 }
 private boolean action_createRootSection(OOComponentHelper ooDoc, String sectionName) {
   boolean bResult = false;
   try {
     XText docText = ooDocument.getTextDocument().getText();
     XTextCursor docCursor = docText.createTextCursor();
     docCursor.gotoStart(false);
     docCursor.gotoEnd(true);
     XTextContent theContent = ooDocument.createTextSection(sectionName, (short) 1);
     docText.insertTextContent(docCursor, theContent, true);
     bResult = true;
   } catch (IllegalArgumentException ex) {
     log.error("in action_createRootSection :" + ex.getMessage());
     log.error("in action_createRootSection :" + CommonExceptionUtils.getStackTrace(ex));
   } finally {
     return bResult;
   }
 }
Exemple #11
0
 private void setupBookmarks() throws com.sun.star.uno.Exception {
   XText xText = m_xDoc.getText();
   UnoRuntime.queryInterface(XSimpleText.class, xText);
   for (int nPara = 0; nPara < 10; ++nPara) {
     for (int nBookmark = 0; nBookmark < 100; ++nBookmark) {
       insertBookmark(
           xText.createTextCursor(),
           "P" + nPara + "word" + nBookmark,
           "P" + nPara + "word" + nBookmark);
       XTextCursor xWordCursor = xText.createTextCursor();
       xWordCursor.setString(" ");
     }
     XTextCursor xParaCursor = xText.createTextCursor();
     XTextRange xParaCursorAsRange = UnoRuntime.queryInterface(XTextRange.class, xParaCursor);
     xText.insertControlCharacter(
         xParaCursorAsRange, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false);
   }
 }
  /**
   * 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()
Exemple #13
0
    public BandFinder find() {
      bandName = tableName;
      band = rootBand.findBandRecursively(bandName);
      if (band == null) {
        XText xText = tableManager.findFirstEntryInRow(BAND_NAME_DECLARATION_PATTERN, 0);
        if (xText != null) {
          Matcher matcher = BAND_NAME_DECLARATION_PATTERN.matcher(xText.getString());
          if (matcher.find()) {
            bandName = matcher.group(1);
            band = rootBand.findBandRecursively(bandName);
            XTextCursor xTextCursor = xText.createTextCursor();

            xTextCursor.gotoStart(false);
            xTextCursor.goRight((short) matcher.end(), false);
            xTextCursor.goLeft((short) matcher.group().length(), true);

            xText.insertString(xTextCursor, "", true);
          }
        }
      }
      return this;
    }
  /**
   * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.text.TextFrame</code>. Then inserts created text frame to the text, and
   * finally gets all frames of text document using <code>XTextFramesSupplier</code> interface.<br>
   */
  public synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
      throws StatusException {
    XInterface oObj = null;
    XTextFrame oFrame1 = null;
    XText oText = null;
    XTextCursor oCursor = null;
    XMultiServiceFactory oDocMSF = null;
    XTextFramesSupplier oInterface = null;

    log.println("creating a test environment");
    try {
      oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
      Object oInt = oDocMSF.createInstance("com.sun.star.text.TextFrame");
      oFrame1 = UnoRuntime.queryInterface(XTextFrame.class, oInt);
    } catch (com.sun.star.uno.Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't create instance of TextFrame", e);
    }

    oText = xTextDoc.getText();
    oCursor = oText.createTextCursor();

    try {
      oText.insertTextContent(oCursor, oFrame1, false);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
      throw new StatusException("Error: can't insert text content to text document", e);
    }

    oInterface = UnoRuntime.queryInterface(XTextFramesSupplier.class, xTextDoc);

    oObj = oInterface.getTextFrames();

    log.println("creating a new environment for Frame object");
    TestEnvironment tEnv = new TestEnvironment(oObj);

    return tEnv;
  } // finish method getTestEnvironment
Exemple #15
0
  protected void insertValue(
      XText text, XTextRange textRange, BandData band, String parameterName) {
    String fullParameterName = band.getName() + "." + parameterName;
    Object paramValue = band.getParameterValue(parameterName);

    Map<String, ReportFieldFormat> formats = rootBand.getReportFieldFormats();
    try {
      boolean handled = false;

      if (paramValue != null) {
        if ((formats != null) && (formats.containsKey(fullParameterName))) {
          String format = formats.get(fullParameterName).getFormat();
          // Handle doctags
          for (ContentInliner contentInliner : contentInliners) {
            Matcher matcher = contentInliner.getTagPattern().matcher(format);
            if (matcher.find()) {
              contentInliner.inlineToDoc(officeComponent, textRange, text, paramValue, matcher);
              handled = true;
            }
          }
        }
        if (!handled) {
          String valueString = formatValue(paramValue, parameterName, fullParameterName);
          text.insertString(textRange, valueString, true);
        }
      } else {
        text.insertString(textRange, "", true);
      }
    } catch (Exception ex) {
      throw wrapWithReportingException(
          String.format(
              "An error occurred while inserting parameter [%s] into text line [%s]",
              parameterName, text.getString()),
          ex);
    }
  }
Exemple #16
0
  /**
   * Removes the text contet added before.
   *
   * <p>Has <b> OK </b> status if the method successfully returns and no exceptions were thrown.
   *
   * <p>The following method tests are to be completed successfully before :
   *
   * <ul>
   *   <li><code> insertTextContent() </code> : inserts the content to be removed in this test.
   * </ul>
   */
  public void _removeTextContent() {

    // leads to a method which should be called previously
    requiredMethod("insertTextContent()");

    // write to log what we try next
    log.println("test for  removeTextContent");
    try {
      oObj.removeTextContent((XTextContent) oInt);
      // oObj.removeTextContent( (XTextContent)oInt );
    } catch (com.sun.star.container.NoSuchElementException nseE) {
      // Some exception.FAILED
      Status.failed(nseE.toString());
      return;
    }

    // no exception occurred so it works
    tRes.tested("removeTextContent()", true);
  }
  public void drawOrganigram() throws java.lang.Exception {
    // get the remote office component context
    xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
    System.out.println("Connected to a running office ...");
    // get the remote service manager
    xRemoteServiceManager = xRemoteContext.getServiceManager();

    Object desktop =
        xRemoteServiceManager.createInstanceWithContext(
            "com.sun.star.frame.Desktop", xRemoteContext);
    XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop);

    PropertyValue[] loadProps = new PropertyValue[0];
    XComponent xDrawComponent =
        xComponentLoader.loadComponentFromURL("private:factory/sdraw", "_blank", 0, loadProps);

    // get draw page by index
    com.sun.star.drawing.XDrawPagesSupplier xDrawPagesSupplier =
        UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPagesSupplier.class, xDrawComponent);
    com.sun.star.drawing.XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
    Object drawPage = xDrawPages.getByIndex(0);
    com.sun.star.drawing.XDrawPage xDrawPage =
        UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class, drawPage);

    com.sun.star.lang.XMultiServiceFactory xDocumentFactory =
        UnoRuntime.queryInterface(com.sun.star.lang.XMultiServiceFactory.class, xDrawComponent);

    com.sun.star.beans.XPropertySet xPageProps =
        UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xDrawPage);

    int pageWidth = AnyConverter.toInt(xPageProps.getPropertyValue("Width"));
    int pageHeight = AnyConverter.toInt(xPageProps.getPropertyValue("Height"));
    int pageBorderTop = AnyConverter.toInt(xPageProps.getPropertyValue("BorderTop"));
    int pageBorderLeft = AnyConverter.toInt(xPageProps.getPropertyValue("BorderLeft"));
    int pageBorderRight = AnyConverter.toInt(xPageProps.getPropertyValue("BorderRight"));
    int drawWidth = pageWidth - pageBorderLeft - pageBorderRight;
    int horCenter = pageBorderLeft + drawWidth / 2;

    String[][] orgUnits = new String[2][4];
    orgUnits[0][0] = "Management";
    orgUnits[1][0] = "Production";
    orgUnits[1][1] = "Purchasing";
    orgUnits[1][2] = "IT Services";
    orgUnits[1][3] = "Sales";
    int[] levelCount = {1, 4};

    int horSpace = 300;
    int verSpace = 3000;

    int shapeWidth = (drawWidth - (levelCount[1] - 1) * horSpace) / levelCount[1];
    int shapeHeight = pageHeight / 20;
    int shapeX = pageWidth / 2 - shapeWidth / 2;
    int shapeY = pageBorderTop;

    int levelY;
    int levelX;

    com.sun.star.drawing.XShape xStartShape = null;

    for (int level = 0; level <= 1; level++) {
      levelY = pageBorderTop + 2000 + level * (shapeHeight + verSpace);
      for (int i = levelCount[level] - 1; i > -1; i--) {
        shapeX =
            horCenter
                - (levelCount[level] * shapeWidth + (levelCount[level] - 1) * horSpace) / 2
                + i * shapeWidth
                + i * horSpace;
        Object shape = xDocumentFactory.createInstance("com.sun.star.drawing.RectangleShape");
        com.sun.star.drawing.XShape xShape =
            UnoRuntime.queryInterface(com.sun.star.drawing.XShape.class, shape);
        xShape.setPosition(new com.sun.star.awt.Point(shapeX, levelY));
        xShape.setSize(new com.sun.star.awt.Size(shapeWidth, shapeHeight));
        xDrawPage.add(xShape);

        com.sun.star.text.XText xText =
            UnoRuntime.queryInterface(com.sun.star.text.XText.class, xShape);

        xText.setString(orgUnits[level][i]);

        // memorize the root shape
        if (level == 0 && i == 0) xStartShape = xShape;

        if (level == 1) {
          Object connector = xDocumentFactory.createInstance("com.sun.star.drawing.ConnectorShape");
          com.sun.star.beans.XPropertySet xConnectorProps =
              UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, connector);
          com.sun.star.drawing.XShape xConnector =
              UnoRuntime.queryInterface(com.sun.star.drawing.XShape.class, connector);
          xDrawPage.add(xConnector);
          xConnectorProps.setPropertyValue("StartShape", xStartShape);
          xConnectorProps.setPropertyValue("EndShape", xShape);
          xConnectorProps.setPropertyValue(
              "StartGluePointIndex", new Integer(2)); // 2 = bottom glue point
          xConnectorProps.setPropertyValue(
              "EndGluePointIndex", new Integer(0)); // 0 = top glue point
        }
      }
    }
  }
  /**
   * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service
   * <code>com.sun.star.text.AutoTextContainer</code>, then selects the 'mytexts' group from the
   * given container using <code>XNameAccess</code> interface, and inserts some text entry to this
   * group. Then entry passed as test component.
   *
   * <p>Object relations created :
   *
   * <ul>
   *   <li><code>'XTEXTINFO'</code> for {@link ifc.text._XText} : creates tables 6x4
   *   <li><code>'TEXTDOC'</code> for {@link ifc.text._XAutoTextEntry} : text document
   * </ul>
   */
  protected synchronized TestEnvironment createTestEnvironment(
      TestParameters Param, PrintWriter log) {

    XAutoTextEntry oEntry = null;
    XAutoTextContainer oContainer;
    XInterface oObj = null;
    log.println("creating a test environment");
    try {
      XMultiServiceFactory myMSF = (XMultiServiceFactory) Param.getMSF();
      Object oInst = myMSF.createInstance("com.sun.star.text.AutoTextContainer");
      oContainer = UnoRuntime.queryInterface(XAutoTextContainer.class, oInst);
    } catch (com.sun.star.uno.Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't create AutoTextContainer", e);
    }

    XNameAccess oContNames = UnoRuntime.queryInterface(XNameAccess.class, oContainer);

    String contNames[] = oContNames.getElementNames();
    for (int i = 0; i < contNames.length; i++) {
      log.println("ContainerNames[ " + i + "]: " + contNames[i]);
    }

    try {
      oObj =
          (XInterface)
              AnyConverter.toObject(new Type(XInterface.class), oContNames.getByName("mytexts"));
    } catch (com.sun.star.uno.Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get AutoTextGroup", e);
    }

    oGroup = UnoRuntime.queryInterface(XAutoTextGroup.class, oObj);
    String[] oENames = oGroup.getElementNames();
    for (int i = 0; i < oENames.length; i++) {
      log.println("AutoTextEntryNames[" + i + "]: " + oENames[i]);
    }

    XText oText = xTextDoc.getText();
    oText.insertString(oText.getStart(), "New AutoText", true);
    XTextRange oTextRange = oText;
    try {
      if (oGroup.hasByName("NewEntryName")) {
        oGroup.removeByName("NewEntryName");
        log.println("Element 'NewEntryName' exists, removing...");
      }
      log.println("Adding new element 'NewEntryName' to group...");
      oGroup.insertNewByName("NewEntryName", "NewEntryTitle", oTextRange);
      oEntry =
          (XAutoTextEntry)
              AnyConverter.toObject(
                  new Type(XAutoTextEntry.class), oGroup.getByName("NewEntryName"));
    } catch (com.sun.star.container.ElementExistException e) {
      e.printStackTrace(log);
    } catch (com.sun.star.container.NoSuchElementException e) {
      e.printStackTrace(log);
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
    }

    oObj = oEntry;

    log.println("Trying to use XText as TextRange in the method applyTo");
    oEntry.applyTo(oTextRange);

    oTextRange = oText.createTextCursor();
    log.println("Trying to use XTextCursor as TextRange in the method applyTo");
    oEntry.applyTo(oTextRange);

    log.println("creating a new environment for AutoTextEntry object");
    TestEnvironment tEnv = new TestEnvironment(oObj);

    // adding relation for XText
    DefaultDsc tDsc =
        new DefaultDsc("com.sun.star.text.XTextContent", "com.sun.star.text.TextField.DateTime");
    log.println("    adding InstCreator object");
    tEnv.addObjRelation("XTEXTINFO", new InstCreator(xTextDoc, tDsc));

    log.println("adding TextDocument as mod relation to environment");
    tEnv.addObjRelation("TEXTDOC", xTextDoc);

    return tEnv;
  } // finish method getTestEnvironment
  /**
   * Creating a Testenvironment for the interfaces to be tested. Retrieves the collection of style
   * families available in the document using the interface <code>XStyleFamiliesSupplier</code>.
   * Obtains default style from the style family <code>'PageStyles'</code>. Retrieves value of the
   * property <code>'RightPageHeaderContent'</code>. Sets some string for the text which is printed
   * in the center part of the header or footer using the interface <code>XHeaderFooterContent
   * </code> and sets new value of the property <code>'RightPageHeaderContent'</code>. Creates text
   * cursor for the text which is printed in the center part of the header or footer. This text
   * cursor is the instance of the service <code>com.sun.star.text.TextCursor</code>.
   * </ul>
   */
  protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {

    XInterface oObj = null;
    XPropertySet PropSet;
    XNameAccess PageStyles = null;
    XStyle StdStyle = null;

    XStyleFamiliesSupplier StyleFam =
        UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xSpreadsheetDoc);

    XNameAccess StyleFamNames = StyleFam.getStyleFamilies();
    try {
      PageStyles =
          (XNameAccess)
              AnyConverter.toObject(
                  new Type(XNameAccess.class), StyleFamNames.getByName("PageStyles"));
      StdStyle =
          (XStyle) AnyConverter.toObject(new Type(XStyle.class), PageStyles.getByName("Default"));
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get by name", e);
    } catch (com.sun.star.container.NoSuchElementException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get by name", e);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get by name", e);
    }

    // get the property-set
    PropSet = UnoRuntime.queryInterface(XPropertySet.class, StdStyle);

    XHeaderFooterContent RPHC = null;
    // creation of testobject here
    // first we write what we are intend to do to log file
    log.println("creating a test environment");
    try {
      RPHC =
          (XHeaderFooterContent)
              AnyConverter.toObject(
                  new Type(XHeaderFooterContent.class),
                  PropSet.getPropertyValue("RightPageHeaderContent"));
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get HeaderContent", e);
    } catch (com.sun.star.beans.UnknownPropertyException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get HeaderContent", e);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't get HeaderContent", e);
    }

    XText center = RPHC.getCenterText();
    center.setString("CENTER");

    try {
      PropSet.setPropertyValue("RightPageHeaderContent", RPHC);
    } catch (com.sun.star.lang.WrappedTargetException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    } catch (com.sun.star.lang.IllegalArgumentException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    } catch (com.sun.star.beans.PropertyVetoException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    } catch (com.sun.star.beans.UnknownPropertyException e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't set HeaderContent", e);
    }

    // create testobject here
    oObj = center.createTextCursor();
    TestEnvironment tEnv = new TestEnvironment(oObj);

    // add relation for XTextRange
    tEnv.addObjRelation("XTEXT", UnoRuntime.queryInterface(XText.class, center));

    return tEnv;
  } // finish method getTestEnvironment
 private void appendText(XText xText, String text) {
   xText.insertString(xText.getEnd(), text, false);
 }
  /**
   * Called to create an instance of <code>TestEnvironment</code> with an object to test and related
   * objects. Creates a frame and inserts it into document. Obtains accessible object for the
   * inserted text frame.
   *
   * @param Param test parameters
   * @param log writer to log information while testing
   * @see TestEnvironment
   * @see #getTestEnvironment
   */
  protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {

    XInterface oObj = null;
    XTextFrame oFrame1 = null;
    XPropertySet oPropSet = null;
    XText oText = null;
    XTextCursor oCursor = null;

    // get a soffice factory object
    SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) Param.getMSF());
    // creating Frames
    log.println("creating Frames");
    try {
      oFrame1 = SOfficeFactory.createTextFrame(xTextDoc, 500, 500);
      oPropSet = UnoRuntime.queryInterface(XPropertySet.class, oFrame1);
      oPropSet.setPropertyValue("AnchorType", TextContentAnchorType.AS_CHARACTER);
      oText = xTextDoc.getText();
      oCursor = oText.createTextCursor();

      log.println("inserting Frame1");
      XTextContent the_content = UnoRuntime.queryInterface(XTextContent.class, oFrame1);
      oText.insertTextContent(oCursor, the_content, true);
    } catch (Exception e) {
      e.printStackTrace(log);
      throw new StatusException("Couldn't insert TextFrame", e);
    }

    XModel aModel = UnoRuntime.queryInterface(XModel.class, xTextDoc);

    AccessibilityTools at = new AccessibilityTools();

    XWindow xWindow =
        AccessibilityTools.getCurrentWindow((XMultiServiceFactory) Param.getMSF(), aModel);
    XAccessible xRoot = AccessibilityTools.getAccessibleObject(xWindow);

    oObj = AccessibilityTools.getAccessibleObjectForRole(xRoot, AccessibleRole.TEXT_FRAME);

    log.println("ImplementationName " + utils.getImplName(oObj));
    AccessibilityTools.printAccessibleTree(
        log, xRoot, Param.getBool(util.PropertyName.DEBUG_IS_ACTIVE));

    TestEnvironment tEnv = new TestEnvironment(oObj);

    XController xController = xTextDoc.getCurrentController();
    XViewSettingsSupplier xViewSetSup =
        UnoRuntime.queryInterface(XViewSettingsSupplier.class, xController);

    final XPropertySet PropSet = xViewSetSup.getViewSettings();

    tEnv.addObjRelation(
        "EventProducer",
        new ifc.accessibility._XAccessibleEventBroadcaster.EventProducer() {
          public void fireEvent() {
            try {
              // change zoom value to 15%
              PropSet.setPropertyValue("ZoomValue", new Short("15"));
              // and back to 100%
              PropSet.setPropertyValue("ZoomValue", new Short("100"));
            } catch (com.sun.star.lang.WrappedTargetException e) {

            } catch (com.sun.star.lang.IllegalArgumentException e) {

            } catch (com.sun.star.beans.PropertyVetoException e) {

            } catch (com.sun.star.beans.UnknownPropertyException e) {

            }
          }
        });

    return tEnv;
  }