Пример #1
0
  /**
   * 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;
  }
Пример #2
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);
      }
    }
  }
Пример #3
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);
  }
Пример #4
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);
   }
 }
 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;
   }
 }
  /**
   * 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()
Пример #7
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;
    }
Пример #8
0
  /**
   * 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
  /**
   * 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
  /**
   * 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;
  }
  /**
   * 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