WhiteListType.NONE, but <td> is allowed. TestCase is like this:
https://codelabor.googlecode.com/svn/trunk/codelabor-prototype/src/main/java/org/codelabor/example/validation/hibernate/safeHtml/dto/SafeHtmlWhitelistNoneDto.java ---------------------------------------------------------------------------------------------- package org.codelabor.example.validation.hibernate.safeHtml.dto;
import java.io.Serializable; import java.util.List;
import org.hibernate.validator.constraints.NotEmpty; import org.hibernate.validator.constraints.SafeHtml; import org.hibernate.validator.constraints.SafeHtml.WhiteListType;
/**
-
@author Shin Sang-Jae
* */ public class SafeHtmlWhitelistNoneDto implements Serializable {
/** * */ private static final long serialVersionUID = 452811399327066527L;
public static long getSerialversionuid() { return serialVersionUID; }
/** * */ @SafeHtml(whitelistType=WhiteListType.NONE) private String stringData1;
public String getStringData1() { return stringData1; }
public void setStringData1(String stringData1) { this.stringData1 = stringData1; }
} ----------------------------------------------------------------------------------------------
https://codelabor.googlecode.com/svn/trunk/codelabor-prototype/src/test/java/javax/validation/HibernateValidatorTest.java ---------------------------------------------------------------------------------------------- package javax.validation;
import java.util.ArrayList; import java.util.List; import java.util.Set;
import junit.framework.Assert;
import org.codelabor.example.validation.hibernate.safeHtml.dto.HtmlContents1Dto; import org.codelabor.example.validation.hibernate.safeHtml.dto.SafeHtmlWhitelistNoneDto; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory;
public class HibernateValidatorTest {
private static final Logger logger = LoggerFactory .getLogger(HibernateValidatorTest.class); private static Validator validator; @BeforeClass public static void setUpBeforeClass() throws Exception { }
@AfterClass public static void tearDownAfterClass() throws Exception { }
@Before public void setUp() throws Exception { validator = Validation.buildDefaultValidatorFactory().getValidator(); }
@After public void tearDown() throws Exception { }
@Test public final void testSafehtmlWhitelistNone() throws Exception { SafeHtmlWhitelistNoneDto safeHtmlWhitelistNoneDto = new SafeHtmlWhitelistNoneDto(); safeHtmlWhitelistNoneDto.setStringData1("<td>1234qwer</td>");
Set<ConstraintViolation<SafeHtmlWhitelistNoneDto>> constraintViolations = validator .validate(safeHtmlWhitelistNoneDto); logger.error("violation count: {}", constraintViolations.size());
for (ConstraintViolation<?> violation : constraintViolations) { logger.error(""); logger.error("executableParameters: {}", violation.getExecutableParameters()); logger.error("executableReturnValue: {}", violation.getExecutableReturnValue()); logger.error("constraintDescriptor: {}", violation.getConstraintDescriptor()); logger.error("propertyPath: {}", violation.getPropertyPath()); logger.error("invalidValue: {}", violation.getInvalidValue()); logger.error("message: {}", violation.getMessage()); } Assert.assertEquals(1, constraintViolations.size()); } }
|