View Javadoc

1   package ch.odi.justblog.command;
2   
3   import java.net.URL;
4   
5   import ch.odi.justblog.JustBlog;
6   import ch.odi.justblog.api.ApiRegistry;
7   import ch.odi.justblog.api.Blog;
8   import ch.odi.justblog.api.BlogApi;
9   import ch.odi.justblog.api.Entry;
10  import ch.odi.justblog.discovery.Discovery;
11  import ch.odi.justblog.discovery.RsdApi;
12  import ch.odi.justblog.gui.IAuthenticator;
13  import ch.odi.justblog.gui.Ui;
14  
15  /***
16   * Sets a new URL for the session. 
17   *
18   * @author oglueck
19   */
20  public class SetUrl implements Command {
21      private URL url;
22      
23      
24      /***
25       * 
26       */
27      public SetUrl(URL url) {
28          this.url = url;
29      }
30  
31      public void execute(ISession session) throws CommandException {
32          try {
33              Discovery discovery = new Discovery(url);
34              RsdApi rsdapi = discovery.autoSelect();
35              BlogApi api = ApiRegistry.get(rsdapi.getName());
36              Ui gui = JustBlog.app().getUi(); //FIXME: authenticator instance should come out of the session! (or it won't work with a web UI)
37              IAuthenticator auth = gui.createAuthenticator();
38              auth.setContext("Authenticate against "+ api.getName() +", Blog "+ rsdapi.getBlogId());
39              Blog blog = api.getBlog(rsdapi.getApiUrl(), rsdapi.getBlogId());
40              blog.authenticate(auth);
41              session.setEntry(new Entry());
42              session.setBlog(blog);
43          } catch(Throwable e) {
44              throw new CommandException(e);
45          }
46      }
47  }