public class XWikiServletURLFactory extends XWikiDefaultURLFactory
Modifier and Type | Field and Description |
---|---|
protected String |
contextPath |
protected boolean |
daemon |
protected String |
defaultURL
Deprecated.
since 10.3, use #defaultURLs instead
|
protected Map<String,URL> |
defaultURLs
This is the URL which was requested by the user possibly with the host modified if x-forwarded-host header is set
or if xwiki.home parameter is set and we are viewing the main page.
|
protected URL |
originalURL |
Constructor and Description |
---|
XWikiServletURLFactory() |
XWikiServletURLFactory(URL defaultURL,
String contextPath,
String actionPath) |
XWikiServletURLFactory(XWikiContext context)
Creates a new URL factory that uses the server URL and context path specified by the given XWiki context.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addFileName(StringBuilder path,
String fileName,
boolean encode,
XWikiContext context) |
protected void |
addFileName(StringBuilder path,
String fileName,
XWikiContext context) |
URL |
createAttachmentRevisionURL(String filename,
String spaces,
String name,
String revision,
long recycleId,
String querystring,
String xwikidb,
XWikiContext context) |
URL |
createAttachmentRevisionURL(String filename,
String spaces,
String name,
String revision,
String querystring,
String xwikidb,
XWikiContext context) |
URL |
createAttachmentURL(String filename,
String spaces,
String name,
String action,
String querystring,
String xwikidb,
XWikiContext context) |
URL |
createExternalURL(String spaces,
String name,
String action,
String querystring,
String anchor,
String xwikidb,
XWikiContext context) |
URL |
createResourceURL(String filename,
boolean forceSkinAction,
XWikiContext context,
Map<String,Object> queryParameters)
Create an URL for the file resource.
|
URL |
createSkinURL(String filename,
String spaces,
String name,
String xwikidb,
XWikiContext context,
Map<String,Object> queryParameters)
Create an URL for the filename located in the spaces and with given repository.
|
URL |
createSkinURL(String filename,
String skin,
XWikiContext context,
Map<String,Object> queryParameters)
Create an URL for the given filename in the given skin directory.
|
URL |
createTemplateURL(String fileName,
XWikiContext context) |
URL |
createURL(String spaces,
String name,
String action,
boolean redirect,
XWikiContext context) |
URL |
createURL(String spaces,
String name,
String action,
String querystring,
String anchor,
String xwikidb,
XWikiContext context) |
XWikiAttachment |
findAttachmentForDocRevision(XWikiDocument doc,
String docRevision,
String filename,
XWikiContext context) |
long |
findDeletedAttachmentForDocRevision(XWikiDocument doc,
String docRevision,
String filename,
XWikiContext context) |
String |
getContextPath()
Returns the part of the URL identifying the web application.
|
protected URL |
getDefaultURL(String wikiId,
XWikiContext xcontext) |
URL |
getRequestURL(XWikiContext context) |
URL |
getServerURL(String wikiId,
XWikiContext context)
Get the url of the server EG: http://www.xwiki.org/ This function sometimes will return a URL with a trailing /
and other times not.
|
URL |
getServerURL(XWikiContext context)
Generate the base external URL to access this server.
|
String |
getURL(URL url,
XWikiContext context)
Converts a URL to a relative URL if it's a XWiki URL (keeping only the path + query string + anchor) and leave
the URL unchanged if it's an external URL.
|
void |
init(XWikiContext context) |
protected boolean |
isContextDoc(String wiki,
String spaces,
String name,
XWikiContext context)
Check if a document is the original context document.
|
protected static URL |
normalizeURL(String url,
XWikiContext context)
Encodes the passed URL and offers the possibility for Servlet Filter to perform URL rewriting (this is used for
example by Tuckey's URLRewriteFilter for rewriting outbound URLs, see
http://platform.xwiki.org/xwiki/bin/view/Main/ShortURLs).
|
protected static URL |
normalizeURL(URL url,
XWikiContext context)
Encodes the passed URL and offers the possibility for Servlet Filter to perform URL rewriting (this is used for
example by Tuckey's URLRewriteFilter for rewriting outbound URLs, see
http://platform.xwiki.org/xwiki/bin/view/Main/ShortURLs).
|
void |
setDefaultURL(String wikiId,
URL baseURL) |
createAttachmentRevisionURL, createAttachmentRevisionURL, createAttachmentURL, createExternalURL, createResourceURL, createSkinURL, createSkinURL, createSkinURL, createSkinURL, createURL, createURL, createURL
protected boolean daemon
protected URL originalURL
@Deprecated protected String defaultURL
defaultURLs
protected Map<String,URL> defaultURLs
protected String contextPath
public XWikiServletURLFactory()
public XWikiServletURLFactory(URL defaultURL, String contextPath, String actionPath)
public XWikiServletURLFactory(XWikiContext context)
XWikiContext.setURL(URL)
is called before this
constructor.context
- public void init(XWikiContext context)
public void setDefaultURL(String wikiId, URL baseURL)
wikiId
- the wiki identifier to associate with this URLbaseURL
- the input URL to take into account, null to disable itprotected URL getDefaultURL(String wikiId, XWikiContext xcontext)
public String getContextPath()
public URL getServerURL(XWikiContext context) throws MalformedURLException
XWikiURLFactory
context
- the XWiki context.MalformedURLException
- error when creating the URL
.public URL getServerURL(String wikiId, XWikiContext context) throws MalformedURLException
wikiId
- the identifier of the wiki, if null it is assumed to be the same as the wiki which we are currently
displaying.context
- the XWikiContext used to determine the current wiki and the value if the xwiki.home parameter if
needed as well as access the xwiki server document if in virtual mode.MalformedURLException
public URL createURL(String spaces, String name, String action, boolean redirect, XWikiContext context)
spaces
- a serialized space reference which can contain one or several spaces (e.g. "space1.space2"). If
a space name contains a dot (".") it must be passed escaped as in "space1\.with\.dot.space2"public URL createURL(String spaces, String name, String action, String querystring, String anchor, String xwikidb, XWikiContext context)
spaces
- a serialized space reference which can contain one or several spaces (e.g. "space1.space2"). If
a space name contains a dot (".") it must be passed escaped as in "space1\.with\.dot.space2"querystring
- the URL-encoded Query String. It's important to realize that the implementation of this
method cannot encode it automatically since the Query String is passed as a String (and it's not possible
to differentiate between a '=' character that should be encoded and one that shouldn't. Imagine an input
of 'a=&b=c' which can be understood either as 'a' = '&b=c' or as 'a' = '' and 'b' = 'c'). Ideally
we would need an API signature that accepts a Map<String, String>
for the Query String, for
exampleprotected void addFileName(StringBuilder path, String fileName, XWikiContext context)
protected void addFileName(StringBuilder path, String fileName, boolean encode, XWikiContext context)
public URL createExternalURL(String spaces, String name, String action, String querystring, String anchor, String xwikidb, XWikiContext context)
spaces
- a serialized space reference which can contain one or several spaces (e.g. "space1.space2"). If
a space name contains a dot (".") it must be passed escaped as in "space1\.with\.dot.space2"querystring
- the URL-encoded Query String. It's important to realize that the implementation of this
method cannot encode it automatically since the Query String is passed as a String (and it's not possible
to differentiate between a '=' character that should be encoded and one that shouldn't. Imagine an input
of 'a=&b=c' which can be understood either as 'a' = '&b=c' or as 'a' = '' and 'b' = 'c'). Ideally
we would need an API signature that accepts a Map<String, String>
for the Query String, for
examplepublic URL createSkinURL(String filename, String skin, XWikiContext context, Map<String,Object> queryParameters)
XWikiURLFactory
filename
- the file to reach.skin
- the skin where the file should be loadedcontext
- current contextqueryParameters
- the parameters to put at the end of the URLpublic URL createSkinURL(String filename, String spaces, String name, String xwikidb, XWikiContext context, Map<String,Object> queryParameters)
XWikiURLFactory
filename
- the path of the file to reach.spaces
- the spaces where the file is located.name
- the directory where the file is located.xwikidb
- the wiki in which the file is located.context
- current context.queryParameters
- parameters to put at the end of the URL.public URL createResourceURL(String filename, boolean forceSkinAction, XWikiContext context, Map<String,Object> queryParameters)
XWikiURLFactory
filename
- the path of the file to load.forceSkinAction
- if true specify the skin directory in the URL.context
- the current context.queryParameters
- the parameters to put at the end of the URL.public URL createTemplateURL(String fileName, XWikiContext context)
public URL createAttachmentURL(String filename, String spaces, String name, String action, String querystring, String xwikidb, XWikiContext context)
spaces
- a serialized space reference which can contain one or several spaces (e.g. "space1.space2"). If
a space name contains a dot (".") it must be passed escaped as in "space1\.with\.dot.space2"querystring
- the URL-encoded Query String. It's important to realize that the implementation of this
method cannot encode it automatically since the Query String is passed as a String (and it's not possible
to differentiate between a '=' character that should be encoded and one that shouldn't. Imagine an input
of 'a=&b=c' which can be understood either as 'a' = '&b=c' or as 'a' = '' and 'b' = 'c'). Ideally
we would need an API signature that accepts a Map<String, String>
for the Query String, for
exampleprotected boolean isContextDoc(String wiki, String spaces, String name, XWikiContext context)
wiki
- the wiki name of the document to checkspaces
- the space names of the document to checkname
- the document name of the document to checkcontext
- the current request contexttrue
if the provided document is the same as the current context document, false
otherwisepublic URL createAttachmentRevisionURL(String filename, String spaces, String name, String revision, String querystring, String xwikidb, XWikiContext context)
spaces
- a serialized space reference which can contain one or several spaces (e.g. "space1.space2"). If
a space name contains a dot (".") it must be passed escaped as in "space1\.with\.dot.space2"querystring
- the URL-encoded Query String. It's important to realize that the implementation of this
method cannot encode it automatically since the Query String is passed as a String (and it's not possible
to differentiate between a '=' character that should be encoded and one that shouldn't. Imagine an input
of 'a=&b=c' which can be understood either as 'a' = '&b=c' or as 'a' = '' and 'b' = 'c'). Ideally
we would need an API signature that accepts a Map<String, String>
for the Query String, for
examplepublic URL createAttachmentRevisionURL(String filename, String spaces, String name, String revision, long recycleId, String querystring, String xwikidb, XWikiContext context)
public String getURL(URL url, XWikiContext context)
An URL is considered to be external if its server component doesn't match the server of the current request URL. This means that URLs are made relative with respect to the current request URL rather than the current wiki set on the XWiki context. Let's take an example:
request URL: http://playground.xwiki.org/xwiki/bin/view/Sandbox/TestURL
current wiki: code (code.xwiki.org)
URL (1): http://code.xwiki.org/xwiki/bin/view/Main/WebHome
URL (2): http://playground.xwiki.org/xwiki/bin/view/Spage/Page
The result will be:
(1) http://code.xwiki.org/xwiki/bin/view/Main/WebHome
(2) /xwiki/bin/view/Spage/Page
getURL
in interface XWikiURLFactory
getURL
in class XWikiDefaultURLFactory
url
- the URL to convertXWikiDefaultURLFactory.getURL(java.net.URL, com.xpn.xwiki.XWikiContext)
public URL getRequestURL(XWikiContext context)
getRequestURL
in interface XWikiURLFactory
getRequestURL
in class XWikiDefaultURLFactory
public XWikiAttachment findAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename, XWikiContext context) throws XWikiException
XWikiException
public long findDeletedAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename, XWikiContext context) throws XWikiException
XWikiException
protected static URL normalizeURL(URL url, XWikiContext context) throws MalformedURLException
However Servlet Container will also add a ";jsessionid=xxx" content to the URL while encoding the URL and we strip it since we don't want to have that in our URLs as it can cause issues with:
url
- the URL to encode and normalizecontext
- the XWiki Context used to get access to the Response for encoding the URLMalformedURLException
- if the passed URL is invalidprotected static URL normalizeURL(String url, XWikiContext context) throws MalformedURLException
However Servlet Container will also add a ";jsessionid=xxx" content to the URL while encoding the URL and we strip it since we don't want to have that in our URLs as it can cause issues with:
url
- the URL to encode and normalizecontext
- the XWiki Context used to get access to the Response for encoding the URLMalformedURLException
- if the passed URL is invalidCopyright © 2004–2021 XWiki. All rights reserved.