Hey Karl

I can show you one of my first attempts to use IRequestTargetUrlCodingStrategy. It's for a never-published weblog I wrote a while ago.

It maps http://localhost/weblog/article/some_article_title_in_url_form

to

new BlogItemPage(BlogItem blogItem)

which means I do the resolving of the BlogItem object from a DAO in the IRequestTargetUrlCodingStrategy.

I think it somewhat covers your needs:



BlogItemPageUrlCodingStrategy.java

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import dk.billen.weblog.dao.BlogItemDAO;
import dk.billen.weblog.domain.BlogItem;
import dk.billen.weblog.frontend.pages.BlogItemPage;
import dk.billen.weblog.frontend.pages.FrontendFrontPage;
import wicket.IRequestTarget ;
import wicket.Page;
import wicket.PageParameters;
import wicket.request.RequestParameters;
import wicket.request.target.coding.IRequestTargetUrlCodingStrategy;
import wicket.request.target.component.BookmarkablePageRequestTarget ;
import wicket.request.target.component.PageRequestTarget;

/**
 *
 */
public class BlogItemPageUrlCodingStrategy implements IRequestTargetUrlCodingStrategy {

    private BlogItemDAO blogItemDAO;

    /**
     * @param blogItemDAO
     */
    public BlogItemPageUrlCodingStrategy(BlogItemDAO blogItemDAO) {
        this.blogItemDAO = blogItemDAO;
    }

    public IRequestTarget decode(RequestParameters requestParameters) {
        IRequestTarget target = null;

        String path = requestParameters.getPath();

        Pattern pat = Pattern.compile("^\\/article\\/([^\\/]+)$");
        Matcher mat = pat.matcher(path);
        if (mat.matches()) {
            String title = mat.group(1);

            BlogItem blogItem = blogItemDAO.get(title);

            Page page = null;
            if (blogItem == null) {
                page = new FrontendFrontPage();
            } else {
                page = new BlogItemPage(blogItem);
            }

            target = new PageRequestTarget(page);
        }

        return target;
    }

    public CharSequence encode(IRequestTarget requestTarget) {
        StringBuffer buffer = new StringBuffer();

        if (requestTarget instanceof BookmarkablePageRequestTarget) {
            BookmarkablePageRequestTarget target = (BookmarkablePageRequestTarget) requestTarget;

            PageParameters pageParameters = target.getPageParameters();
            String title = pageParameters.getString("articleTitle");
           
            buffer.append("/article/");
            buffer.append(title);
        }

        return buffer.toString();
    }

    public boolean matches(IRequestTarget requestTarget) {
        boolean matches = false;

        if (requestTarget instanceof BookmarkablePageRequestTarget) {
            BookmarkablePageRequestTarget target = (BookmarkablePageRequestTarget) requestTarget;

            if (BlogItemPage.class.equals(target.getPageClass())) {
                matches = true;
            }
        }

        return matches;
    }

}


BlogItemPage.java

import wicket.PageParameters;
import dk.billen.weblog.command.CommandInterface;
import dk.billen.weblog.command.CommandRequest;
import dk.billen.weblog.domain.BlogItem;
import dk.billen.weblog.frontend.components.BlogItemPanel;

public class BlogItemPage extends FrontendBasePage {
    private static final long serialVersionUID = 1L;

    public BlogItemPage(BlogItem blogItem) {
        add(new BlogItemPanel("item", blogItem));
    }

    public static class ShowBlogItem implements CommandInterface {
        private static final long serialVersionUID = 1L;
       
        private BlogItem blogItem;

        public ShowBlogItem(BlogItem blogItem) {
            super();
            this.blogItem = blogItem;
        }

        public BlogItem getBlogItem() {
            return blogItem;
        }

        public void execute(CommandRequest request) {
            PageParameters pageParameters = new PageParameters();
            pageParameters.add("articleId", "" + blogItem.getId());

            request.setResponsePage(BlogItemPage.class, pageParameters);
        }
    }
}



And then in *Application.java #init()

...
mount("/article", new BlogItemPageUrlCodingStrategy(getBlogItemDAO()));
...



Hope it makes sense.


On 8/15/06, Karl M. Davis <[EMAIL PROTECTED]> wrote:
Hello all,
 
What I would like to have is a site where user-specific feature pages map to hierarchical URLs.  For example:
 * /site/user/karl/blog/2006/08/14 maps to BlogViewer(bob, "2006", "08", "14")
 * /site/user/karl/content/BestEssayEver maps to ContentViewer(fred, "MyLifeStory")
 * /site/user/fred/content/BestEssayEver maps to ContentViewer(fred, "BestEssayEver")
 
I could "cheat" and use Bookmarkable pages but this would leave the users also being passed as strings-- I'd rather resolve them ahead of time and pass the pages the real Actor instances.
 
In order to do that, I think I'll have to write an implementation of AbstractRequestTargetUrlCodingStrategy that encodes and decodes the pages.  Also, I will have to have a "guarantee" that each of the mounted pages has a constructor in the form of Constructor(user, string[] params).
 
The AbstractRequestTargetUrlCodingStrategy shouldn't be all that hard to write, but I think the aforementioned "guarantee" will require an implementation of IRequestTarget similar to IBookmarkablePageRequestTarget that stores the request's parameters for the pages.  From what I can see, this would also be simple to write as it seems to be mostly a data-storage class.  However, I am unsure of how to "wire up" Wicket to use my new IRequestTarget implementation once I have completed it.
 
Can anyone help me with that?  I would also really appreciate any insight/links someone could provide on how Wicket's entire URLmapping scheme works-- I haven't been able to find any architecture documents or anything that explain this in a general sense.  I'm used to using IIS and writing URL filters so this is pretty new territory for me.

Thanks in advance,
Karl

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to