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

相关文章

Java实现Excel与HTML互转

《Java实现Excel与HTML互转》Excel是一种电子表格格式,而HTM则是一种用于创建网页的标记语言,虽然两者在用途上存在差异,但有时我们需要将数据从一种格式转换为另一种格式,下面我们就来看看... Excel是一种电子表格格式,广泛用于数据处理和分析,而HTM则是一种用于创建网页的标记语言。虽然两

java图像识别工具类(ImageRecognitionUtils)使用实例详解

《java图像识别工具类(ImageRecognitionUtils)使用实例详解》:本文主要介绍如何在Java中使用OpenCV进行图像识别,包括图像加载、预处理、分类、人脸检测和特征提取等步骤... 目录前言1. 图像识别的背景与作用2. 设计目标3. 项目依赖4. 设计与实现 ImageRecogni

Java中Springboot集成Kafka实现消息发送和接收功能

《Java中Springboot集成Kafka实现消息发送和接收功能》Kafka是一个高吞吐量的分布式发布-订阅消息系统,主要用于处理大规模数据流,它由生产者、消费者、主题、分区和代理等组件构成,Ka... 目录一、Kafka 简介二、Kafka 功能三、POM依赖四、配置文件五、生产者六、消费者一、Kaf

Java访问修饰符public、private、protected及默认访问权限详解

《Java访问修饰符public、private、protected及默认访问权限详解》:本文主要介绍Java访问修饰符public、private、protected及默认访问权限的相关资料,每... 目录前言1. public 访问修饰符特点:示例:适用场景:2. private 访问修饰符特点:示例:

Window Server创建2台服务器的故障转移群集的图文教程

《WindowServer创建2台服务器的故障转移群集的图文教程》本文主要介绍了在WindowsServer系统上创建一个包含两台成员服务器的故障转移群集,文中通过图文示例介绍的非常详细,对大家的... 目录一、 准备条件二、在ServerB安装故障转移群集三、在ServerC安装故障转移群集,操作与Ser

详解Java如何向http/https接口发出请求

《详解Java如何向http/https接口发出请求》这篇文章主要为大家详细介绍了Java如何实现向http/https接口发出请求,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 用Java发送web请求所用到的包都在java.net下,在具体使用时可以用如下代码,你可以把它封装成一

windos server2022的配置故障转移服务的图文教程

《windosserver2022的配置故障转移服务的图文教程》本文主要介绍了windosserver2022的配置故障转移服务的图文教程,以确保服务和应用程序的连续性和可用性,文中通过图文介绍的非... 目录准备环境:步骤故障转移群集是 Windows Server 2022 中提供的一种功能,用于在多个

SpringBoot使用Apache Tika检测敏感信息

《SpringBoot使用ApacheTika检测敏感信息》ApacheTika是一个功能强大的内容分析工具,它能够从多种文件格式中提取文本、元数据以及其他结构化信息,下面我们来看看如何使用Ap... 目录Tika 主要特性1. 多格式支持2. 自动文件类型检测3. 文本和元数据提取4. 支持 OCR(光学

Java内存泄漏问题的排查、优化与最佳实践

《Java内存泄漏问题的排查、优化与最佳实践》在Java开发中,内存泄漏是一个常见且令人头疼的问题,内存泄漏指的是程序在运行过程中,已经不再使用的对象没有被及时释放,从而导致内存占用不断增加,最终... 目录引言1. 什么是内存泄漏?常见的内存泄漏情况2. 如何排查 Java 中的内存泄漏?2.1 使用 J

JAVA系统中Spring Boot应用程序的配置文件application.yml使用详解

《JAVA系统中SpringBoot应用程序的配置文件application.yml使用详解》:本文主要介绍JAVA系统中SpringBoot应用程序的配置文件application.yml的... 目录文件路径文件内容解释1. Server 配置2. Spring 配置3. Logging 配置4. Ma