Esempio n. 1
0
  protected void doCreateDocument(
      final ReportOutputType outputType, final OutputStream outputStream)
      throws NoFreePortsException {
    OfficeTask officeTask =
        new OfficeTask() {
          @Override
          public void processTaskInOpenOffice(OfficeResourceProvider ooResourceProvider) {
            try {
              loadDocument(ooResourceProvider);

              // Handling tables
              fillTables(ooResourceProvider.getXDispatchHelper());
              // Handling text
              replaceAllAliasesInDocument();
              replaceAllAliasesInDocument(); // we do it second time to handle several open office
                                             // bugs (page breaks in html, etc). Do not remove.
              // Saving document to output stream and closing
              saveAndClose(ooResourceProvider, xComponent, outputType, outputStream);
            } catch (Exception e) {
              throw wrapWithReportingException(
                  "An error occurred while running task in Open Office server", e);
            }
          }
        };

    officeIntegration.runTaskWithTimeout(officeTask, officeIntegration.getTimeoutInSeconds());
  }
Esempio n. 2
0
  protected void fillTable(
      String name,
      BandData parentBand,
      TableManager tableManager,
      XDispatchHelper xDispatchHelper,
      int numberOfRowWithAliases)
      throws com.sun.star.uno.Exception {
    // Lock clipboard, cause uno uses it to grow tables, relevant for desktops
    synchronized (clipboardLock) {
      XTextTable xTextTable = tableManager.getXTextTable();
      if (officeIntegration.isDisplayDeviceAvailable()) {
        clearClipboard();
      }

      List<BandData> childrenByName = parentBand.getChildrenByName(name);
      for (BandData ignored : childrenByName) {
        tableManager.copyRow(
            xDispatchHelper,
            as(XTextDocument.class, xComponent).getCurrentController(),
            numberOfRowWithAliases);
      }

      int i = numberOfRowWithAliases;
      for (BandData child : childrenByName) {
        if (name.equals(child.getName())) {
          fillRow(child, tableManager, i);
          i++;
        }
      }
      tableManager.deleteRow(i);
    }
  }
Esempio n. 3
0
  public void renderDocument() {
    try {
      doCreateDocument(reportTemplate.getOutputType(), outputStream);
    } catch (Exception e) { // just try again if any exceptions occurred
      log.warn(
          String.format(
              "An error occurred while generating doc report [%s]. System will retry to generate report again.",
              reportTemplate.getDocumentName()),
          e);

      for (int i = 0; i < officeIntegration.getCountOfRetry(); i++) {
        try {
          doCreateDocument(reportTemplate.getOutputType(), outputStream);
          return;
        } catch (NoFreePortsException e1) {
          if (e instanceof NoFreePortsException) {
            throw (NoFreePortsException) e;
          }
        }
      }

      throw wrapWithReportingException("An error occurred while generating doc report.", e);
    }
  }