James Moger
2015-11-22 ed552ba47c02779c270ffd62841d6d1048dade70
commit | author | age
82df52 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
009656 18 import java.util.List;
JM 19
20 import javax.servlet.http.HttpServletRequest;
82df52 21
JM 22 import org.apache.wicket.PageParameters;
23 import org.apache.wicket.markup.html.basic.Label;
009656 24 import org.apache.wicket.protocol.http.WebRequest;
82df52 25
e21181 26 import com.gitblit.models.RepositoryModel;
009656 27 import com.gitblit.models.RepositoryUrl;
d37bce 28 import com.gitblit.models.UserModel;
JM 29 import com.gitblit.wicket.GitBlitWebSession;
9bdf88 30 import com.gitblit.wicket.GitblitRedirectException;
82df52 31 import com.gitblit.wicket.WicketUtils;
8c9255 32 import com.gitblit.wicket.panels.RepositoryUrlPanel;
82df52 33
9e7b14 34 public class EmptyRepositoryPage extends RepositoryPage {
82df52 35
JM 36     public EmptyRepositoryPage(PageParameters params) {
37         super(params);
38
9bdf88 39         setVersioned(false);
JM 40
82df52 41         String repositoryName = WicketUtils.getRepositoryName(params);
99d0d4 42         RepositoryModel repository = app().repositories().getRepositoryModel(repositoryName);
b845f1 43         if (repository == null) {
JM 44             error(getString("gb.canNotLoadRepository") + " " + repositoryName, true);
45         }
699e71 46
4e1cc8 47         if (repository.hasCommits) {
JM 48             // redirect to the summary page if this repository is not empty
9bdf88 49             throw new GitblitRedirectException(SummaryPage.class, params);
4e1cc8 50         }
699e71 51
d37bce 52         UserModel user = GitBlitWebSession.get().getUser();
264ba9 53         if (user == null) {
JM 54             user = UserModel.ANONYMOUS;
55         }
699e71 56
009656 57         HttpServletRequest req = ((WebRequest) getRequest()).getHttpServletRequest();
7d3a31 58         List<RepositoryUrl> repositoryUrls = app().services().getRepositoryUrls(req, user, repository);
009656 59         RepositoryUrl primaryUrl = repositoryUrls.size() == 0 ? null : repositoryUrls.get(0);
JM 60         String url = primaryUrl != null ? primaryUrl.url : "";
699e71 61
9e7b14 62         String createSyntax = readResource("create_git.md").replace("${primaryUrl}", url);
JM 63         String existingSyntax = readResource("existing_git.md").replace("${primaryUrl}", url);
64
82df52 65         add(new Label("repository", repositoryName));
009656 66         add(new RepositoryUrlPanel("pushurl", false, user, repository));
9e7b14 67         add(new Label("createSyntax", createSyntax));
JM 68         add(new Label("existingSyntax", existingSyntax));
82df52 69     }
699e71 70
6ef8d7 71     @Override
9e7b14 72     protected String getPageName() {
JM 73         return getString("gb.summary");
6ef8d7 74     }
82df52 75 }