All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.andriykuba.play.handlebars.helpers.StringHelpers Maven / Gradle / Ivy

Go to download

Handlebars templates based on Java port of handlebars with special handlers for Play Framework

There is a newer version: 2.6.7
Show newest version
package com.github.andriykuba.play.handlebars.helpers;

import java.net.URLEncoder;

/**
 * Helpers for work with strings.
 *
 */
public final class StringHelpers {
	  
  /**
   * Encode the given string so it could be used in the URL as parameter.
   * There is {@link java.net.URLEncoder#encode java.net.URLEncoder.encode} under the hood.
   * 
   * @param parameter
   * 	string that will be encoded.
   * @return
   * 	encoded string.  
   * @throws Exception
   * 	exception in the case of unable to encode.
   */
  public static CharSequence encodeUrlParameter(final Object parameter) throws Exception{
    if(parameter == null) return "";
    return URLEncoder.encode(parameter.toString(), "UTF-8");
  }
  
  /**
   * Returns value if obj1 and obj2 are equals
   * 
   * @param obj1
   * 	Object pretend to be a string.
   * @param obj2
   * 	Object pretend to be a string.
   * @param value
   * 	String representation of this object would be returned if {@code obj1} equals {@code obj2}
   * @return
   * 	{@code value} as string or an empty string.
   */
  public static CharSequence if_equals(final Object obj1, final Object obj2, final Object value){
    if(obj1 == null) {
    	return obj2 == null ? value.toString() : "";
    } 
    return obj1.equals(obj2) ? value.toString() : "";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy