Skip to content

Instantly share code, notes, and snippets.

@lucascs
Created January 10, 2013 02:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucascs/4498748 to your computer and use it in GitHub Desktop.
Save lucascs/4498748 to your computer and use it in GitHub Desktop.
A Routes parser that uses the last package name as the first level of uri: /package/controller/method
@Component
@ApplicationScoped
public class PackageRoutesParser extends PathAnnotationRoutesParser {
//delegate constructor
public PackageRoutesParser(Router router) {
super(router);
}
@Override
protected String extractControllerNameFrom(Class<?> type) {
return "/" + extractPackage(type) + super.extractControllerNameFrom(type);
}
private String extractPackage(Class<?> type) {
String[] subpackages = type.getPackage().getName().split("\\.");
return subpackages[subpackages.length - 1]; //last
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment