Skip to content

Instantly share code, notes, and snippets.

View chkal's full-sized avatar

Christian Kaltepoth chkal

View GitHub Profile
@chkal
chkal / CountryAndQuantity.java
Created March 15, 2011 16:34
Custom result objects with Criteria4JPA
public static class CountryAndQuantity {
private final String country;
private final Long quantity;
public CountryAndQuantity(String country, Long quantity) {
this.country = country;
this.quantity = quantity;
}
@chkal
chkal / JadeTransformer.java
Created August 8, 2012 04:57
Using Jade with Rewrite
public class JadeTransformer extends StringTransformer
{
@Override
public String transform(String src)
{
try {
return new Jade().process(src, new HashMap<String, Object>());
}
catch (IOException e) {
@chkal
chkal / SingletonFeatureManagerProvider.java
Created September 28, 2012 15:03
Bootstrapping Togglz in client applications
/**
* Register the provider by creating a file 'META-INF/services/org.togglz.core.spi.FeatureManagerProvider'.
* The file must contains the fully-qualified name of the provider class.
*/
public class SingletonFeatureManagerProvider implements FeatureManagerProvider {
private static FeatureManager featureManager;
@Override
public int priority() {
@chkal
chkal / TogglzManagement.java
Created December 15, 2012 10:39
Demonstrates how to integrate Togglz with JMX
/**
* Implementation of the Management interface
*/
public class TogglzManagement implements TogglzManagementMBean {
@Override
public void toggle(String featureName, boolean enabled) {
// as we only know the name, wrap it into an UntypedFature
UntypedFeature feature = new UntypedFeature(featureName);
@chkal
chkal / MultiEnumFeatureProvider.java
Created May 21, 2013 13:28
Using multiple feature enums with Togglz
public class MultiEnumFeatureProvider implements FeatureProvider {
private final Set<Feature> features = new LinkedHashSet<>();
public MultiEnumFeatureProvider( Class<? extends Feature>... enumTypes ) {
for( Class<? extends Feature> clazz : enumTypes ) {
for( Feature feature : clazz.getEnumConstants() ) {
features.add( feature );
}
}
@chkal
chkal / FeatureServlet.java
Created July 31, 2013 06:19
Simple Servlet to control Togglz features using GET requests
@WebServlet(urlPatterns = "/FeatureServlet")
public class FeatureServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException {
Feature feature = new NamedFeature( req.getParameter( "feature" ) );
boolean enabled = "on".equals( req.getParameter( "state" ) );
@chkal
chkal / UserClientIpActivationStrategy.java
Created September 30, 2013 05:48
Example for a custom activation strategy that combines two existing strategies
public class UserClientIpActivationStrategy implements ActivationStrategy {
private final ActivationStrategy userStrategy = new UsernameActivationStrategy();
private final ActivationStrategy ipStrategy = new ClientIpActivationStrategy();
@Override
public String getId() {
return "user-ip";
}
@Controller
@Path("/somepage")
public class SomeController {
@Inject
private Result result;
@Inject
private Validator validation;
@chkal
chkal / CustomConfigurationProducer.java
Last active August 29, 2015 14:18
Customization of the configuration used by FreemarkerViewEngine
public class CustomConfigurationProducer extends DefaultConfigurationProducer {
@Override
@Specializes
@Produces
@ViewEngineConfig // <--- See my note in the mail
public Configuration getConfiguration() {
Configuration config = super.getConfiguration();
// do custom initialization here
return config;
/**
* This will result in an additional ViewEngine. The priority ensures
* that this implementation is preferred.
*/
@Priority(1000)
public class AdditionalViewEngine extends FreemarkerViewEngine {
@Override
protected Configuration buildConfiguration() {