Line data Source code
1 : // Copyright (C) 2008 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.common; 16 : 17 : import com.google.gerrit.entities.AccountGroup; 18 : import com.google.gerrit.entities.Change; 19 : import com.google.gerrit.entities.Change.Status; 20 : import com.google.gerrit.entities.KeyUtil; 21 : import com.google.gerrit.entities.PatchSet; 22 : import com.google.gerrit.entities.Project; 23 : 24 : public class PageLinks { 25 : public static final String PROJECT_CHANGE_DELIMITER = "/+/"; 26 : 27 : public static final String SETTINGS = "/settings/"; 28 : public static final String SETTINGS_PREFERENCES = "/settings/preferences"; 29 : public static final String SETTINGS_DIFF_PREFERENCES = "/settings/diff-preferences"; 30 : public static final String SETTINGS_EDIT_PREFERENCES = "/settings/edit-preferences"; 31 : public static final String SETTINGS_SSHKEYS = "/settings/ssh-keys"; 32 : public static final String SETTINGS_GPGKEYS = "/settings/gpg-keys"; 33 : public static final String SETTINGS_HTTP_PASSWORD = "/settings/http-password"; 34 : public static final String SETTINGS_OAUTH_TOKEN = "/settings/oauth-token"; 35 : public static final String SETTINGS_WEBIDENT = "/settings/web-identities"; 36 : public static final String SETTINGS_MYGROUPS = "/settings/group-memberships"; 37 : public static final String SETTINGS_AGREEMENTS = "/settings/agreements"; 38 : public static final String SETTINGS_CONTACT = "/settings/contact"; 39 : public static final String SETTINGS_PROJECTS = "/settings/projects"; 40 : public static final String SETTINGS_NEW_AGREEMENT = "/settings/new-agreement"; 41 : public static final String SETTINGS_EXTENSION = "/settings/x/"; 42 : public static final String REGISTER = "/register"; 43 : 44 : public static final String MINE = "/"; 45 : public static final String QUERY = "/q/"; 46 : public static final String PROJECTS = "/projects/"; 47 : public static final String DASHBOARDS = ",dashboards/"; 48 : public static final String ADMIN_GROUPS = "/admin/groups/"; 49 : public static final String ADMIN_CREATE_GROUP = "/admin/create-group/"; 50 : public static final String ADMIN_PROJECTS = "/admin/projects/"; 51 : public static final String ADMIN_CREATE_PROJECT = "/admin/create-project/"; 52 : public static final String ADMIN_PLUGINS = "/admin/plugins/"; 53 : public static final String MY_GROUPS = "/groups/self"; 54 : public static final String DOCUMENTATION = "/Documentation/"; 55 : 56 : public static String toChangeInEditMode(@Nullable Project.NameKey project, Change.Id c) { 57 0 : return toChangeNoSlash(project, c) + ",edit/"; 58 : } 59 : 60 : public static String toChange(@Nullable Project.NameKey project, Change.Id c) { 61 1 : return toChangeNoSlash(project, c) + "/"; 62 : } 63 : 64 : public static String toChange(@Nullable Project.NameKey project, Change.Id c, String p) { 65 0 : return toChange(project, c) + p; 66 : } 67 : 68 : public static String toChange( 69 : @Nullable Project.NameKey project, Change.Id c, String b, String p) { 70 0 : String u = toChange(project, c); 71 0 : if (b != null) { 72 0 : u += b + ".."; 73 : } 74 0 : u += p; 75 0 : return u; 76 : } 77 : 78 : public static String toChangeId(@Nullable Project.NameKey project, Change.Id c) { 79 0 : if (project == null) { 80 0 : return String.valueOf(c.get()); 81 : } 82 0 : return project.get() + PROJECT_CHANGE_DELIMITER + c.get(); 83 : } 84 : 85 : public static String toChange(@Nullable Project.NameKey project, PatchSet.Id ps) { 86 0 : return toChange(project, ps.changeId()) + ps.getId(); 87 : } 88 : 89 : public static String toProject(Project.NameKey p) { 90 0 : return ADMIN_PROJECTS + p.get(); 91 : } 92 : 93 : public static String toProjectAccess(Project.NameKey p) { 94 0 : return ADMIN_PROJECTS + p.get() + ",access"; 95 : } 96 : 97 : public static String toProjectBranches(Project.NameKey p) { 98 0 : return ADMIN_PROJECTS + p.get() + ",branches"; 99 : } 100 : 101 : public static String toProjectTags(Project.NameKey p) { 102 0 : return ADMIN_PROJECTS + p.get() + ",tags"; 103 : } 104 : 105 : public static String toAccountQuery(String fullname, Status status) { 106 0 : return toChangeQuery(op("owner", fullname) + " " + status(status)); 107 : } 108 : 109 : public static String toAssigneeQuery(String fullname) { 110 0 : return toChangeQuery(op("assignee", fullname)); 111 : } 112 : 113 : public static String toCustomDashboard(String params) { 114 0 : return "/dashboard/?" + params; 115 : } 116 : 117 : public static String toProjectDashboards(Project.NameKey proj) { 118 0 : return ADMIN_PROJECTS + proj.get() + ",dashboards"; 119 : } 120 : 121 : public static String toChangeQuery(String query) { 122 0 : return QUERY + KeyUtil.encode(query); 123 : } 124 : 125 : public static String toProjectDashboard(Project.NameKey name, String id) { 126 0 : return PROJECTS + name.get() + DASHBOARDS + id; 127 : } 128 : 129 : public static String toProjectDefaultDashboard(Project.NameKey name) { 130 0 : return PROJECTS + name.get() + DASHBOARDS + "default"; 131 : } 132 : 133 : public static String projectQuery(Project.NameKey proj) { 134 0 : return op("project", proj.get()); 135 : } 136 : 137 : public static String projectQuery(Project.NameKey proj, Status status) { 138 0 : return status(status) + " " + op("project", proj.get()); 139 : } 140 : 141 : public static String topicQuery(Status status, String topic) { 142 0 : switch (status) { 143 : case ABANDONED: 144 0 : return toChangeQuery(status(status) + " " + op("topic", topic)); 145 : case MERGED: 146 : case NEW: 147 0 : return toChangeQuery( 148 0 : op("topic", topic) + " (" + status(Status.NEW) + " OR " + status(Status.MERGED) + ")"); 149 : } 150 0 : return toChangeQuery(status(status) + " " + op("topic", topic)); 151 : } 152 : 153 : public static String toGroup(AccountGroup.UUID uuid) { 154 37 : return ADMIN_GROUPS + "uuid-" + uuid; 155 : } 156 : 157 : public static String toSettings(String pluginName, String path) { 158 0 : return SETTINGS_EXTENSION + pluginName + "/" + path; 159 : } 160 : 161 : public static String toDocumentationQuery(String query) { 162 0 : return DOCUMENTATION + KeyUtil.encode(query); 163 : } 164 : 165 : private static String status(Status status) { 166 0 : switch (status) { 167 : case ABANDONED: 168 0 : return "status:abandoned"; 169 : case MERGED: 170 0 : return "status:merged"; 171 : case NEW: 172 : default: 173 0 : return "status:open"; 174 : } 175 : } 176 : 177 : private static String toChangeNoSlash(@Nullable Project.NameKey project, Change.Id c) { 178 1 : if (project != null) { 179 1 : return "/c/" + project.get() + PROJECT_CHANGE_DELIMITER + c; 180 : } 181 0 : return "/c/" + c; 182 : } 183 : 184 : public static String op(String op, int value) { 185 0 : return op + ":" + value; 186 : } 187 : 188 : public static String op(String op, String value) { 189 0 : if (isSingleWord(value)) { 190 0 : return op + ":" + value; 191 : } 192 0 : return op + ":\"" + value + "\""; 193 : } 194 : 195 : private static boolean isSingleWord(String value) { 196 0 : if (value.startsWith("-")) { 197 0 : return false; 198 : } 199 0 : return value.matches("[^\u0000-\u0020!\"#$%&'():;?\\[\\]{}~]+"); 200 : } 201 : 202 0 : protected PageLinks() {} 203 : }