James Moger
2015-11-22 ed552ba47c02779c270ffd62841d6d1048dade70
commit | author | age
f13c4c 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  */
5fe7df 16 package com.gitblit.wicket.pages;
JM 17
4ab184 18 import java.text.MessageFormat;
JM 19 import java.util.Arrays;
e11f48 20 import java.util.Date;
608ece 21 import java.util.List;
JM 22
5fe7df 23 import org.apache.wicket.PageParameters;
6ef8d7 24 import org.apache.wicket.markup.html.WebPage;
4ab184 25 import org.apache.wicket.markup.html.basic.Label;
JM 26 import org.eclipse.jgit.lib.Constants;
5fe7df 27 import org.eclipse.jgit.lib.Repository;
JM 28
1f9dae 29 import com.gitblit.models.RefModel;
5fe7df 30 import com.gitblit.utils.JGitUtils;
a7db57 31 import com.gitblit.wicket.CacheControl;
JM 32 import com.gitblit.wicket.CacheControl.LastModified;
bc10f9 33 import com.gitblit.wicket.WicketUtils;
b57b9e 34 import com.gitblit.wicket.panels.AvatarImage;
1f9dae 35 import com.gitblit.wicket.panels.LinkPanel;
4ab184 36 import com.gitblit.wicket.panels.RefsPanel;
5fe7df 37
a7db57 38 @CacheControl(LastModified.BOOT)
5fe7df 39 public class TagPage extends RepositoryPage {
JM 40
41     public TagPage(PageParameters params) {
cebf45 42         super(params);
5fe7df 43
155bf7 44         Repository r = getRepository();
JM 45
4ab184 46         // Find tag in repository
5cc4f2 47         List<RefModel> tags = JGitUtils.getTags(r, true, -1);
9ab5cc 48         RefModel tagRef = null;
155bf7 49         for (RefModel tag : tags) {
9ab5cc 50             if (tag.getName().equals(objectId) || tag.getObjectId().getName().equals(objectId)) {
JM 51                 tagRef = tag;
52                 break;
608ece 53             }
JM 54         }
5fe7df 55
4ab184 56         // Failed to find tag!
9ab5cc 57         if (tagRef == null) {
6caa93 58             error(MessageFormat.format(getString("gb.couldNotFindTag"), objectId), true);
155bf7 59         }
JM 60
4ab184 61         // Display tag.
6ef8d7 62         Class<? extends WebPage> linkClass;
4ab184 63         PageParameters linkParameters = newCommitParameter(tagRef.getReferencedObjectId().getName());
JM 64         String typeKey;
65         switch (tagRef.getReferencedObjectType()) {
66         case Constants.OBJ_BLOB:
67             typeKey = "gb.blob";
68             linkClass = BlobPage.class;
69             break;
70         case Constants.OBJ_TREE:
71             typeKey = "gb.tree";
72             linkClass = TreePage.class;
73             break;
74         case Constants.OBJ_COMMIT:
75         default:
76             typeKey = "gb.commit";
77             linkClass = CommitPage.class;
78             break;
79         }
b57b9e 80         add(new AvatarImage("taggerAvatar", tagRef.getAuthorIdent()));
699e71 81
4ab184 82         add(new RefsPanel("tagName", repositoryName, Arrays.asList(tagRef)));
JM 83         add(new Label("tagId", tagRef.getObjectId().getName()));
84         add(new LinkPanel("taggedObject", "list", tagRef.getReferencedObjectId().getName(),
85                 linkClass, linkParameters));
86         add(new Label("taggedObjectType", getString(typeKey)));
5fe7df 87
33d8d8 88         add(createPersonPanel("tagger", tagRef.getAuthorIdent(), com.gitblit.Constants.SearchType.AUTHOR));
e11f48 89         Date when = new Date(0);
JM 90         if (tagRef.getAuthorIdent() != null) {
91             when = tagRef.getAuthorIdent().getWhen();
92         }
9adf62 93         add(WicketUtils.createTimestampLabel("tagDate", when, getTimeZone(), getTimeUtils()));
4ab184 94
cd9461 95         addFullText("fullMessage", tagRef.getFullMessage());
5fe7df 96     }
155bf7 97
cebf45 98     @Override
JM 99     protected String getPageName() {
1e47ab 100         return getString("gb.tag");
cebf45 101     }
699e71 102
6ef8d7 103     @Override
5d5e55 104     protected boolean isCommitPage() {
JM 105         return true;
106     }
107
108     @Override
6ef8d7 109     protected Class<? extends BasePage> getRepoNavPageClass() {
JM 110         return LogPage.class;
111     }
5fe7df 112 }