code: @Nullable
    private XTextDocument getCurrentDocument(XComponentContext xContext) {
      try {
        XComponent curComp = OfficeTools.getCurrentComponent(xContext);
        if (curComp == null) {
          return null;
        }
        else return UnoRuntime.queryInterface(XTextDocument.class, curComp);
      } catch (Throwable t) {
        MessageHandler.printException(t);     // all Exceptions thrown by UnoRuntime.queryInterface are caught
        return null;           // Return null as method failed
      }
    }
docs: Returns the current text document (if any)
  Returns null if it fails