Package com.xpn.xwiki.web
Class XWikiServletURLFactory
- java.lang.Object
-
- com.xpn.xwiki.web.XWikiDefaultURLFactory
-
- com.xpn.xwiki.web.XWikiServletURLFactory
-
- All Implemented Interfaces:
XWikiURLFactory
- Direct Known Subclasses:
ExportURLFactory
,ExternalServletURLFactory
,FileSystemURLFactory
public class XWikiServletURLFactory extends XWikiDefaultURLFactory
-
-
Field Summary
Fields Modifier and Type Field Description protected String
contextPath
protected boolean
daemon
protected String
defaultURL
Deprecated.since 10.3, use #defaultURLs insteadprotected 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 Summary
Constructors Constructor Description XWikiServletURLFactory()
XWikiServletURLFactory(XWikiContext context)
Creates a new URL factory that uses the server URL and context path specified by the given XWiki context.XWikiServletURLFactory(URL defaultURL, String contextPath, String actionPath)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 skin, XWikiContext context, Map<String,Object> queryParameters)
Create an URL for the given filename in the given skin directory.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
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(XWikiContext context)
Generate the base external URL to access this server.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.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)
-
Methods inherited from class com.xpn.xwiki.web.XWikiDefaultURLFactory
createAttachmentRevisionURL, createAttachmentRevisionURL, createAttachmentURL, createExternalURL, createResourceURL, createSkinURL, createSkinURL, createSkinURL, createSkinURL, createURL, createURL, createURL
-
-
-
-
Field Detail
-
daemon
protected boolean daemon
-
originalURL
protected URL originalURL
-
defaultURL
@Deprecated protected String defaultURL
Deprecated.since 10.3, use #defaultURLs instead- See Also:
defaultURLs
-
defaultURLs
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.
-
contextPath
protected String contextPath
-
-
Constructor Detail
-
XWikiServletURLFactory
public XWikiServletURLFactory()
-
XWikiServletURLFactory
public XWikiServletURLFactory(URL defaultURL, String contextPath, String actionPath)
-
XWikiServletURLFactory
public XWikiServletURLFactory(XWikiContext context)
Creates a new URL factory that uses the server URL and context path specified by the given XWiki context. This constructor should be used only in tests. Make sureXWikiContext.setURL(URL)
is called before this constructor.- Parameters:
context
-
-
-
Method Detail
-
init
public void init(XWikiContext context)
-
setDefaultURL
public void setDefaultURL(String wikiId, URL baseURL)
- Parameters:
wikiId
- the wiki identifier to associate with this URLbaseURL
- the input URL to take into account, null to disable it- Since:
- 10.3
-
getDefaultURL
protected URL getDefaultURL(String wikiId, XWikiContext xcontext)
-
getContextPath
public String getContextPath()
Returns the part of the URL identifying the web application. In a normal install, that isxwiki/
.- Returns:
- The configured context path.
-
getServerURL
public URL getServerURL(XWikiContext context) throws MalformedURLException
Description copied from interface:XWikiURLFactory
Generate the base external URL to access this server.- Parameters:
context
- the XWiki context.- Returns:
- the URL of the server.
- Throws:
MalformedURLException
- error when creating theURL
.
-
getServerURL
public URL getServerURL(String wikiId, XWikiContext context) throws MalformedURLException
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. This is because the xwiki.home param is recommended to have a trailing / but this.serverURL never does.- Parameters:
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.- Returns:
- a URL containing the protocol, host, and port (if applicable) of the server to use for the given database.
- Throws:
MalformedURLException
-
createURL
public URL createURL(String spaces, String name, String action, boolean redirect, XWikiContext context)
- Parameters:
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"
-
createURL
public URL createURL(String spaces, String name, String action, String querystring, String anchor, String xwikidb, XWikiContext context)
- Parameters:
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 aMap<String, String>
for the Query String, for example
-
addFileName
protected void addFileName(StringBuilder path, String fileName, XWikiContext context)
-
addFileName
protected void addFileName(StringBuilder path, String fileName, boolean encode, XWikiContext context)
-
createExternalURL
public URL createExternalURL(String spaces, String name, String action, String querystring, String anchor, String xwikidb, XWikiContext context)
- Parameters:
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 aMap<String, String>
for the Query String, for example
-
createSkinURL
public URL createSkinURL(String filename, String skin, XWikiContext context, Map<String,Object> queryParameters)
Description copied from interface:XWikiURLFactory
Create an URL for the given filename in the given skin directory.- Parameters:
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 URL- Returns:
- a URL to load the given file with the given query parameters.
-
createSkinURL
public URL createSkinURL(String filename, String spaces, String name, String xwikidb, XWikiContext context, Map<String,Object> queryParameters)
Description copied from interface:XWikiURLFactory
Create an URL for the filename located in the spaces and with given repository.- Parameters:
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.- Returns:
- an URL to load the given file.
-
createResourceURL
public URL createResourceURL(String filename, boolean forceSkinAction, XWikiContext context, Map<String,Object> queryParameters)
Description copied from interface:XWikiURLFactory
Create an URL for the file resource.- Parameters:
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.- Returns:
- an URL to load the given file
-
createTemplateURL
public URL createTemplateURL(String fileName, XWikiContext context)
-
createAttachmentURL
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 aMap<String, String>
for the Query String, for example
-
isContextDoc
protected boolean isContextDoc(String wiki, String spaces, String name, XWikiContext context)
Check if a document is the original context document. This is needed when generating attachment revision URLs, since only attachments of the context document should also be versioned.- Parameters:
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 context- Returns:
true
if the provided document is the same as the current context document,false
otherwise
-
createAttachmentRevisionURL
public 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 aMap<String, String>
for the Query String, for example
-
createAttachmentRevisionURL
public URL createAttachmentRevisionURL(String filename, String spaces, String name, String revision, long recycleId, String querystring, String xwikidb, XWikiContext context)
-
getURL
public 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.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
- Specified by:
getURL
in interfaceXWikiURLFactory
- Overrides:
getURL
in classXWikiDefaultURLFactory
- Parameters:
url
- the URL to convert- Returns:
- the converted URL as a string
- See Also:
XWikiDefaultURLFactory.getURL(java.net.URL, com.xpn.xwiki.XWikiContext)
-
getRequestURL
public URL getRequestURL(XWikiContext context)
- Specified by:
getRequestURL
in interfaceXWikiURLFactory
- Overrides:
getRequestURL
in classXWikiDefaultURLFactory
-
findAttachmentForDocRevision
public XWikiAttachment findAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename, XWikiContext context) throws XWikiException
- Throws:
XWikiException
-
findDeletedAttachmentForDocRevision
public long findDeletedAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename, XWikiContext context) throws XWikiException
- Throws:
XWikiException
-
normalizeURL
protected static URL normalizeURL(URL url, XWikiContext context) throws MalformedURLException
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).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:
- security
- SEO
- clients not expecting jsessionid in URL, for example RSS feed readers which will think that articles are different as they'll get different URLs everytime they call the XWiki server
- Parameters:
url
- the URL to encode and normalizecontext
- the XWiki Context used to get access to the Response for encoding the URL- Returns:
- the normalized URL
- Throws:
MalformedURLException
- if the passed URL is invalid
-
normalizeURL
protected static URL normalizeURL(String url, XWikiContext context) throws MalformedURLException
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).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:
- security
- SEO
- clients not expecting jsessionid in URL, for example RSS feed readers which will think that articles are different as they'll get different URLs everytime they call the XWiki server
- Parameters:
url
- the URL to encode and normalizecontext
- the XWiki Context used to get access to the Response for encoding the URL- Returns:
- the normalized URL
- Throws:
MalformedURLException
- if the passed URL is invalid
-
-