Skip to content

Instantly share code, notes, and snippets.

View andrewspencer's full-sized avatar

Andrew Spencer andrewspencer

View GitHub Profile
@andrewspencer
andrewspencer / StringUtil.java
Created May 2, 2011 14:40
Remove accents from a String
package net.andrewspencer.util;
import sun.text.Normalizer; // java.text.Normalizer in 1.6
/**
* Here's how to remove accents in Java 1.5.
* NB Doesn't separate ligatures.
*/
// WARNING Uses unofficial Sun classes, so JVM-dependent.
// Normalizer became standard in Java 1.6, though.
@andrewspencer
andrewspencer / FbMultipleCheckableBeans.java
Created March 24, 2011 10:46
Multiple dynamic checkboxes in Struts 1.x using DisplayTag
package net.andrewspencer.gist.multiple-checkboxes-struts;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
@andrewspencer
andrewspencer / EqualDataSetAssertBuilder.java
Created December 17, 2010 10:46
EqualDataSetAssertBuilder: a wrapper around DbUnitAssert.assertEqualsIgnoreCols(), DBUnit's post-test dataset equality assertion, to allow comparing multiple tables instead of just one table at a time.
import java.util.HashMap;
import java.util.Map;
import org.dbunit.DatabaseUnitException;
import org.dbunit.assertion.DbUnitAssert;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.ITable;
import org.dbunit.dataset.filter.DefaultColumnFilter;
/**
@andrewspencer
andrewspencer / AbstractSpringTestNGDBUnitTest.java
Created December 17, 2010 10:40
AbstractSpringTestNGDBUnitTest: adds DBUnit functionality to Spring's base class for Spring-context aware TestNG tests. To use, subclass and provide XML dataset and DTD files (at locations indicated in API comments).
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import javax.annotation.Resource;
import org.dbunit.DefaultDatabaseTester;
import org.dbunit.IDatabaseTester;
@andrewspencer
andrewspencer / UserTypeSupport.java
Created December 15, 2010 14:10
Base class for Hibernate UserTypes
package net.andrewspencer.util.hibernate;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.HibernateException;