コード例 #1
0
ファイル: MessageBundlesHelper.java プロジェクト: pmalves/cde
  public MessageBundlesHelper(String msgsRelativeDir, IBasicFile sourceDashboardBaseMsgFile) {

    this.staticBaseContentUrl = CdeEngine.getEnv().getExtApi().getPluginStaticBaseUrl();

    if (StringUtils.isEmpty(msgsRelativeDir)) {
      this.msgsRelativeDir = String.valueOf(RepositoryHelper.SEPARATOR);
    } else if (!msgsRelativeDir.startsWith(String.valueOf(RepositoryHelper.SEPARATOR))) {
      this.msgsRelativeDir = String.valueOf(RepositoryHelper.SEPARATOR) + msgsRelativeDir;
    }
    this.sourceDashboardBaseMsgFile = sourceDashboardBaseMsgFile;
    this.languagesCacheUrl = Utils.joinPath(staticBaseContentUrl, BASE_CACHE_DIR, msgsRelativeDir);
  }
コード例 #2
0
ファイル: MessageBundlesHelper.java プロジェクト: pmalves/cde
  protected void appendMessageFiles(
      IBasicFile sourceDashboardBaseMsgFile,
      IBasicFile globalBaseMessageFile,
      IBasicFile targetDashboardBaseMsgFile)
      throws IOException {

    Locale locale = CdeEngine.getEnv().getLocale();

    IUserContentAccess userContentAccess =
        CdeEngine.getEnv().getContentAccessFactory().getUserContentAccess(msgsRelativeDir);
    IRWAccess systemWriter =
        CdeEngine.getEnv()
            .getContentAccessFactory()
            .getPluginSystemWriter(Utils.joinPath(BASE_CACHE_DIR, msgsRelativeDir));

    // If localized global message file doesn't exists then use the standard base global message
    // file
    // and generate a fake global message file. So this way we're sure that we always have the file
    String localizedMsgGlobalName =
        BASE_GLOBAL_MESSAGE_SET_FILENAME + "_" + locale.getLanguage() + ".properties";

    if (userContentAccess.fileExists(localizedMsgGlobalName)) {

      systemWriter.saveFile(
          localizedMsgGlobalName, userContentAccess.getFileInputStream(localizedMsgGlobalName));

    } else if (globalBaseMessageFile != null) {

      systemWriter.saveFile(localizedMsgGlobalName, globalBaseMessageFile.getContents());
    }

    // Append specific message file only if it exists otherwise just use the global message files
    if (sourceDashboardBaseMsgFile != null) {

      systemWriter.saveFile(
          sourceDashboardBaseMsgFile.getName(), sourceDashboardBaseMsgFile.getContents());

      String localizedMsgTargetName =
          FilenameUtils.getBaseName(sourceDashboardBaseMsgFile.getName())
              + "_"
              + locale.getLanguage()
              + ".properties";

      if (userContentAccess.fileExists(localizedMsgTargetName)) {

        systemWriter.saveFile(
            localizedMsgTargetName, userContentAccess.getFileInputStream(localizedMsgTargetName));
      }
    }
  }
コード例 #3
0
ファイル: MessageBundlesHelper.java プロジェクト: pmalves/cde
  protected IBasicFile getGlobalMsgCacheFile() {
    if (globalMsgCacheFile == null) {

      IReadAccess systemReader =
          CdeEnvironment.getPluginSystemReader(Utils.joinPath(BASE_CACHE_DIR, msgsRelativeDir));

      String msg = BASE_GLOBAL_MESSAGE_SET_FILENAME + ".properties";

      if (systemReader.fileExists(msg)) {
        globalMsgCacheFile = systemReader.fetchFile(msg);
      }
    }

    return globalMsgCacheFile;
  }
コード例 #4
0
ファイル: MessageBundlesHelper.java プロジェクト: pmalves/cde
  protected IBasicFile getTargetDashboardBaseMessageFile() {
    if (targetDashboardBaseMsgFile == null) {

      IReadAccess systemReader =
          CdeEnvironment.getPluginSystemReader(Utils.joinPath(BASE_CACHE_DIR, msgsRelativeDir));

      String msg =
          sourceDashboardBaseMsgFile != null
              ? sourceDashboardBaseMsgFile.getName()
              : BASE_GLOBAL_MESSAGE_SET_FILENAME + ".properties";

      if (systemReader.fileExists(msg)) {
        targetDashboardBaseMsgFile = systemReader.fetchFile(msg);
      }
    }
    return targetDashboardBaseMsgFile;
  }
コード例 #5
0
ファイル: CdfTemplates.java プロジェクト: pmalves/cde
  public void save(String file, String structure) throws DashboardStructureException, IOException {
    logger.info("Saving File:" + file);
    IRWAccess access = CdeEnvironment.getPluginRepositoryWriter();

    if (!access.fileExists(REPOSITORY_CDF_DD_TEMPLATES_CUSTOM)) {
      access.createFolder(REPOSITORY_CDF_DD_TEMPLATES_CUSTOM);
    }

    structure = addDashboardStyleAndRendererTypeToTemplate(structure);

    byte[] fileData = structure.getBytes(CharsetHelper.getEncoding());
    if (!access.saveFile(
        Utils.joinPath(REPOSITORY_CDF_DD_TEMPLATES_CUSTOM, file),
        new ByteArrayInputStream(fileData))) {
      throw new DashboardStructureException(
          Messages.getString("DashboardStructure.ERROR_006_SAVE_FILE_ADD_FAIL_EXCEPTION"));
    }
  }
コード例 #6
0
ファイル: MessageBundlesHelper.java プロジェクト: pmalves/cde
  public void saveI18NMessageFilesToCache() {

    if (!CdeEnvironment.getPluginSystemReader(BASE_CACHE_DIR).fileExists(msgsRelativeDir)) {
      CdeEnvironment.getPluginSystemWriter()
          .createFolder(Utils.joinPath(BASE_CACHE_DIR, msgsRelativeDir));
    }

    try {

      copyStdGlobalMessageFileToCache();

      appendMessageFiles(
          sourceDashboardBaseMsgFile,
          getGlobalBaseMessageFile(),
          getTargetDashboardBaseMessageFile());

    } catch (IOException e) {
      logger.error(e);
    }
  }
コード例 #7
0
ファイル: MessageBundlesHelper.java プロジェクト: pmalves/cde
  protected void copyStdGlobalMessageFileToCache() throws IOException {

    IBasicFile globalMsgCacheFile = getGlobalMsgCacheFile();

    if (globalMsgCacheFile != null && globalMsgCacheFile.getContents() != null) {
      return;

    } else {

      String globalMsgFileName = BASE_GLOBAL_MESSAGE_SET_FILENAME + ".properties";

      IBasicFile globalMsgFile =
          CdeEnvironment.getPluginSystemReader(SYSTEM_PLUGIN_GLOBAL_LANGUAGES_DIR)
              .fetchFile(globalMsgFileName);

      CdeEnvironment.getPluginSystemWriter()
          .saveFile(
              Utils.joinPath(BASE_CACHE_DIR, msgsRelativeDir, globalMsgFileName),
              globalMsgFile.getContents());
    }
  }
コード例 #8
0
  @POST
  @Path("/syncronizeDashboard")
  @Produces(MimeTypes.JSON)
  public String syncronize(
      @FormParam(MethodParams.FILE) @DefaultValue("") String file,
      @FormParam(MethodParams.PATH) @DefaultValue("") String path,
      @FormParam(MethodParams.TITLE) @DefaultValue("") String title,
      @FormParam(MethodParams.AUTHOR) @DefaultValue("") String author,
      @FormParam(MethodParams.DESCRIPTION) @DefaultValue("") String description,
      @FormParam(MethodParams.STYLE) @DefaultValue("") String style,
      @FormParam(MethodParams.WIDGET_NAME) @DefaultValue("") String widgetName,
      @FormParam(MethodParams.WIDGET) boolean widget,
      @FormParam(MethodParams.RENDERER_TYPE) @DefaultValue("") String rendererType,
      @FormParam(MethodParams.WIDGET_PARAMETERS) List<String> widgetParams,
      @FormParam(MethodParams.DASHBOARD_STRUCTURE) String cdfStructure,
      @FormParam(MethodParams.OPERATION) String operation,
      @FormParam(MethodParams.REQUIRE) boolean require,
      @Context HttpServletRequest request,
      @Context HttpServletResponse response)
      throws Exception {

    boolean isPreview = false;

    if (!file.isEmpty() && !file.equals(UNSAVED_FILE_PATH)) {

      file = Utils.getURLDecoded(file, CharsetHelper.getEncoding());

      // check access to path folder
      String fileDir =
          file.contains(".wcdf") || file.contains(".cdfde")
              ? file.substring(0, file.lastIndexOf("/"))
              : file;

      isPreview = (file.contains("_tmp.cdfde") || file.contains("_tmp.wcdf"));

      IReadAccess rwAccess = Utils.getSystemOrUserRWAccess(file);

      if (rwAccess == null) {
        String msg =
            "Access denied for the syncronize method syncronizeDashboard."
                + operation
                + " : "
                + file;
        logger.warn(msg);
        return JsonUtils.getJsonResult(false, msg);
      }
    }

    try {
      final DashboardStructure dashboardStructure = new DashboardStructure();
      Object result = null;
      HashMap<String, Object> params = new HashMap<String, Object>();
      params.put(MethodParams.FILE, file);
      params.put(MethodParams.WIDGET, String.valueOf(widget));
      params.put(MethodParams.REQUIRE, String.valueOf(require));
      if (!author.isEmpty()) {
        params.put(MethodParams.AUTHOR, author);
      }
      if (!style.isEmpty()) {
        params.put(MethodParams.STYLE, style);
      }
      if (!widgetName.isEmpty()) {
        params.put(MethodParams.WIDGET_NAME, widgetName);
      }
      if (!rendererType.isEmpty()) {
        params.put(MethodParams.RENDERER_TYPE, rendererType);
      }
      if (!title.isEmpty()) {
        params.put(MethodParams.TITLE, title);
      }
      if (!description.isEmpty()) {
        params.put(MethodParams.DESCRIPTION, description);
      }
      String[] widgetParameters = widgetParams.toArray(new String[0]);
      if (widgetParameters.length > 0) {
        params.put(MethodParams.WIDGET_PARAMETERS, widgetParameters);
      }

      String wcdfdeFile = file.replace(".wcdf", ".cdfde");

      if (OPERATION_LOAD.equalsIgnoreCase(operation)) {
        return dashboardStructure.load(wcdfdeFile);
      } else if (OPERATION_DELETE.equalsIgnoreCase(operation)) {
        dashboardStructure.delete(params);
      } else if (OPERATION_DELETE_PREVIEW.equalsIgnoreCase(operation)) {
        dashboardStructure.deletePreviewFiles(wcdfdeFile);
      } else if (OPERATION_SAVE.equalsIgnoreCase(operation)) {
        result = dashboardStructure.save(file, cdfStructure);
      } else if (OPERATION_SAVE_AS.equalsIgnoreCase(operation)) {
        if (StringUtils.isEmpty(title)) {
          title = FilenameUtils.getBaseName(file);
        }
        result = dashboardStructure.saveAs(file, title, description, cdfStructure, isPreview);
      } else if (OPERATION_NEW_FILE.equalsIgnoreCase(operation)) {
        dashboardStructure.newfile(params);
      } else if (OPERATION_SAVE_SETTINGS.equalsIgnoreCase(operation)) {

        // check if user is attempting to save settings over a new (non yet saved)
        // dashboard/widget/template
        if (StringUtils.isEmpty(file) || file.equals(UNSAVED_FILE_PATH)) {
          logger.warn(getMessage("CdfTemplates.ERROR_003_SAVE_DASHBOARD_FIRST"));
          return JsonUtils.getJsonResult(
              false, getMessage("CdfTemplates.ERROR_003_SAVE_DASHBOARD_FIRST"));
        }
        dashboardStructure.savesettings(params);
      } else {
        logger.error("Unknown operation: " + operation);
      }
      return JsonUtils.getJsonResult(true, result);
    } catch (Exception e) {
      if (e.getCause() != null) {
        if (e.getCause() instanceof DashboardStructureException) {
          JsonUtils.buildJsonResult(response.getOutputStream(), false, e.getCause().getMessage());
        } else if (e instanceof InvocationTargetException) {
          throw (Exception) e.getCause();
        }
      }
      throw e;
    }
  }
コード例 #9
0
  @POST
  @Path("/saveDashboard")
  @Produces(MimeTypes.JSON)
  @Consumes("multipart/form-data")
  public String saveDashboard(
      @FormDataParam(MethodParams.FILE) @DefaultValue("") String file,
      @FormDataParam(MethodParams.TITLE) @DefaultValue("") String title,
      @FormDataParam(MethodParams.DESCRIPTION) @DefaultValue("") String description,
      @FormDataParam(MethodParams.DASHBOARD_STRUCTURE) String cdfStructure,
      @FormDataParam(MethodParams.OPERATION) String operation,
      @Context HttpServletResponse response)
      throws Exception {

    boolean isPreview = false;

    if (!file.isEmpty()
        && !(file.equals(UNSAVED_FILE_PATH)
            || Utils.getURLDecoded(file).equals(UNSAVED_FILE_PATH))) {

      file = Utils.getURLDecoded(file, CharsetHelper.getEncoding());

      if (StringUtils.isEmpty(title)) {
        title = FilenameUtils.getBaseName(file);
      }

      // check access to path folder
      String fileDir =
          file.contains(".wcdf") || file.contains(".cdfde")
              ? file.substring(0, file.lastIndexOf("/"))
              : file;

      isPreview = (file.contains("_tmp.cdfde") || file.contains("_tmp.wcdf"));

      IReadAccess rwAccess;
      if (OPERATION_SAVE_AS.equalsIgnoreCase(operation) && !isPreview) {
        rwAccess = Utils.getSystemOrUserRWAccess(fileDir);
      } else {
        rwAccess = Utils.getSystemOrUserRWAccess(file);
      }

      if (rwAccess == null) {
        String msg =
            "Access denied for the syncronize method saveDashboard." + operation + " : " + file;
        logger.warn(msg);
        return JsonUtils.getJsonResult(false, msg);
      }
    }

    try {
      final DashboardStructure dashboardStructure = new DashboardStructure();
      Object result = null;

      if (OPERATION_SAVE.equalsIgnoreCase(operation)) {
        result = dashboardStructure.save(file, cdfStructure);
      } else if (OPERATION_SAVE_AS.equalsIgnoreCase(operation)) {
        result = dashboardStructure.saveAs(file, title, description, cdfStructure, isPreview);
      } else {
        logger.error("Unknown operation: " + operation);
      }
      return JsonUtils.getJsonResult(true, result);
    } catch (Exception e) {
      if (e.getCause() != null) {
        if (e.getCause() instanceof DashboardStructureException) {
          JsonUtils.buildJsonResult(response.getOutputStream(), false, e.getCause().getMessage());
        } else if (e instanceof InvocationTargetException) {
          throw (Exception) e.getCause();
        }
      }
      throw e;
    }
  }