方法:
public static String convertHtmlEntities(String htmlString) throws UnsupportedEncodingException{
String result = null;
Tidy tidy = new Tidy();
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setPrintBodyOnly(false); // only print the content
tidy.setXmlOut(true); // to XML
tidy.setSmartIndent(true);
ByteArrayInputStream inputStream = new ByteArrayInputStream(htmlString.getBytes("UTF-8"));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
tidy.parseDOM(inputStream, outputStream);
result = outputStream.toString("UTF-8");
return result;
}
通过 htmlString 作为参数输入的内容:
"<#macro print_bono voucher>
<div id="content">
<div class="icn_fold2"><div class="text"></div></div>
<div id="area1">
<div id="bg1">
<p class="barcode"><img src="${voucher.barcode}" alt="${voucher.numberCode}" /></p>
<div class="title">
<h1>Ésta es tu entrada</h1>
<p class="note"><strong>IMPORTANTE:</strong> Para acceder al recinto hay que presentar esta hoja entera</p>
</div>
<div class="services_bg">
<p class="logo_fcb"><img src="http://evo.cdnstc.com/static/images/bono_ds/logos_fcb.gif" alt="FCB, LFP" /></p>
<div class="service">
<table width="260">
<tr>
<td width="85"><strong>Jornada:</strong></td>
<td width="45">${voucher.jornada}</td>
<td width="85"><strong>Temporada:</strong></td>
<td width="45">${temporada}</td>
</tr>
<tr>
<td width="85" colspan="2"><strong>Fecha*:</strong></td>
<td colspan="2">${voucher.serviceDate}</td>
</tr>
<tr>
<td width="85" colspan="2"><strong>Partido:</strong></td>
<td colspan="2">${voucher.match}</td>
</tr>
<tr>
<td colspan="4"><strong>*</strong> <i>Se recomienda verificar la fecha y hora del partido en <span>www.fcbarcelona.cat</span></i></td>
</tr>
</table>
<table>
<tr>
<td width="130" colspan="2"><strong>Zona:</strong></td>
<td colspan="2">${voucher.zoneDescription}</td>
</tr>
<tr>
<td width="130" colspan="2"><strong>Acceso recomendado:</strong></td>
<td colspan="2">${voucher.access}</td>
</tr>
<tr>
<td width="85"><strong>Puerta:</strong></td>
<td>${voucher.entranceDoor}</td>
<td width="85"><strong>Boca:</strong></td>
<td>${voucher.gate}</td>
</tr>
<tr>
<td width="85"><strong>Fila:</strong></td>
<td>${voucher.row}</td>
<td width="85"><strong>Asiento:</strong></td>
<td>${voucher.seat}</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr class="price">
<td width="130" colspan="2"><strong>Precio:</strong></td>
<td colspan="2"><span>10.080 EUR €</span></td>
</tr>
</table>
</div>
</div>
<div class="logo_hex">
<p>CIF:G08266298</p>
<img src="http://evo.cdnstc.com/static/images/bono_ds/logo_hotelextras.gif" alt="hotelextras" />
</div>
</div>
</div>
<div id="area2">
<div id="bg2">
<h1>Cómo llegar</h1>
<p class="map"><img src="http://evo.cdnstc.com/static/images/bono_ds/img_mapa.gif" alt="" /></p>
<p class="logos_pie"><img src="http://evo.cdnstc.com/static/images/bono_ds/logos_pie.gif" alt="" /></p>
</div>
</div>
<div class="icn_fold1"><div class="text"></div></div>
<div id="area3">
<div id="bg3">
<div id="banner-content">
<div class="banner">
<img src="http://evo.cdnstc.com/static/images/bono_ds/banner.jpg" alt="" />
<img src="http://evo.cdnstc.com/static/images/bono_ds/logo_sensefum.gif" alt="" style="width: 100%; margin-left: 15px;"/>
<span class="publi">publicitat</span>
</div>
</div>
</div>
</div>
<div id="area4">
<div id="bg4">
<p class="note"><strong>IMPORTANTE:</strong> Para acceder al recinto hay que presentar esta hoja entera</p>
<div class="info">
<ul class="instructions">
<li><strong>Prohibida la reproducción total o parcial de este documento.</strong><br />El FCBarcelona se reserva el derecho de denegar el acceso al recinto en caso de que se detecte la posible duplicación de esta entrada. El titular de la compra se responsabiliza del buen uso de esta entrada.</li>
<li><strong class="txt_rose">Para validar la entrada en el mecanismo de control, hay que doblarla como indicamos:</strong><img src="http://evo.cdnstc.com/static/images/bono_ds/img_pliegue.gif" alt="" /></li>
</ul>
<p class="attention"><strong>ATENCIÓN:</strong> Si alguien te ofrece venderte esta entrada no la aceptes. No tendría ningún valor oficial y, por lo tanto, sería una copia no autorizada.</p>
<h2>Instrucciones y condiciones importantes</h2>
<p>La tenencia y/o uso de esta entrada significa la aceptación expresa de todos los términos y condiciones asociados a la entrada y ratificados durante el proceso de compra. En caso de duda, consulta de nuevo las condiciones en <strong>www.fcbarcelona.cat</strong></p>
<ul class="list1">
<li><strong>El código de barras de esta entrada permite el acceso al recinto sólo una vez.</strong> Cualquier duplicado de la misma, bajo ningún concepto, podrá dar acceso al recinto.</li>
<li>En caso de que aparezcan copias duplicadas, el FCBarcelona adoptar� las medidas oportunas, <strong>denegando el acceso al recinto.</strong></li>
<li>
Reglamento para la prevención de la violencia en espectáculos deportivos. <strong>Causas que impiden el acceso al recinto:</strong>
<ul class="list2">
<li>La introducción de bebidas alcohólicas, armas e instrumentos susceptibles de ser utilizados como tales, bengalas, fuegos de artificio u objetos análogos.</li>
<li>La introducción y exhibición de pancartas, símbolos, emblemas o leyendas que impliquen incitación a la violencia.</li>
<li>Que el portador haya sido sancionado con la prohibición de acceso a cualquier recinto deportivo, mientras no se haya extinguido la sanción.</li>
<li>Encontrarse bajo los efectos de bebidas alcohólicas, estupefacientes, psicotrópicos, estimulantes o sustancias análogas.</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div class="icn_fold1 icn_fold1_right"><div class="text"></div></div>
<div class="icn_fold2 icn_fold2_bottom"><div class="text"></div></div>
</div>
</#macro>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Voucher</title>
<style>
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td {
margin: 0;
padding: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
fieldset, img {
border: 0 none;
}
address, caption, cite, code, dfn, em, strong, th, var {
font-style: normal;
font-weight: normal;
}
ol, ul, li {
list-style: none outside none;
}
caption, th {
text-align: left;
}
h1, h2, h3, h4, h5, h6 {
font-size: 100%;
font-weight: normal;
}
body {
background-color: #FFFFFF;
color: #000000;
font-family: Arial,Helvetica,sans-serif;
font-size: 10px;
margin: 0;
padding: 0;
text-align: left;
}
h1 {
font-size: 15px;
font-weight: bold;
text-transform: uppercase;
padding: 10px 0 5px 0;
text-align: center;
color:#fff;
}
#content {
background-color: #FFFFFF;
overflow: hidden;
position: relative;
margin:0;
padding:0;
}
#content #bg1 .title h1 {
color:#fff;
padding:0;
margin-top:6px;
text-align:center;
}
#content #bg1 .title {
background: url("http://evo.cdnstc.com/static/images/bono_ds/bg_title.png") repeat-y left top;
width: 309px;
height: 44px;
margin: 0 0 0 6px;
}
.note {
color:#fff;
padding:0;
font-size: 8px;
margin-bottom: 8px;
}
.note strong {
font-size: 9px;
}
.txt_rose {
color:#A30245;
}
#content #bg4 .note {
padding: 0;
text-align:center;
}
#content #bg1 .services_bg {
background: url("http://evo.cdnstc.com/static/images/bono_ds/bg_services.png") no-repeat left top;
width:309px;
height: 238px;
margin: 0 0 0 6px;
}
#content #bg1 .logo_fcb {
margin-top:4px;
}
#content #bg1 .price span {
font-size: 15px;
color:#000;
}
a:hover {
text-decoration: underline;
}
.hidden {
display: none;
}
.first {
margin-left: 0;
}
.last {
margin-right: 0;
}
.clear {
clear: both;
display: block;
height: 0;
overflow: hidden;
visibility: hidden;
width: 0;
}
.left {
float:left;
}
.right {
float:right;
}
.icn_fold1 {
position:absolute;
top:500px;
left:7px;
font-size:8px;
font-weight: bold;
color:#A30245;
background: url("http://evo.cdnstc.com/static/images/bono_ds/icn_fold1_cas.gif") no-repeat left top;
height:217px;
z-index: 100;
*width:40px;
}
.icn_fold2 {
position:absolute;
top:6px;
left:245px;
font-size:8px;
font-weight: bold;
color:#A30245;
background: url("http://evo.cdnstc.com/static/images/bono_ds/icn_fold2_cas.gif") no-repeat left top;
height:26px;
z-index: 100;
}
.icn_fold1_right {
left:680px;
}
.icn_fold2_bottom {
top:965px;
}
.icn_fold1 .text {
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
margin-left: -145px;
margin-top: -72px;
*margin-left: 3px;
*margin-top: -115px;
margin-left: 3px\0/;
margin-top: -115px\0/;
width: 300px;
}
.icn_fold2 .text {
margin-left: 15px;
margin-top: -2px;
width: 300px;
}
strong {
font-weight: bold;
}
#content {
width:720px;
}
#content div {
float:left;
}
#content #area1 {
width: 350px;
border-right: 1px dashed #A30245;
border-bottom: 1px dashed #A30245;
}
#content #area2 {
width: 354px;
border-bottom: 1px dashed #A30245;
}
#content #area3 {
width: 350px;
border-right: 1px dashed #A30245;
}
#content #area4 {
width: 354px;
}
#content #bg1 {
background: url("http://evo.cdnstc.com/static/images/bono_ds/bg1.png") no-repeat left top;
width: 321px;
height: 457px;
margin: 25px 8px 8px 25px;
}
#content #bg1 p {
text-align: center;
}
#content #bg2 {
background: url("http://evo.cdnstc.com/static/images/bono_ds/bg2.png") no-repeat left top;
width: 321px;
height: 457px;
margin: 25px 25px 8px 4px;
}
#content #bg3 {
background: url("http://evo.cdnstc.com/static/images/bono_ds/bg3.png") no-repeat left top;
width: 321px;
height: 457px;
margin: 8px 8px 25px 25px;
text-align:center;
display: table;
position: relative;
}
#content #bg4 {
background: url("http://evo.cdnstc.com/static/images/bono_ds/bg4.png") no-repeat left top;
width: 321px;
height: 457px;
margin: 8px 0px 25px 4px;
}
#content #bg4 .info {
padding: 5px 0px 0px 13px;
font-size:8px;
}
#content #bg4 ul {
float:left;
}
#content #bg4 .instructions li{
width:148px;
display: inline;
float:left;
margin-right: 5px;
}
#content #bg4 .instructions img{
margin-top: 10px;
}
#content #bg4 .attention {
background: url("http://evo.cdnstc.com/static/images/bono_ds/ico_par.gif") no-repeat left top;
padding: 0px 15px 4px 10px;
margin: 3px 0 3px 0;
float:left;
/**width:580px;*/
}
#content #bg4 .attention strong {
font-size: 9px;
}
#content #bg4 h2 {
font-size: 10px;
text-transform: uppercase;
float:left;
color:#A30245;
font-weight: bold;
margin-bottom: 5px;
/**width:620px;*/
}
#content #bg4 p {
float:left;
padding-right: left;
}
#content #bg4 p.note {
float:none;
margin-top:13px;
}
#content #bg4 .list1 {
margin:5px 0 0 0px;
font-size: 8px;
padding-right: 10px;
}
#content #bg4 .list1 li {
background: url("http://evo.cdnstc.com/static/images/bono_ds/ico_line1.png") no-repeat 0 2px;
padding-left:8px;
margin-bottom:5px;
}
#content #bg4 .list2 {
margin-top: 10px;
*margin-left:20px;
}
#content #bg4 .list2 li {
background: url("http://evo.cdnstc.com/static/images/bono_ds/ico_line2.png") no-repeat left 3px;
}
#content .service {
margin: 10px 10px 5px 18px;
width: 268px;
}
#content .service table {
margin-bottom:15px;
font-size:9px;
}
#content .service table strong {
color: #A30245;
}
#content .service table span {
font-weight:bold;
}
#content .service table tr.lastd td {
border-bottom: 1px dotted #000;
padding-bottom:20px;
}
#content .access strong{
font-size: 10px;
color: #FF0000;
}
#content #bg1 .logo_hex {
margin: -20px 0 0 6px;
width: 309px;
text-align: center;
}
#content #bg1 .logo_hex img {
margin-top: 45px;
}
#content #bg2 .map {
margin:0 0 0 7px;
text-align: center;
}
#content #bg2 .logos_pie {
text-align:center;
margin-top: 27px;
}
#content #bg3 .banner {
position:relative;
margin-bottom: 10px;
*position: absolute;
*bottom: 0px;
*left:0px;
}
#content #bg3 #banner-content {
margin-top: 100px;
float:none;
}
#content #bg3 #banner-content .publi {
float:right;
font-size:8px;
margin:3px 14px 0 0;
text-transform: uppercase;
}
#content .locator {
text-align: center;
float: none;
font-size:10px;
}
#content .barcode {
margin: 9px 0 5px 0;
}
</style>
</head>
<body>
<#list vouchers as voucher>
<@print_bono voucher />
<#if voucher_has_next>
<br /><br /><br /><br />
</#if>
</#list>
</body>
</html>"
在返回语句之前填充结果的内容:
"<html>
<head>
<meta name="generator"
content="HTML Tidy for Java (vers. 2009-12-01), see jtidy.sourceforge.net" />
<title></title>
</head>
<body></body>
</html>
"
我什至无法想象出了什么问题...任何帮助或指导?