protected void updateExternalServices(ActionRequest actionRequest, PortletPreferences preferences)
      throws Exception {

    boolean imageMagickEnabled = ParamUtil.getBoolean(actionRequest, "imageMagickEnabled");
    String imageMagickPath = ParamUtil.getString(actionRequest, "imageMagickPath");
    boolean openOfficeEnabled = ParamUtil.getBoolean(actionRequest, "openOfficeEnabled");
    int openOfficePort = ParamUtil.getInteger(actionRequest, "openOfficePort");
    boolean xugglerEnabled = ParamUtil.getBoolean(actionRequest, "xugglerEnabled");

    preferences.setValue(PropsKeys.IMAGEMAGICK_ENABLED, String.valueOf(imageMagickEnabled));
    preferences.setValue(PropsKeys.IMAGEMAGICK_GLOBAL_SEARCH_PATH, imageMagickPath);
    preferences.setValue(PropsKeys.OPENOFFICE_SERVER_ENABLED, String.valueOf(openOfficeEnabled));
    preferences.setValue(PropsKeys.OPENOFFICE_SERVER_PORT, String.valueOf(openOfficePort));
    preferences.setValue(PropsKeys.XUGGLER_ENABLED, String.valueOf(xugglerEnabled));

    Enumeration<String> enu = actionRequest.getParameterNames();

    while (enu.hasMoreElements()) {
      String name = enu.nextElement();

      if (name.startsWith("imageMagickLimit")) {
        String key = name.substring(16, name.length()).toLowerCase();
        String value = ParamUtil.getString(actionRequest, name);

        preferences.setValue(PropsKeys.IMAGEMAGICK_RESOURCE_LIMIT + key, value);
      }
    }

    preferences.store();

    GhostscriptUtil.reset();
    ImageMagickUtil.reset();
  }
  private void _generateImages(FileVersion fileVersion, File file) throws Exception {

    if (GhostscriptUtil.isEnabled()) {
      if (!_ghostscriptInitialized) {
        GhostscriptUtil.reset();

        _ghostscriptInitialized = true;
      }

      _generateImagesGS(fileVersion, file);
    } else {
      _generateImagesPB(fileVersion, file);
    }
  }