html页面代码结合Java加密,关于springframework框架spring-web包HtmlUtils页面工具类进行字符串加密解密htmlEscape/htmlUnescape等处理源码说明...

一、前言

关于springframework框架spring-web包(4.1.4)的org.springframework.web.util.HtmlUtils页面工具类,进行对html字符串进行加密htmlEscape伪码、对加密html字符串进行解密htmlUnescape等处理。

二、源码说明

1. HtmlUtils类package org.springframework.web.util;@b@@b@import org.springframework.util.Assert;@b@@b@public abstract class HtmlUtils@b@{@b@  private static final HtmlCharacterEntityReferences characterEntityReferences = new HtmlCharacterEntityReferences();@b@@b@  public static String htmlEscape(String input)@b@  {@b@    return htmlEscape(input, "ISO-8859-1");@b@  }@b@@b@  public static String htmlEscape(String input, String encoding)@b@  {@b@    Assert.notNull(encoding, "Encoding is required");@b@    if (input == null)@b@      return null;@b@@b@    StringBuilder escaped = new StringBuilder(input.length() * 2);@b@    for (int i = 0; i 

2.HtmlCharacterEntityReferences、HtmlCharacterEntityDecoder类package org.springframework.web.util;@b@@b@import java.io.IOException;@b@import java.io.InputStream;@b@import java.util.Enumeration;@b@import java.util.HashMap;@b@import java.util.Map;@b@import java.util.Properties;@b@import org.springframework.util.Assert;@b@@b@class HtmlCharacterEntityReferences@b@{@b@  private static final String PROPERTIES_FILE = "HtmlCharacterEntityReferences.properties";@b@  static final char REFERENCE_START = 38;@b@  static final String DECIMAL_REFERENCE_START = "";@b@  static final String HEX_REFERENCE_START = "";@b@  static final char REFERENCE_END = 59;@b@  static final char CHAR_NULL = 65535;@b@  private final String[] characterToEntityReferenceMap = new String[3000];@b@  private final Map entityReferenceToCharacterMap = new HashMap(252);@b@@b@  public HtmlCharacterEntityReferences()@b@  {@b@    Properties entityReferences = new Properties();@b@@b@    InputStream is = HtmlCharacterEntityReferences.class.getResourceAsStream("HtmlCharacterEntityReferences.properties");@b@    if (is == null)@b@      throw new IllegalStateException("Cannot find reference definition file [HtmlCharacterEntityReferences.properties] as class path resource");@b@    try@b@    {@b@      try@b@      {@b@        entityReferences.load(is);@b@@b@        is.close(); } finally { is.close();@b@      }@b@    }@b@    catch (IOException ex)@b@    {@b@      throw new IllegalStateException("Failed to parse reference definition file [HtmlCharacterEntityReferences.properties]: " + ex@b@        .getMessage());@b@    }@b@@b@    Enumeration keys = entityReferences.propertyNames();@b@    while (keys.hasMoreElements()) {@b@      String key = (String)keys.nextElement();@b@      int referredChar = Integer.parseInt(key);@b@      Assert.isTrue(((referredChar = 8000) && (referredChar ':@b@        return ">";@b@      case '"':@b@        return """;@b@      case '&':@b@        return "&";@b@      case '\'':@b@        return "'";@b@      }@b@    }@b@    else if ((character = 8000) && (character  3) {@b@        this.decodedMessage.append(this.originalMessage.substring(this.currentPosition, skipUntilIndex));@b@        this.currentPosition = skipUntilIndex;@b@      }@b@      else {@b@        while (this.currentPosition 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值