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 String replaceParameters(String text, ArrayList<String> i18nTagsList) throws Exception {

    if (i18nTagsList == null) {
      i18nTagsList = new ArrayList<String>();
    }

    saveI18NMessageFilesToCache();

    // If dashboard specific files aren't specified set message filename in cache to the global
    // messages file filename
    String dashboardsMessagesBaseFilename =
        sourceDashboardBaseMsgFile != null
            ? FilenameUtils.getBaseName(sourceDashboardBaseMsgFile.getName())
            : BASE_GLOBAL_MESSAGE_SET_FILENAME;

    text =
        text.replaceAll(
            "\\{load\\}", "onload=\"load()\""); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    text = text.replaceAll("\\{body-tag-unload\\}", ""); // $NON-NLS-1$
    text =
        text.replaceAll(
            "#\\{GLOBAL_MESSAGE_SET_NAME\\}", dashboardsMessagesBaseFilename); // $NON-NLS-1$
    text =
        text.replaceAll("#\\{GLOBAL_MESSAGE_SET_PATH\\}", getMessageFilesCacheUrl()); // $NON-NLS-1$
    text =
        text.replaceAll(
            "#\\{GLOBAL_MESSAGE_SET\\}", buildMessageSetCode(i18nTagsList)); // $NON-NLS-1$
    text =
        text.replaceAll(
            "#\\{LANGUAGE_CODE\\}", CdeEngine.getEnv().getLocale().getLanguage()); // $NON-NLS-1$
    return text;
  }
Ejemplo n.º 3
0
  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);
  }
Ejemplo n.º 4
0
 // useful to mock the resource endpoint when unit testing CdfTemplates
 protected String getResourceUrl(String resourceEndpoint) {
   return CdeEngine.getInstance().getEnvironment().getApplicationBaseContentUrl()
       + resourceEndpoint
       + SYSTEM_CDF_DD_TEMPLATES
       + "/";
 }