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

net.pms.util.StringUtil Maven / Gradle / Ivy

Go to download

PS3 Media Server is a cross-platform DLNA-compliant UPnP Media Server. Originally written to support the PlayStation 3, PS3 Media Server has been expanded to support a range of other media renderers, including smartphones, televisions, music players and more.

The newest version!
package net.pms.util;

public class StringUtil {
	/**Appends "<tag " to the StringBuilder. This is a typical HTML/DIDL/XML tag opening.
	 * @param sb String to append the tag beginning to.
	 * @param tag String that represents the tag
	 */
	public static void openTag(StringBuilder sb, String tag) {
		sb.append("<");
		sb.append(tag);
	}

	/**Appends the closing symbol > to the StringBuilder. This is a typical HTML/DIDL/XML tag closing.
	 * @param sb String to append the ending character of a tag.
	 */
	public static void endTag(StringBuilder sb) {
		sb.append(">");
	}

	/**Appends "</tag>" to the StringBuilder. This is a typical closing HTML/DIDL/XML tag.
	 * @param sb
	 * @param tag
	 */
	public static void closeTag(StringBuilder sb, String tag) {
		sb.append("</");
		sb.append(tag);
		sb.append(">");
	}

	public static void addAttribute(StringBuilder sb, String attribute, Object value) {
		sb.append(" ");
		sb.append(attribute);
		sb.append("=\"");
		sb.append(value);
		sb.append("\"");
	}

	public static void addXMLTagAndAttribute(StringBuilder sb, String tag, Object value) {
		sb.append("<");
		sb.append(tag);
		sb.append(">");
		sb.append(value);
		sb.append("</");
		sb.append(tag);
		sb.append(">");
	}

	/**Does basic transformations between characters and their HTML representation with ampersands.
	 * @param s String to be encoded
	 * @return Encoded String
	 */
	public static String encodeXML(String s) {

		s = s.replace("&", "&");
		s = s.replace("<", "<");
		s = s.replace(">", ">");
		s = s.replace("\"", """);
		s = s.replace("'", "'");
		s = s.replace("&", "&");

		return s;
	}

	/**Converts an URL string to it more canonical form
	 * @param url String to be converted
	 * @return Converted String.
	 */
	public static String convertURLToFileName(String url) {
		url = url.replace('/', '\u00b5');
		url = url.replace('\\', '\u00b5');
		url = url.replace(':', '\u00b5');
		url = url.replace('?', '\u00b5');
		url = url.replace('*', '\u00b5');
		url = url.replace('|', '\u00b5');
		url = url.replace('<', '\u00b5');
		url = url.replace('>', '\u00b5');
		return url;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy