Here you can find the source of forHTMLTag(String aTagFragment)
public static final String forHTMLTag(String aTagFragment)
//package com.java2s; /*/*from w w w .jav a 2 s . c o m*/ * Spirit, a study/biosample management tool for research. * Copyright (C) 2018 Idorsia Pharmaceuticals Ltd., Hegenheimermattweg 91, * CH-4123 Allschwil, Switzerland. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/> * * @author Joel Freyss */ import java.text.*; public class Main { /** * Replace characters having special meaning <em>inside</em> HTML tags * with their escaped equivalents, using character entities such as <tt>'&'</tt>. * * <P>The escaped characters are : * <ul> * <li> < * <li> > * <li> " * <li> ' * <li> \ * <li> & * </ul> * * <P>This method ensures that arbitrary text appearing inside a tag does not "confuse" * the tag. For example, <tt>HREF='Blah.do?Page=1&Sort=ASC'</tt> * does not comply with strict HTML because of the ampersand, and should be changed to * <tt>HREF='Blah.do?Page=1&Sort=ASC'</tt>. This is commonly seen in building * query strings. (In JSTL, the c:url tag performs this task automatically.) */ public static final String forHTMLTag(String aTagFragment) { final StringBuffer result = new StringBuffer(); final StringCharacterIterator iterator = new StringCharacterIterator(aTagFragment); char character = iterator.current(); while (character != CharacterIterator.DONE) { if (character == '<') { result.append("<"); } else if (character == '>') { result.append(">"); } else if (character == '\"') { result.append("""); } else if (character == '\'') { result.append("'"); } else if (character == '\\') { result.append("\"); } else if (character == '&') { result.append("&"); } else { //the char is not a special one //add it to the result as is result.append(character); } character = iterator.next(); } return result.toString(); } }