Beispiel #1
0
 /**
  * Replaces parameters in the string with values specified.
  *
  * <p>
  *
  * <p>For example a string like 'My name is &lt;name&gt;' and you provide {@code Param.P("name",
  * "rojoss")} it would return 'My name is rojoss' <b>Notice how there is no &lt; and &gt; sign
  * around the parameter name for {@link Param}!</b> If the message doesn't have parameters
  * specified nothing will happen.
  *
  * <p>
  *
  * <p><b>No need to call this for messages from {@link Msg#get(String, Param...)} as that already
  * replaces the specified params using this method</b>
  *
  * <p>It does not affect JSON messages unless used before parsing to JSON.
  *
  * <p>
  *
  * <p>It supports capitalization for parameters too. For example if you put &lt;Name&gt; it would
  * be replaced with Rojoss and if you put &lt;NAME&gt; it would be ROJOSS. Lowercase parameter
  * names will use the value provided in the parameter. The parameter can be prefixed with a
  * underscore to force the value lowercase like &lt;_name&gt;
  *
  * @param params The list of parameters to replace. The &lt;p&gt; parameter is reserved and this
  *     gets replaced with global prefix.
  * @return This msg instance.
  * @see Param
  */
 public Msg params(Param... params) {
   if (!message.contains(Character.toString(PARAM_OPEN))
       || !message.contains(Character.toString(PARAM_CLOSE))) {
     return this;
   }
   if (message == null) {
     message = original;
   }
   for (Param param : params) {
     message =
         message.replace(
             PARAM_OPEN + param.getParam().toLowerCase() + PARAM_CLOSE, param.toString());
     message =
         message.replace(
             PARAM_OPEN + "_" + param.getParam().toLowerCase() + PARAM_CLOSE,
             param.toString().toLowerCase());
     message =
         message.replace(
             PARAM_OPEN + param.getParam().toUpperCase() + PARAM_CLOSE,
             param.toString().toUpperCase());
     message =
         message.replace(
             PARAM_OPEN + Str.capitalize(param.getParam().toLowerCase()) + PARAM_CLOSE,
             Str.capitalize(param.toString()));
   }
   message = message.replace("<p>", Msg.getRaw("prefix").message);
   return this;
 }
Beispiel #2
0
 /**
  * Capitalize the first letter of the message.
  *
  * <p>Uses {@link Str#capitalize(String)}
  *
  * @return This msg instance.
  */
 public Msg capitalize() {
   message = Str.capitalize(message);
   return this;
 }