This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean validateTextBox(String text, int limitBytes) { | |
return !containsControl(text) && !isOverBytes(text, limitBytes); | |
} | |
public static boolean validateTextArea(String text, int limitBytes) { | |
return !containsInvisible(text) && !isOverBytes(text, limitBytes); | |
} | |
private static boolean containsControl(String text) { | |
return !text.matches("\\P{Cntrl}*"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean isAlphaNumPunct(String string) { | |
if (string == null) { | |
return false; | |
} | |
return string.matches("\\p{Graph}+"); | |
} | |
@Test | |
public void testIsAlphaNumPunctOK() { | |
assertTrue(isAlphaNumPunct("abcxyzABCXYZ150!$/:=@[_`~")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.firefox.FirefoxProfile; | |
import org.apache.commons.io.FileUtils; | |
public class FileDownloadTest { | |
private static WebDriver driver; | |
private static final String DOWNLOAD_DIR = "C:\\work\\download"; | |
private static final String COMPARE_DIR = "C:\\work\\compare"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URL url = new URL(request.getRequestURL().toString()); | |
String baseUrl = new URL(url.getProtocol(), url.getHost(), url.getPort(), | |
request.getContextPath()).toString(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mail.pop3.host=localhost | |
mail.debug=false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.mail.*; | |
public class MailSender { | |
private final Properties props = loadProperties("/mail/MailSender.properties"); | |
private final Session session = createSession(); | |
private Properties loadProperties(String propPath) { | |
try { | |
Properties res = new Properties(); | |
res.load(MailSender.class.getResourceAsStream(propPath)); | |
return res; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean chackMailAddress(String address) { | |
try { | |
new javax.mail.internet.InternetAddress(address, true); | |
} catch (AddressException e) { | |
return false; | |
} | |
return true; | |
} | |
@Test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.lang3.RandomStringUtils; | |
@Test public void testRandomStringUtils() { | |
String random1 = RandomStringUtils.randomAlphanumeric(10); | |
String random2 = RandomStringUtils.randomAlphanumeric(10); | |
assertTrue(random1, random1.matches("[a-zA-Z0-9]{10}")); | |
assertTrue(random2, random2.matches("[a-zA-Z0-9]{10}")); | |
assertFalse(random1.equals(random2)); | |
System.out.println(random1); | |
System.out.println(random2); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.codec.digest.DigestUtils; | |
public static String hash(String password, String salt) { | |
return DigestUtils.sha256Hex(password + salt); | |
} | |
public static String hashAndStretch(String password, String salt, int count) { | |
String hashed = password; | |
for (int i = 0; i < count; i++) { | |
hashed = hash(hashed, salt); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@WebServlet({"/rewrite/hoge", "/rewrite/fuga"}) | |
public class UrlRewriteTestServlet extends HttpServlet { | |
protected void doGet(HttpServletRequest request, | |
HttpServletResponse response) throws ServletException, IOException { | |
Writer writer = response.getWriter(); | |
writer.write("<html>"); | |
writer.write(request.getRequestURI() + "<br/>"); | |
writer.write("id=" + request.getParameter("id") + "<br/>"); | |
writer.write("param1=" + request.getParameter("param1") + "<br/>"); | |
writer.write("<a href='fuga'>fuga</a>"); |