James Moger
2012-02-09 5cc40c89abafdcccbc8a5b2cf3890780ccff908e
commit | author | age
797322 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit.wicket.pages;
17
18 import java.io.IOException;
19 import java.text.MessageFormat;
20
21 import org.apache.wicket.AttributeModifier;
22 import org.apache.wicket.PageParameters;
23 import org.apache.wicket.markup.html.basic.Label;
24 import org.apache.wicket.markup.html.image.Image;
25 import org.apache.wicket.markup.html.link.ExternalLink;
26 import org.apache.wicket.model.Model;
27
28 import com.gitblit.models.GravatarProfile;
29 import com.gitblit.utils.ActivityUtils;
30 import com.gitblit.wicket.WicketUtils;
31
32 /**
33  * Gravatar Profile Page shows the Gravatar information, if available.
34  * 
35  * @author James Moger
36  * 
37  */
38 public class GravatarProfilePage extends RootPage {
39
40     public GravatarProfilePage(PageParameters params) {
41         super();
42         setupPage("", "");
43         String object = WicketUtils.getObject(params);
44         GravatarProfile profile = null;
45         try {
46             if (object.indexOf('@') > -1) {
47                 profile = ActivityUtils.getGravatarProfileFromAddress(object);
48             } else {
49                 profile = ActivityUtils.getGravatarProfile(object);
50             }
51         } catch (IOException e) {
52             error(MessageFormat.format("Failed to find Gravatar profile for {0}", object), e, true);
53         }
d17f43 54         
JM 55         if (profile == null) {
56             error(MessageFormat.format("Failed to find Gravatar profile for {0}", object), true);
57         }
797322 58         add(new Label("displayName", profile.displayName));
JM 59         add(new Label("username", profile.preferredUsername));
60         add(new Label("location", profile.currentLocation));
61         add(new Label("aboutMe", profile.aboutMe));
62         Image image = new Image("profileImage");
63         image.add(new AttributeModifier("src", true, new Model<String>(profile.thumbnailUrl + "?s=256&d=identicon")));
64         add(image);
65         add(new ExternalLink("profileLink", profile.profileUrl));
66     }
67 }