Beispiel #1
0
  public static void setLocale(String locale) {
    if (locale == null || "".equals(locale.trim())) {
      return;
    }
    Localizer localizer = Localization.getGlobalLocalizerAdvanced();
    log.info("Setting locale to : " + locale + " available: " + localizer.getAvailableLocales());
    for (String availabile : localizer.getAvailableLocales()) {
      if (locale.equals(availabile)) {
        localizer.setLocale(locale);

        return;
      }
    }
  }
Beispiel #2
0
  public String fillTemplateString(
      String template, TreeReference contextRef, Hashtable<String, ?> variables) {
    Hashtable args = new Hashtable();

    int depth = 0;
    Vector outstandingArgs = Localizer.getArgs(template);
    while (outstandingArgs.size() > 0) {
      for (int i = 0; i < outstandingArgs.size(); i++) {
        String argName = (String) outstandingArgs.elementAt(i);
        if (!args.containsKey(argName)) {
          int ix = -1;
          try {
            ix = Integer.parseInt(argName);
          } catch (NumberFormatException nfe) {
            System.err.println("Warning: expect arguments to be numeric [" + argName + "]");
          }

          if (ix < 0 || ix >= outputFragments.size()) continue;

          IConditionExpr expr = (IConditionExpr) outputFragments.elementAt(ix);
          EvaluationContext ec = new EvaluationContext(exprEvalContext, contextRef);
          ec.setVariables(variables);
          String value = expr.evalReadable(this.getInstance(), ec);
          args.put(argName, value);
        }
      }

      template = Localizer.processArguments(template, args);
      outstandingArgs = Localizer.getArgs(template);

      depth++;
      if (depth >= TEMPLATING_RECURSION_LIMIT) {
        throw new RuntimeException("Dependency cycle in <output>s; recursion limit exceeded!!");
      }
    }

    return template;
  }