You're misunderstanding.

A ServiceEncoder translates between a completely arbitrary URI path -- any extension or none, any parameters, any path structure -- and the "real" internal URL.

For example, here's an encoder of mine from Imre that translates between an external link of this form:

        /imre/article/1673

...and an internal URL of this form:

        /app?service=external&page=ArticleView&sp=*Article#1673

Hope this helps.

Cheers, P


public class ArticlePermalinkEncoder
    implements ServiceEncoder
    {
    private static final String
        ARTICLE_VIEW_PAGE = "ArticleView",
        ARTICLE_PREFIX = "/article/";

private static final Pattern pathFormat = Pattern.compile("/ article/([0-9]+)(\\.([0-9]+))?");

    public void encode(ServiceEncoding encoding)
        {
String service = encoding.getParameterValue (ServiceConstants.SERVICE); String pageName = encoding.getParameterValue (ServiceConstants.PAGE); if(Tapestry.EXTERNAL_SERVICE.equals(service) && ARTICLE_VIEW_PAGE.equals(pageName))
            {
            DomainObject param = DomainObjectSqueezeAdaptor.unsqueeze(
encoding.getParameterValue (ServiceConstants.PARAMETER));

            Long articleId = null;
            String suffix = "";
            if(param instanceof Version)
                {
                Version version = (Version) param;
                suffix = "." + version.getVersionNumber();
                param = version.getArticle();
                }
            if(param instanceof Article)
                articleId = ((Article) param).getId();

            if(articleId != null)
                {
encoding.setServletPath(ARTICLE_PREFIX + articleId + suffix); encoding.setParameterValue(ServiceConstants.SERVICE, null); encoding.setParameterValue(ServiceConstants.PAGE, null); encoding.setParameterValue (ServiceConstants.PARAMETER, null);
                }
            }
        }

    public void decode(ServiceEncoding encoding)
        {
        Class<? extends DomainObject> type = null;

        Matcher matcher = pathFormat.matcher(
encoding.getServletPath() + StringUtils.defaultString (encoding.getPathInfo()));

        if(matcher.matches())
            {
Article article = HibernateHelper.fromId(Article.class, matcher.group(1));
            DomainObject param =
                (matcher.group(3) == null)
                    ? article
: article.getVersion(Integer.parseInt (matcher.group(3)));

encoding.setParameterValue(ServiceConstants.SERVICE, Tapestry.EXTERNAL_SERVICE); encoding.setParameterValue(ServiceConstants.PAGE, ARTICLE_VIEW_PAGE); encoding.setParameterValue(ServiceConstants.PARAMETER, DomainObjectSqueezeAdaptor.squeeze(param));
            }
        }
    }



On Jan 4, 2006, at 12:55 PM, Rusty Phillips wrote:

Well, I did look at that part of the page a great deal before asking the
question.  Perhaps you understand it better than I.

It is my understanding that within an encode method, you specify
encoding.setParameterValue(CONSTANT_NAME,VALUE)
to set the service name, page, and any other parameters you want to set.

The thing I don't see is where you decide that if you're looking for a
page named "Foo" then Tapestry should be looking for a "Foo.xml," and
not "Foo.html"

Unless I'm not understanding (and admittedly, I might not be), this
doesn't have anything to do with encoding:
Using the URL: http://localhost/tap/app?page=Home
causes tapestry to look for the file "Home.html" to generate the page.

-----Original Message-----
From: Paul Cantrell [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 04, 2006 1:59 PM
To: Tapestry users
Subject: Re: Rewriting URLs: is something missing?

?!!??

What you're describing is exactly what friendly URLs do ... and the
doc page you mention describes how to do it. Looks like you just
missed it. Read the section on "encoder."

     http://jakarta.apache.org/tapestry/UsersGuide/friendly-
urls.html#encoder

Cheers,

Paul


On Jan 4, 2006, at 11:55 AM, Rusty Phillips wrote:

I can see from the docs
(http://jakarta.apache.org/tapestry/UsersGuide/friendly-urls.html)
that
I can rewrite urls to be friendlier quite easily.



What I don't see anywhere is a way to stop creating pages with the
".html".  This is important because most editors consider extension
when
deciding how to do markup.



Does anyone know where tapestry decides that a particular page is
located in the path at "[pagename].html", and how I'd change that to
something else?



Ultimately, my goal here is to be able to be able to make a file
named,
for instance:

MyTemplate.xml



Which is perhaps a tapestry template that specifies an xml-fo document
when you render it, and be able to render that as:

http://localhost:8080/app/MyTemplate.pdf



rather than having a file named "MyTemplate.html" and having to
refer to
the page as:

http://localhost:8080/app/service=xmlconverter&page=MyTemplate



Note that I do know how to do URL remapping, and can create encodings.
My question is how to avoid the use of the html extension.



Thanks for your help!


_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to