com.xpn.xwiki.web
Class XWikiServletURLFactory

java.lang.Object
  extended by com.xpn.xwiki.web.XWikiDefaultURLFactory
      extended by com.xpn.xwiki.web.XWikiServletURLFactory
All Implemented Interfaces:
XWikiURLFactory
Direct Known Subclasses:
ExportURLFactory, ExternalServletURLFactory, FileSystemURLFactory, XWikiDebugGWTURLFactory, XWikiXmlRpcURLFactory

public class XWikiServletURLFactory
extends XWikiDefaultURLFactory


Field Summary
protected  String contextPath
           
protected  URL serverURL
          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.
 
Constructor Summary
XWikiServletURLFactory()
           
XWikiServletURLFactory(URL serverURL, 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.
 
Method Summary
protected  void addFileName(StringBuffer newpath, String filename, boolean encode, XWikiContext context)
           
protected  void addFileName(StringBuffer newpath, String filename, XWikiContext context)
           
 URL createAttachmentRevisionURL(String filename, String web, String name, String revision, long recycleId, String querystring, String xwikidb, XWikiContext context)
           
 URL createAttachmentRevisionURL(String filename, String web, String name, String revision, String querystring, String xwikidb, XWikiContext context)
           
 URL createAttachmentURL(String filename, String web, String name, String action, String querystring, String xwikidb, XWikiContext context)
           
 URL createExternalURL(String web, String name, String action, String querystring, String anchor, String xwikidb, XWikiContext context)
           
 URL createResourceURL(String filename, boolean forceSkinAction, XWikiContext context)
           
 URL createSkinURL(String filename, String web, String name, String xwikidb, XWikiContext context)
           
 URL createSkinURL(String filename, String skin, XWikiContext context)
           
 URL createTemplateURL(String filename, XWikiContext context)
           
 URL createURL(String web, String name, String action, boolean redirect, XWikiContext context)
           
 URL createURL(String web, 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.
 URL getRequestURL(XWikiContext context)
           
 URL getServerURL(String xwikidb, 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 space, 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).
 
Methods inherited from class com.xpn.xwiki.web.XWikiDefaultURLFactory
createAttachmentRevisionURL, createAttachmentRevisionURL, createAttachmentURL, createExternalURL, createSkinURL, createURL, createURL, createURL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serverURL

protected URL serverURL
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 serverURL,
                              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 sure XWikiContext.setURL(URL) is called before this constructor.

Parameters:
context -
Method Detail

init

public void init(XWikiContext context)

getContextPath

public String getContextPath()
Returns the part of the URL identifying the web application. In a normal install, that is xwiki/.

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 the URL.

getServerURL

public URL getServerURL(String xwikidb,
                        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:
xwikidb - the name of the database (subwiki) 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 web,
                     String name,
                     String action,
                     boolean redirect,
                     XWikiContext context)

createURL

public URL createURL(String web,
                     String name,
                     String action,
                     String querystring,
                     String anchor,
                     String xwikidb,
                     XWikiContext context)

addFileName

protected void addFileName(StringBuffer newpath,
                           String filename,
                           XWikiContext context)

addFileName

protected void addFileName(StringBuffer newpath,
                           String filename,
                           boolean encode,
                           XWikiContext context)

createExternalURL

public URL createExternalURL(String web,
                             String name,
                             String action,
                             String querystring,
                             String anchor,
                             String xwikidb,
                             XWikiContext context)

createSkinURL

public URL createSkinURL(String filename,
                         String skin,
                         XWikiContext context)

createSkinURL

public URL createSkinURL(String filename,
                         String web,
                         String name,
                         String xwikidb,
                         XWikiContext context)

createResourceURL

public URL createResourceURL(String filename,
                             boolean forceSkinAction,
                             XWikiContext context)

createTemplateURL

public URL createTemplateURL(String filename,
                             XWikiContext context)

createAttachmentURL

public URL createAttachmentURL(String filename,
                               String web,
                               String name,
                               String action,
                               String querystring,
                               String xwikidb,
                               XWikiContext context)

isContextDoc

protected boolean isContextDoc(String wiki,
                               String space,
                               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 check
space - the space name of the document to check
name - the document name of the document to check
context - 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 web,
                                       String name,
                                       String revision,
                                       String querystring,
                                       String xwikidb,
                                       XWikiContext context)

createAttachmentRevisionURL

public URL createAttachmentRevisionURL(String filename,
                                       String web,
                                       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 interface XWikiURLFactory
Overrides:
getURL in class XWikiDefaultURLFactory
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 interface XWikiURLFactory
Overrides:
getRequestURL in class XWikiDefaultURLFactory

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:

See why jsessionid are considered harmful here and here

Parameters:
url - the URL to encode and normalize
context - 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:

See why jsessionid are considered harmful here and here

Parameters:
url - the URL to encode and normalize
context - 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


Copyright © 2004–2014 XWiki. All rights reserved.