The Artima Developer Community
Sponsored Link

Java Buzz Forum
JSR-311 with Spring fragment

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Bill de hÓra

Posts: 1137
Nickname: dehora
Registered: May, 2003

Bill de hÓra is a technical architect with Propylon
JSR-311 with Spring fragment Posted: Aug 23, 2008 6:49 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Bill de hÓra.
Original Post: JSR-311 with Spring fragment
Feed Title: Bill de hÓra
Feed URL: http://www.dehora.net/journal/atom.xml
Feed Description: FD85 1117 1888 1681 7689 B5DF E696 885C 20D8 21F8
Latest Java Buzz Posts
Latest Java Buzz Posts by Bill de hÓra
Latest Posts From Bill de hÓra

Advertisement

Handling a path based URL in Java, with Jersey, Spring2.5 and StringTemplate:

@Path("users") @Singleton
public class SingletonUserResourceWithSpring
{
    private static final String OPENSOCIAL_MEDIATYPE = "application/atom+xml";
   
    @Inject private UserAccountService userAccountService;
    private StringTemplateGroup templates;
   
    public SingletonUserResourceWithSpring() {
        templates = new StringTemplateGroup("templates");
    }

    @GET @Path("/{uid}")
    @Produces(OPENSOCIAL_MEDIATYPE)   
    public String getByUID(@PathParam("uid") String uid) {
        UserAccount account = userAccountService.findByUID(uid);
        return renderToResponse(account);
    }

    private String renderToResponse(UserAccount account) {
        StringTemplate userxml = loadTemplate("templates/user_opensocial");
        userxml.setAttribute("accountName", account.getAccountName());
        userxml.setAttribute("uid", account.getUid());
        userxml.setAttribute("email", account.getEmail());
        userxml.setAttribute("firstName", account.getFirstName());
        userxml.setAttribute("lastName", account.getLastName());
        userxml.setAttribute("render_summary_flag", "yes");
        return userxml.toString();
    }

    private StringTemplate loadTemplate(String template) {
        return templates.getInstanceOf(template);
    }
}

 

That's not bad. It could be even tighter in Groovy. Tip of the hat to javakaffee and Paul Sandoz.

Read: JSR-311 with Spring fragment

Topic: Web2-ContractSite Previous Topic   Next Topic Topic: Optional typing and dynamic languages

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use