close

Filter

loading table of contents...

Blueprint Developer Manual / Version 2107

Table Of Contents
5.5.3.4.3 XLIFF Import

In order to import XLIFF and apply the translation to the target documents, you will use the XliffImporter.

boolean importXliffFile(InputStream inputStream) {
  XliffImporter importer = getSpringContext()
          .getBean(XliffImporter.class);

  List<XliffImportResultItem> resultItems;

  try {
    resultItems = asRobotUser(() -> importer.importXliff(inputStream));
  } catch (CapXliffImportException e) {
    LOG.warn("Failed to import XLIFF.", e);
    return false;
  }

  List<XliffImportResultItem> majorIssues =
          XliffImportResults.getMajorIssues(resultItems);

  if (!majorIssues.isEmpty()) {
    LOG.warn("XLIFF has major issues: {}", majorIssues);
    return false;
  }

  return true;
}

Example 5.18. Importing XLIFF


Example 5.18, “Importing XLIFF” shows how you may import a received XLIFF document within a workflow action. The example is used within an action to poll the results from the translation service and which will automatically apply XLIFF results as soon as they are available. The implementation assumes that it should repeat the XLIFF download until the download was successful.

To start get the XliffImporter bean from Spring context via getSpringContext() from SpringAwareLongAction.

The XliffImporter provides two ways to signal problems. While exceptions are typically related to for example I/O problems, internal problems such as missing translations, target documents which are gone, and so on, are reported as major issues. To help rating and analyzing the issues there is a utility class XliffImportResults, which will for example filter any relevant issues for you.

Note, that you may want to store issues in a workflow variable instead to present the information in CoreMedia Studio as part of the workflow detail panel.

If the workflow action runs in an automated task, it needs some user to update contents according to the translation result. It depends on your actual design of the action and the workflow process, which user should be taken. In the example, the translation workflow robot user is reused, which is part of the site model.

<T> T asRobotUser(Supplier<T> run) {
  User robotUser = getRobotUser();

  // Perform content operations in the name of the robot user.
  CapSession session = getCapSessionPool().acquireSession(robotUser);

  try {
    CapSession oldSession = session.activate();
    try {
      return run.get();
    } finally {
      oldSession.activate();
    }
  } finally {
    getCapSessionPool().releaseSession(session);
  }

}

User getRobotUser() {
  SiteModel siteModel = getSpringContext().getBean(SiteModel.class);
  String robotUserName = siteModel.getTranslationWorkflowRobotUser();
  UserRepository userRepository = getConnection().getUserRepository();

  User robotUser = userRepository.getUserByName(robotUserName);

  // Recommended: Add a check that the robotUser actually exists.

  return robotUser;
}

Example 5.19. Importing XLIFF


Example 5.19, “Importing XLIFF” sketches a possible implementation. asRobotUser will switch the session to a user session using the CapSessionPool provided by LongActionBase to execute the given supplier.

getRobotUser uses the site model to get the artificial robot user to perform the import action.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.