public interface

NavBuilder

com.atlassian.bitbucket.nav.NavBuilder

Class Overview

Helps build URLs using a fluent interface. All returned URLs are URL encoded. Example usages:

  • nb.allProjects().startAt(0).withLimit(25).buildAbsolute() => http://localhost:7990/bitbucket/projects?start=0&limit=25
  • nb.project("EX").repo("example").settings().buildRelative() => /stash/projects/EX/repos/example/settings
  • nb.project("EX").repo("example").browse().resource("foo/bar/baz.xml").buildNoContext() => /projects/EX/repos/example/browse/foo/bar/baz.xml
  • nb.project("EX").repo("example").browse().resource("foo/bar/baz.xml").onBranch("stash1.0").buildNoContext() => /projects/EX/repos/example/browse/foo/bar/baz.xml?branchName=stash1.0
  • nb.project("EX").repo("example").pullRequest("7636").buildNoContext() => /projects/EX/repos/example/pull-request/7636

Summary

Nested Classes
interface NavBuilder.AddonRequests  
interface NavBuilder.Addons  
interface NavBuilder.Admin The builder for /admin  
interface NavBuilder.BrowseRepoResource The builder of urls of the form /projects/PROJ/repos/REPO/browse[/...]  
interface NavBuilder.Builder<B extends Builder> Base interface for all terminal builders (builders which can produce a url)  
interface NavBuilder.Commit Builds URLs of the form /projects/PROJ/repos/REPO/commits/ID  
interface NavBuilder.CommitComment Builds URLs of the form /projects/PROJ/repos/REPO/commits/ID/comment/ID  
interface NavBuilder.Compare The builder of urls of the form /projects/PROJ/repos/REPO/compare  
interface NavBuilder.CompareBuilder<T extends CompareBuilder>  
interface NavBuilder.CreateProject The builder of urls of the form /projects/PROJ?create  
interface NavBuilder.CreatePullRequest The builder for urls of the form /projects/PROJ/repos/REPO/pull-requets?create... 
interface NavBuilder.CreateRepo The builder of urls of the form /projects/PROJ/repos?create  
interface NavBuilder.Database  
interface NavBuilder.DeleteGroup  
interface NavBuilder.DeleteUser The builder for /users/delete  
interface NavBuilder.GettingStarted Builds a URL to the GettingStarted page with an option of adding "next" as a query parameter with the current request url or the passed in url  
interface NavBuilder.GlobalListRepos The builder for /repos  
interface NavBuilder.Groups  
interface NavBuilder.Licensing  
interface NavBuilder.ListBranches The builder of urls of the form /projects/PROJ/repos/REPO/branches  
interface NavBuilder.ListCommits The builder of urls of the form /projects/PROJ/repos/REPO/commits  
interface NavBuilder.ListProjects The builder for /projects  
interface NavBuilder.ListPullRequests  
interface NavBuilder.ListRepos The builder for /projects/PROJ/repos/REPO/browse - essentially the same as NavBuilder.Project but with support for start and limit params to control the repository list  
interface NavBuilder.ListTags The builder of urls of the form /projects/PROJ/repos/REPO/tags[/...]  
interface NavBuilder.Login Builds a login URL for the with an option of adding "next" as a query parameter with the current request url or the passed in url  
interface NavBuilder.NavigationStep<B extends NavigationStep<B>> Builds URL for the with an option of adding "next" as a query parameter with the current request url or the passed in url  
interface NavBuilder.PagedBuilder<B extends PagedBuilder> A builder for urls that represent a collection of things, one page at a time. 
interface NavBuilder.PathBuilder<B extends PathBuilder> The builder of urls that have a path to a file resource  
interface NavBuilder.PluginServlets The builder for the plugin servlets  
interface NavBuilder.Profile  
interface NavBuilder.Project The builder for urls hanging off /projects/PROJ. 
interface NavBuilder.ProjectDelete The builder of urls of the form /projects/PROJ/delete  
interface NavBuilder.ProjectPermissions The builder of urls of the form /projects/PROJ/permissions  
interface NavBuilder.ProjectSettings The builder of urls of the form /projects/PROJ/settings  
interface NavBuilder.PullRequest The builder for urls of the form /projects/PROJ/repos/REPO/pull-requets/ID/... 
interface NavBuilder.PullRequestActivity Builds URLs of the form /projects/PROJ/repos/REPO/pull-requests/ID/activities  
interface NavBuilder.PullRequestComment Builds URLs of the form /projects/PROJ/repos/REPO/pull-requests/ID/overview?commentId=ID  
interface NavBuilder.PullRequestCommit Builds URLs of the form /projects/PROJ/repos/REPO/pull-requests/ID/commits/ID  
interface NavBuilder.PullRequestOverview Builds URLs of the form /projects/PROJ/repos/REPO/pull-requests/ID/overview  
interface NavBuilder.PullRequestRepoSettings The builder of urls of the form /projects/PROJ/repos/REPO/settings/pull-requests  
interface NavBuilder.Repo The builder of urls hanging off /projects/PROJ/repos/REPO. 
interface NavBuilder.RepoAttachments The builder of urls of the form /projects/PROJ/repos/REPO/attachments  
interface NavBuilder.RepoDelete The builder of urls of the form /projects/PROJ/repos/REPO/delete  
interface NavBuilder.RepoFork The builder for urls of the form /projects/PROJ/repos/REPO?fork  
interface NavBuilder.RepoHooks The builder of urls of the form /projects/PROJ/repos/REPO/hooks  
interface NavBuilder.RepoPermissions  
interface NavBuilder.RepoSettings The builder of urls of the form /projects/PROJ/repos/REPO/settings  
interface NavBuilder.Rest The builder for the REST API  
interface NavBuilder.RestAdmin The builder for the REST admin API  
interface NavBuilder.RestHook The builder of urls of the form /rest/hooks/KEY  
interface NavBuilder.RestHooks The builder of urls of the form /rest/hooks  
interface NavBuilder.RestUser The builder for /rest/users/slug  
interface NavBuilder.RestUsers The builder for /rest/users  
interface NavBuilder.RevisionBrowse The builder for urls of the form /projects/PROJ/repos/REPO/browse/...?at=REVISION  
interface NavBuilder.Tmp Group builder for endpoints under /tmp, which are intended to provide access to temporary data stored by the system to facilitate user actions. 
interface NavBuilder.UpgradeOnboarding Builds a URL to the UpgradeOnboarding page with an option of adding "next" as a query parameter with the current request url or the passed in url  
interface NavBuilder.UserAccount The builder for /account  
interface NavBuilder.Users  
interface NavBuilder.ViewGroup The builder for /group/view  
interface NavBuilder.ViewUser The builder for /users/view  
Constants
String BASE_URL_KEY A key which is wrapped in TOKEN_PREFIX and TOKEN_SUFFIX to produce a base URL token.
String BASE_URL_TOKEN The fully-computed base URL token, comprised of TOKEN_PREFIX, BASE_URL_KEY and TOKEN_SUFFIX.
String TOKEN_PREFIX A prefix which is applied to the beginning of tokens which are emitted in built URLs.
String TOKEN_SUFFIX A suffix which is appended to the ending of tokens which are emitted in built URLs.
String USE_BASE_URL_TOKEN The query parameter on the request which indicates the base URL on emitted URLs should be replaced with BASE_URL_TOKEN instead.
Public Methods
Builder<?> about()
NavBuilder.UserAccount account()
NavBuilder.Addons addons()
NavBuilder.Admin admin()
NavBuilder.ListProjects allProjects()
/projects
NavBuilder.GlobalListRepos allRepos()
/repos
String buildAbsolute()
This method respects the USE_BASE_URL_TOKEN parameter if present on the context request.
String buildBaseUrl()
This method does not respect the USE_BASE_URL_TOKEN parameter.
String buildConfigured()
This method is equivalent to buildAbsolute(), but ignores any context HTTP request and always uses the server's configured base URL for generating the scheme, host, port etc and webapp context components of the URL.
String buildRelative()
Builder<?> captcha()
/captcha
NavBuilder.CreateProject createProject()
NavBuilder.GettingStarted gettingStarted()
/getting-started
NavBuilder.Login login()
/login
Builder<?> logout()
/login
Builder<?> passwordReset()
/passwordreset
NavBuilder.PluginServlets pluginServlets()
NavBuilder.Profile profile()
/profile
NavBuilder.Project project(Project project)
/projects/PROJ
NavBuilder.Project project(String key)
/projects/PROJ
NavBuilder.Repo repo(Repository repository)
/projects/PROJ/repos/REPO
NavBuilder.Rest rest()
Builder<?> retrievePassword()
/retrievePassword
Builder<?> securityCheck()
/j_atl_security_check
Builder<?> setup()
/setup
Builder<?> signup()
/signup
NavBuilder.Tmp tmp()
/tmp

Retrieve a builder for constructing URLs related to temporary data.

NavBuilder.UpgradeOnboarding upgradeOnboarding()
/upgrade-onboarding
NavBuilder.Profile user(ApplicationUser user)
/users/SLUG or /bots/SLUG
NavBuilder.Profile userBySlug(String userSlug, UserType type)
/users/SLUG or /bots/SLUG
Builder<?> xsrfNotification()
/mvc/xsrfNotification (as this is generated by a forward it doesn't go through the rewrite filter, and so needs the /mvc explicitly)

Constants

public static final String BASE_URL_KEY

A key which is wrapped in TOKEN_PREFIX and TOKEN_SUFFIX to produce a base URL token.

The key used needs to contain (preferably end with) something which is escaped when URL-encoded. Doing so causes the end token to be different depending on whether the base URL has been encoded and allows callers to encode the value they replace it with. That, in turn, ensures the resulting full URL has correct encoding from beginning to end.

Over and above containing something which requires encoding, the value needs to encode reliably. That means if the token has been encoded 4 times, any caller performing the substitution should be able to detect that count, because they will need to encode the replacement value 4 times over as well.

The current choice is a single trailing %. On first encoding, this produces "%25"; second produces "%2525", third produces "%252525", etc. This allows for two use cases:

  1. I don't care about encoding: Use a regular expression which ignores any number of 25s after the trailing % and before the closing TOKEN_SUFFIX
  2. I want to encode by depth: Use the index of TOKEN_PREFIX + this key to find the first 25, if any are present, and the location of the first TOKEN_SUFFIX to find the end. Use the number of 25s present to determine the depth

Constant Value: "stash.baseUrl%"

public static final String BASE_URL_TOKEN

The fully-computed base URL token, comprised of TOKEN_PREFIX, BASE_URL_KEY and TOKEN_SUFFIX.

Constant Value: "$$$$stash.baseUrl%$$$$"

public static final String TOKEN_PREFIX

A prefix which is applied to the beginning of tokens which are emitted in built URLs.

Constant Value: "$$$$"

public static final String TOKEN_SUFFIX

A suffix which is appended to the ending of tokens which are emitted in built URLs.

Constant Value: "$$$$"

public static final String USE_BASE_URL_TOKEN

The query parameter on the request which indicates the base URL on emitted URLs should be replaced with BASE_URL_TOKEN instead. Using this token allows callers to format in their own base URL for producing links which are correct based on their context.

For example, to better explain the need for this, consider the following:

  • A JIRA instance is running with a public address of http://jira.example.com
  • A Stash instance is running with a public address of http://stash.example.com
  • These two machines, in addition to having public-facing URLs, have a private backplane network which connects them as jira.private.example.com and stash.private.example.com
  • The application link from JIRA to Stash has an RPC URL of http://stash.private.example.com, so that RPC uses the fast backplane network, and a display URL of http://stash.example.com so that end users get valid links
  • When requests come into Stash, if the base URL calculated by buildAbsolute() uses the HTTP request (which is the default behaviour), links are emitted pointing to http://stash.private.example.com. From an end user's browser, however, such links will not work
  • Rather than trying to manually munge the URLs in the client, which is problematic and brittle, the caller can add this parameter to their request and a token suitable for replacement will be emitted in the URLs instead of a fixed base URL

Constant Value: "useBaseUrlToken"

Public Methods

public Builder<?> about ()

public NavBuilder.UserAccount account ()

Returns
  • a builder for urls of the form /account[/*]

public NavBuilder.Addons addons ()

Returns
  • a builder for UPM created URLs

public NavBuilder.Admin admin ()

public NavBuilder.ListProjects allProjects ()

/projects

Returns
  • a builder for the url to list all projects

public NavBuilder.GlobalListRepos allRepos ()

/repos

Returns
  • a builder for the url to list all repositories

public String buildAbsolute ()

This method respects the USE_BASE_URL_TOKEN parameter if present on the context request. Use buildBaseUrl() if you with to avoid this behaviour. Note: if the USE_BASE_URL_TOKEN is present this method may return a String that is not a syntactically valid URI. The base URL (the scheme, host, port etc and webapp context) will be taken from the context HTTP request, if one is present, or otherwise fall back to the configured base URL for the server.

Returns
  • the absolute base url (e.g. http://hostname:7990/context), with no trailing slash

public String buildBaseUrl ()

This method does not respect the USE_BASE_URL_TOKEN parameter. Unless you have a specific need to avoid the token substitution behaviour for this particular URL, you should use buildAbsolute().

Returns
  • the absolute base url (e.g. http://hostname:7990/context), with no trailing slash

public String buildConfigured ()

This method is equivalent to buildAbsolute(), but ignores any context HTTP request and always uses the server's configured base URL for generating the scheme, host, port etc and webapp context components of the URL.

Returns

public String buildRelative ()

Returns
  • the relative base url (e.g. /context), with no trailing slash

public Builder<?> captcha ()

/captcha

Returns
  • a builder for the url to the captcha image

public NavBuilder.CreateProject createProject ()

Returns
  • a builder for urls of the form /projects?create

public NavBuilder.GettingStarted gettingStarted ()

/getting-started

Returns
  • a builder for urls to the Getting Started '/getting-started' page

public NavBuilder.Login login ()

/login

Returns
  • a Login builder for the url to the login page

public Builder<?> logout ()

/login

Returns
  • a builder for the url to the logout page

public Builder<?> passwordReset ()

/passwordreset

Returns
  • a builder for the url to the page to reset your password

public NavBuilder.PluginServlets pluginServlets ()

public NavBuilder.Profile profile ()

/profile

Returns
  • a builder for the url to the profile page of the current user

public NavBuilder.Project project (Project project)

/projects/PROJ

Returns
  • a builder for urls of the named project

public NavBuilder.Project project (String key)

/projects/PROJ

Returns
  • a builder for urls of the named project

public NavBuilder.Repo repo (Repository repository)

/projects/PROJ/repos/REPO

Returns
  • a builder for urls of the named repository

public NavBuilder.Rest rest ()

public Builder<?> retrievePassword ()

/retrievePassword

Returns
  • a builder for the url to the page to retrieve your password

public Builder<?> securityCheck ()

/j_atl_security_check

Returns
  • a builder for the url used to check authentication credentials when logging in

public Builder<?> setup ()

/setup

Returns
  • a builder for the first run wizard

public Builder<?> signup ()

/signup

Returns
  • a builder for the url to the signup page

public NavBuilder.Tmp tmp ()

/tmp

Retrieve a builder for constructing URLs related to temporary data.

Returns
  • a builder for temporary data URLs

public NavBuilder.UpgradeOnboarding upgradeOnboarding ()

/upgrade-onboarding

Returns
  • a builder for urls to the Upgrade Onboarding '/upgrade-onboarding' page

public NavBuilder.Profile user (ApplicationUser user)

/users/SLUG or /bots/SLUG

Returns
  • a builder for the url to the profile page of the supplied user

public NavBuilder.Profile userBySlug (String userSlug, UserType type)

/users/SLUG or /bots/SLUG

Returns
  • a builder for the url to the profile page of the supplied user's slug

public Builder<?> xsrfNotification ()

/mvc/xsrfNotification (as this is generated by a forward it doesn't go through the rewrite filter, and so needs the /mvc explicitly)

Returns
  • a builder for the url to use when an invalid xsrf token is detected.