Ejemplo n.º 1
0
  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));
      }
    }
  }
Ejemplo n.º 2
0
  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"));
    }
  }