Class ExtendedPackageMapper

  • All Implemented Interfaces:
    IRequestMapper

    public class ExtendedPackageMapper
    extends AbstractMapper

    Extended PackageMapper with Named Parameter and HomePage support. Remember to add this mapper before anyone else, so it will have low priority against top-level, more important mappers.

    Usage:

     add(new ExtendedPackageMapper("${username}/static/${group}", Profile.class) {
              protected boolean validateParameters(PageParameters parameters) { 
                 String username = parameters.get("username").toString(); 
                 String group = parameters.get("group").toString();
                 return validUsername(username)
              }
     });
     

    Users can then use URLs like:

    • http://localhost:8080/john/static/admin -> renders Profile page
    • http://localhost:8080/john/static/admin/Profile -> renders Profile page
    • http://localhost:8080/john/static/admin/Groups -> renders Groups page present in same package as Profile
    Parameters can be accessed as usual (PageParameters in constructor, for example)

    Author:
    Bruno Borges
    • Constructor Detail

      • ExtendedPackageMapper

        public ExtendedPackageMapper​(String mountPath,
                                     Class<P> homePage)

        Construct an ExtendedPackageMapper for package of homePage class, at mountPath. homePage is considered the Home Page for this mounted path, in case the user does not indicate which page to render.

        Named parameters are optional and may be defined as the first mount segment

        Parameters:
        mountPath - in the form of "${some}/path/with/${named}/parameters"
        homePage -
    • Method Detail

      • validateParameters

        protected boolean validateParameters​(PageParameters parameters)
        Override this to validate parameters. Return true if this Mapper should handle the current request based on your busines slogic
        Parameters:
        parameters -
        Returns:
        true if this Mapper will handle the request. default: true
      • getCompatibilityScore

        public int getCompatibilityScore​(Request request)
        Scores the compatibility of Request with this Mapper.
        • +1 for segments count equals mountedSegments+1 (page referenced)
        • +1 for segments count equals mountedSegments
        • +2+(score/2) for static segments