java对html转移的语言反编译-org.apache.commons.lang3包有个StringEscapeUtils

本文主要是介绍java对html转移的语言反编译-org.apache.commons.lang3包有个StringEscapeUtils,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

StringEscapeUtils


用escapeJava方法转义

用unescapeJava方法反转义

用escapeHtml方法转义

用unescapeHtml方法反转义

用escapeXml方法转义

用unescapeXml方法反转义

用escapeJavaScript方法转义

用unescapeJavaScript方法反转义

源码内容方法

/** Licensed to the Apache Software Foundation (ASF) under one or more* contributor license agreements.  See the NOTICE file distributed with* this work for additional information regarding copyright ownership.* The ASF licenses this file to You under the Apache License, Version 2.0* (the "License"); you may not use this file except in compliance with* the License.  You may obtain a copy of the License at* *      http://www.apache.org/licenses/LICENSE-2.0* * Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/
package org.apache.commons.lang3;import java.io.IOException;
import java.io.Writer;import org.apache.commons.lang3.text.translate.AggregateTranslator;
import org.apache.commons.lang3.text.translate.CharSequenceTranslator;
import org.apache.commons.lang3.text.translate.EntityArrays;
import org.apache.commons.lang3.text.translate.LookupTranslator;
import org.apache.commons.lang3.text.translate.NumericEntityUnescaper;
import org.apache.commons.lang3.text.translate.OctalUnescaper;
import org.apache.commons.lang3.text.translate.UnicodeEscaper;
import org.apache.commons.lang3.text.translate.UnicodeUnescaper;/*** <p>Escapes and unescapes {@code String}s for* Java, Java Script, HTML and XML.</p>** <p>#ThreadSafe#</p>* @since 2.0* @version $Id: StringEscapeUtils.java 1148520 2011-07-19 20:53:23Z ggregory $*/
public class StringEscapeUtils {/* ESCAPE TRANSLATORS */public static final CharSequenceTranslator ESCAPE_JAVA = new LookupTranslator(new String[][] { {"\"", "\\\""},{"\\", "\\\\"},}).with(new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE())).with(UnicodeEscaper.outsideOf(32, 0x7f) );public static final CharSequenceTranslator ESCAPE_ECMASCRIPT = new AggregateTranslator(new LookupTranslator(new String[][] { {"'", "\\'"},{"\"", "\\\""},{"\\", "\\\\"},{"/", "\\/"}}),new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_ESCAPE()),UnicodeEscaper.outsideOf(32, 0x7f) );public static final CharSequenceTranslator ESCAPE_XML = new AggregateTranslator(new LookupTranslator(EntityArrays.BASIC_ESCAPE()),new LookupTranslator(EntityArrays.APOS_ESCAPE()));public static final CharSequenceTranslator ESCAPE_HTML3 = new AggregateTranslator(new LookupTranslator(EntityArrays.BASIC_ESCAPE()),new LookupTranslator(EntityArrays.ISO8859_1_ESCAPE()));public static final CharSequenceTranslator ESCAPE_HTML4 = new AggregateTranslator(new LookupTranslator(EntityArrays.BASIC_ESCAPE()),new LookupTranslator(EntityArrays.ISO8859_1_ESCAPE()),new LookupTranslator(EntityArrays.HTML40_EXTENDED_ESCAPE()));public static final CharSequenceTranslator ESCAPE_CSV = new CsvEscaper();// TODO: Create a parent class - 'SinglePassTranslator' ?//       It would handle the index checking + length returning, //       and could also have an optimization check method.static class CsvEscaper extends CharSequenceTranslator {private static final char CSV_DELIMITER = ',';private static final char CSV_QUOTE = '"';private static final String CSV_QUOTE_STR = String.valueOf(CSV_QUOTE);private static final char[] CSV_SEARCH_CHARS = new char[] {CSV_DELIMITER, CSV_QUOTE, CharUtils.CR, CharUtils.LF};@Overridepublic int translate(CharSequence input, int index, Writer out) throws IOException {if(index != 0) {throw new IllegalStateException("CsvEscaper should never reach the [1] index");}if (StringUtils.containsNone(input.toString(), CSV_SEARCH_CHARS)) {out.write(input.toString());} else {out.write(CSV_QUOTE);out.write(StringUtils.replace(input.toString(), CSV_QUOTE_STR, CSV_QUOTE_STR + CSV_QUOTE_STR));out.write(CSV_QUOTE);}return input.length();}}/* UNESCAPE TRANSLATORS */// TODO: throw "illegal character: \92" as an Exception if a \ on the end of the Java (as per the compiler)?public static final CharSequenceTranslator UNESCAPE_JAVA = new AggregateTranslator(new OctalUnescaper(),     // .between('\1', '\377'),new UnicodeUnescaper(),new LookupTranslator(EntityArrays.JAVA_CTRL_CHARS_UNESCAPE()),new LookupTranslator(new String[][] { {"\\\\", "\\"},{"\\\"", "\""},{"\\'", "'"},{"\\", ""}}));public static final CharSequenceTranslator UNESCAPE_ECMASCRIPT = UNESCAPE_JAVA;public static final CharSequenceTranslator UNESCAPE_HTML3 = new AggregateTranslator(new LookupTranslator(EntityArrays.BASIC_UNESCAPE()),new LookupTranslator(EntityArrays.ISO8859_1_UNESCAPE()),new NumericEntityUnescaper());public static final CharSequenceTranslator UNESCAPE_HTML4 = new AggregateTranslator(new LookupTranslator(EntityArrays.BASIC_UNESCAPE()),new LookupTranslator(EntityArrays.ISO8859_1_UNESCAPE()),new LookupTranslator(EntityArrays.HTML40_EXTENDED_UNESCAPE()),new NumericEntityUnescaper());public static final CharSequenceTranslator UNESCAPE_XML = new AggregateTranslator(new LookupTranslator(EntityArrays.BASIC_UNESCAPE()),new LookupTranslator(EntityArrays.APOS_UNESCAPE()),new NumericEntityUnescaper());public static final CharSequenceTranslator UNESCAPE_CSV = new CsvUnescaper();static class CsvUnescaper extends CharSequenceTranslator {private static final char CSV_DELIMITER = ',';private static final char CSV_QUOTE = '"';private static final String CSV_QUOTE_STR = String.valueOf(CSV_QUOTE);private static final char[] CSV_SEARCH_CHARS = new char[] {CSV_DELIMITER, CSV_QUOTE, CharUtils.CR, CharUtils.LF};@Overridepublic int translate(CharSequence input, int index, Writer out) throws IOException {if(index != 0) {throw new IllegalStateException("CsvUnescaper should never reach the [1] index");}if ( input.charAt(0) != CSV_QUOTE || input.charAt(input.length() - 1) != CSV_QUOTE ) {out.write(input.toString());return input.length();}// strip quotesString quoteless = input.subSequence(1, input.length() - 1).toString();if ( StringUtils.containsAny(quoteless, CSV_SEARCH_CHARS) ) {// deal with escaped quotes; ie) ""out.write(StringUtils.replace(quoteless, CSV_QUOTE_STR + CSV_QUOTE_STR, CSV_QUOTE_STR));} else {out.write(input.toString());}return input.length();}}public StringEscapeUtils() {super();}public static final String escapeJava(String input) {return ESCAPE_JAVA.translate(input);}public static final String escapeEcmaScript(String input) {return ESCAPE_ECMASCRIPT.translate(input);}public static final String unescapeJava(String input) {return UNESCAPE_JAVA.translate(input);}public static final String unescapeEcmaScript(String input) {return UNESCAPE_ECMASCRIPT.translate(input);}public static final String escapeHtml4(String input) {return ESCAPE_HTML4.translate(input);}public static final String escapeHtml3(String input) {return ESCAPE_HTML3.translate(input);}public static final String unescapeHtml4(String input) {return UNESCAPE_HTML4.translate(input);}public static final String unescapeHtml3(String input) {return UNESCAPE_HTML3.translate(input);}public static final String escapeXml(String input) {return ESCAPE_XML.translate(input);}public static final String unescapeXml(String input) {return UNESCAPE_XML.translate(input);}//-----------------------------------------------------------------------public static final String escapeCsv(String input) {return ESCAPE_CSV.translate(input);}public static final String unescapeCsv(String input) {return UNESCAPE_CSV.translate(input);}}

针对转译,尽量不要进行转译后入库,只做查询出特殊字符的转译,或者自己写具体字符的转译,防止转译编码等导致字符混乱


这篇关于java对html转移的语言反编译-org.apache.commons.lang3包有个StringEscapeUtils的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/387642

相关文章

Python将博客内容html导出为Markdown格式

《Python将博客内容html导出为Markdown格式》Python将博客内容html导出为Markdown格式,通过博客url地址抓取文章,分析并提取出文章标题和内容,将内容构建成html,再转... 目录一、为什么要搞?二、准备如何搞?三、说搞咱就搞!抓取文章提取内容构建html转存markdown

在React中引入Tailwind CSS的完整指南

《在React中引入TailwindCSS的完整指南》在现代前端开发中,使用UI库可以显著提高开发效率,TailwindCSS是一个功能类优先的CSS框架,本文将详细介绍如何在Reac... 目录前言一、Tailwind css 简介二、创建 React 项目使用 Create React App 创建项目

vue使用docxtemplater导出word

《vue使用docxtemplater导出word》docxtemplater是一种邮件合并工具,以编程方式使用并处理条件、循环,并且可以扩展以插入任何内容,下面我们来看看如何使用docxtempl... 目录docxtemplatervue使用docxtemplater导出word安装常用语法 封装导出方

Java编译生成多个.class文件的原理和作用

《Java编译生成多个.class文件的原理和作用》作为一名经验丰富的开发者,在Java项目中执行编译后,可能会发现一个.java源文件有时会产生多个.class文件,从技术实现层面详细剖析这一现象... 目录一、内部类机制与.class文件生成成员内部类(常规内部类)局部内部类(方法内部类)匿名内部类二、

SpringBoot实现数据库读写分离的3种方法小结

《SpringBoot实现数据库读写分离的3种方法小结》为了提高系统的读写性能和可用性,读写分离是一种经典的数据库架构模式,在SpringBoot应用中,有多种方式可以实现数据库读写分离,本文将介绍三... 目录一、数据库读写分离概述二、方案一:基于AbstractRoutingDataSource实现动态

Springboot @Autowired和@Resource的区别解析

《Springboot@Autowired和@Resource的区别解析》@Resource是JDK提供的注解,只是Spring在实现上提供了这个注解的功能支持,本文给大家介绍Springboot@... 目录【一】定义【1】@Autowired【2】@Resource【二】区别【1】包含的属性不同【2】@

springboot循环依赖问题案例代码及解决办法

《springboot循环依赖问题案例代码及解决办法》在SpringBoot中,如果两个或多个Bean之间存在循环依赖(即BeanA依赖BeanB,而BeanB又依赖BeanA),会导致Spring的... 目录1. 什么是循环依赖?2. 循环依赖的场景案例3. 解决循环依赖的常见方法方法 1:使用 @La

Java枚举类实现Key-Value映射的多种实现方式

《Java枚举类实现Key-Value映射的多种实现方式》在Java开发中,枚举(Enum)是一种特殊的类,本文将详细介绍Java枚举类实现key-value映射的多种方式,有需要的小伙伴可以根据需要... 目录前言一、基础实现方式1.1 为枚举添加属性和构造方法二、http://www.cppcns.co

Elasticsearch 在 Java 中的使用教程

《Elasticsearch在Java中的使用教程》Elasticsearch是一个分布式搜索和分析引擎,基于ApacheLucene构建,能够实现实时数据的存储、搜索、和分析,它广泛应用于全文... 目录1. Elasticsearch 简介2. 环境准备2.1 安装 Elasticsearch2.2 J

Java中的String.valueOf()和toString()方法区别小结

《Java中的String.valueOf()和toString()方法区别小结》字符串操作是开发者日常编程任务中不可或缺的一部分,转换为字符串是一种常见需求,其中最常见的就是String.value... 目录String.valueOf()方法方法定义方法实现使用示例使用场景toString()方法方法