/** * Encodes the specified text, escaping certain characters into character references. * <p> * This is equivalent to {@link #encode(CharSequence,boolean) encode(unencodedText,true)}. * * @param unencodedText the text to encode. * @return the encoded string. */ public static String encode(final CharSequence unencodedText) { return encode(unencodedText,true); }
/** * Re-encodes the specified text, equivalent to {@linkplain #decode(CharSequence) decoding} and then {@linkplain #encode(CharSequence) encoding} again. * <p> * This process ensures that the specified encoded text does not contain any remaining unencoded characters. * <p> * IMPLEMENTATION NOTE: At present this method simply calls the {@link #decode(CharSequence) decode} method followed by the * {@link #encode(CharSequence) encode} method, both with <code>insideAttributeValue</code> set to <code>true</code>. * * @param encodedText the text to re-encode. * @return the re-encoded string. */ public static String reencode(final CharSequence encodedText) { return encode(decode(encodedText,true),true); }
@RequestMapping(value = { "/user/edit/emailAddresses" }, method = RequestMethod.GET) public ModelAndView handleEmailAddresses(@RequestParam(value = "newEmail", required=false) String email) { UserProfile userProfile = this.userBusinessService.getCurrentUserProfile(); Map<String, Object> model = getSynchronizedEmailAddressesModel(userProfile); model.put("newEmail", CharacterReference.encode(email)); return new ModelAndView(USER_EMAIL_ADRESSES_EDIT, model); }
private CharSequence getStartTagHTML(StartTag startTag) { // tidies and filters out non-approved attributes StringBuilder sb = new StringBuilder(); sb.append('<').append(startTag.getName()); for (Attribute attribute : startTag.getAttributes()) { if (allowedAttributes.contains(attribute.getKey().toLowerCase())) { sb.append(' ').append(attribute.getName()); if (attribute.getValue() != null) { sb.append("=\""); sb.append(CharacterReference.encode(attribute.getValue())); sb.append('"'); } } } if (startTag.getElement().getEndTag() == null && !HTMLElements.getEndTagOptionalElementNames().contains(startTag.getName())) { sb.append(" /"); } sb.append('>'); return sb; }
private void reencodeTextSegment(Source source, OutputDocument outputDocument, int begin, int end) { if (begin >= end) { return; } Segment textSegment = new Segment(source, begin, end); String decodedText = CharacterReference.decode(textSegment); String encodedText = CharacterReference.encode(decodedText); outputDocument.replace(textSegment, encodedText); }
void replaceInOutputDocument(final OutputDocument outputDocument) { if (outputStyle==FormControlOutputStyle.REMOVE) { outputDocument.remove(getElement()); } else if (outputStyle==FormControlOutputStyle.DISPLAY_VALUE) { outputDocument.replace(getElement(),getDisplayValueHTML(getValue(),true)); } else { replaceAttributesInOutputDocumentIfModified(outputDocument); if (value!=UNCHANGED) outputDocument.replace(getElement().getContent(),CharacterReference.encode(value,false)); } } private String getValue() {