@Test public void getURLWhenRequestWikiAndContextWikiAreDifferent() throws MalformedURLException { initRequest("wiki1server", -1); this.oldcore.getXWikiContext().setWikiId("wiki2"); String url = urlFactory.getURL(new URL("http: assertEquals("/xwiki/bin/view/Space/Page", url); url = urlFactory.getURL(new URL("http: assertEquals("http: }
@Override public String getURL(URL url, XWikiContext context) { String relativeURL = ""; try { if (url != null) { String surl = url.toString(); URL referenceURL = getOriginalURL(context); if (referenceURL == null || !surl.startsWith(referenceURL.toString())) { relativeURL = surl; } else { StringBuilder relativeURLBuilder = new StringBuilder(url.getPath()); String querystring = url.getQuery(); if (!StringUtils.isEmpty(querystring)) { relativeURLBuilder.append("?") .append(StringUtils.removeEnd(StringUtils.removeEnd(querystring, "&"), "&amp;")); } String anchor = url.getRef(); if (!StringUtils.isEmpty(anchor)) { relativeURLBuilder.append("#").append(anchor); } relativeURL = relativeURLBuilder.toString(); } } } catch (Exception e) { LOGGER.error("Failed to create URL", e); } return StringUtils.defaultIfEmpty(relativeURL, "/"); }
XWikiServletURLFactory extends XWikiDefaultURLFactory { @Override public String getURL(URL url, XWikiContext context) { String relativeURL = ""; try { if (url != null) { String surl = url.toString(); URL referenceURL = getOriginalURL(context); if (referenceURL == null || !surl.startsWith(referenceURL.toString())) { relativeURL = surl; } else { StringBuilder relativeURLBuilder = new StringBuilder(url.getPath()); String querystring = url.getQuery(); if (!StringUtils.isEmpty(querystring)) { relativeURLBuilder.append("?") .append(StringUtils.removeEnd(StringUtils.removeEnd(querystring, "&"), "&amp;")); } String anchor = url.getRef(); if (!StringUtils.isEmpty(anchor)) { relativeURLBuilder.append("#").append(anchor); } relativeURL = relativeURLBuilder.toString(); } } } catch (Exception e) { LOGGER.error("Failed to create URL", e); } return StringUtils.defaultIfEmpty(relativeURL, "/"); } }
XWikiServletURLFactory extends XWikiDefaultURLFactory { @Override public String getURL(URL url, XWikiContext context) { String relativeURL = ""; try { if (url != null) { String surl = url.toString(); URL referenceURL = getOriginalURL(context); if (referenceURL == null || !surl.startsWith(referenceURL.toString())) { relativeURL = surl; } else { StringBuilder relativeURLBuilder = new StringBuilder(url.getPath()); String querystring = url.getQuery(); if (!StringUtils.isEmpty(querystring)) { relativeURLBuilder.append("?") .append(StringUtils.removeEnd(StringUtils.removeEnd(querystring, "&"), "&amp;")); } String anchor = url.getRef(); if (!StringUtils.isEmpty(anchor)) { relativeURLBuilder.append("#").append(anchor); } relativeURL = relativeURLBuilder.toString(); } } } catch (Exception e) { LOGGER.error("Failed to create URL", e); } return StringUtils.defaultIfEmpty(relativeURL, "/"); } XWikiServletURLFactory();  XWikiServletURLFactory(URL defaultURL, String contextPath, String actionPath);  XWikiServletURLFactory(XWikiContext context); }
XWikiServletURLFactory extends XWikiDefaultURLFactory { @Override public String getURL(URL url, XWikiContext context) { String relativeURL = ""; try { if (url != null) { String surl = url.toString(); URL referenceURL = getOriginalURL(context); if (referenceURL == null || !surl.startsWith(referenceURL.toString())) { relativeURL = surl; } else { StringBuilder relativeURLBuilder = new StringBuilder(url.getPath()); String querystring = url.getQuery(); if (!StringUtils.isEmpty(querystring)) { relativeURLBuilder.append("?") .append(StringUtils.removeEnd(StringUtils.removeEnd(querystring, "&"), "&amp;")); } String anchor = url.getRef(); if (!StringUtils.isEmpty(anchor)) { relativeURLBuilder.append("#").append(anchor); } relativeURL = relativeURLBuilder.toString(); } } } catch (Exception e) { LOGGER.error("Failed to create URL", e); } return StringUtils.defaultIfEmpty(relativeURL, "/"); } XWikiServletURLFactory();  XWikiServletURLFactory(URL defaultURL, String contextPath, String actionPath);  XWikiServletURLFactory(XWikiContext context); @Override void init(XWikiContext context); void setDefaultURL(String wikiId, URL baseURL); String getContextPath(); @Override URL getServerURL(XWikiContext context); URL getServerURL(String wikiId, XWikiContext context); @Override URL createURL(String spaces, String name, String action, boolean redirect, XWikiContext context); @Override URL createURL(String spaces, String name, String action, String querystring, String anchor, String xwikidb,
        XWikiContext context); @Override URL createExternalURL(String spaces, String name, String action, String querystring, String anchor,
        String xwikidb, XWikiContext context); @Override URL createSkinURL(String filename, String skin, XWikiContext context, Map<String, Object> queryParameters); @Override URL createSkinURL(String filename, String spaces, String name, String xwikidb, XWikiContext context,
        Map<String, Object> queryParameters); @Override URL createResourceURL(String filename, boolean forceSkinAction, XWikiContext context,
        Map<String, Object> queryParameters); URL createTemplateURL(String fileName, XWikiContext context); @Override URL createAttachmentURL(String filename, String spaces, String name, String action, String querystring,
        String xwikidb, XWikiContext context); @Override URL createAttachmentRevisionURL(String filename, String spaces, String name, String revision,
        String querystring, String xwikidb, XWikiContext context); URL createAttachmentRevisionURL(String filename, String spaces, String name, String revision, long recycleId,
        String querystring, String xwikidb, XWikiContext context); @Override String getURL(URL url, XWikiContext context); @Override URL getRequestURL(XWikiContext context); XWikiAttachment findAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename,
        XWikiContext context); long findDeletedAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename,
        XWikiContext context); }
XWikiServletURLFactory extends XWikiDefaultURLFactory { @Override public String getURL(URL url, XWikiContext context) { String relativeURL = ""; try { if (url != null) { String surl = url.toString(); URL referenceURL = getOriginalURL(context); if (referenceURL == null || !surl.startsWith(referenceURL.toString())) { relativeURL = surl; } else { StringBuilder relativeURLBuilder = new StringBuilder(url.getPath()); String querystring = url.getQuery(); if (!StringUtils.isEmpty(querystring)) { relativeURLBuilder.append("?") .append(StringUtils.removeEnd(StringUtils.removeEnd(querystring, "&"), "&amp;")); } String anchor = url.getRef(); if (!StringUtils.isEmpty(anchor)) { relativeURLBuilder.append("#").append(anchor); } relativeURL = relativeURLBuilder.toString(); } } } catch (Exception e) { LOGGER.error("Failed to create URL", e); } return StringUtils.defaultIfEmpty(relativeURL, "/"); } XWikiServletURLFactory();  XWikiServletURLFactory(URL defaultURL, String contextPath, String actionPath);  XWikiServletURLFactory(XWikiContext context); @Override void init(XWikiContext context); void setDefaultURL(String wikiId, URL baseURL); String getContextPath(); @Override URL getServerURL(XWikiContext context); URL getServerURL(String wikiId, XWikiContext context); @Override URL createURL(String spaces, String name, String action, boolean redirect, XWikiContext context); @Override URL createURL(String spaces, String name, String action, String querystring, String anchor, String xwikidb,
        XWikiContext context); @Override URL createExternalURL(String spaces, String name, String action, String querystring, String anchor,
        String xwikidb, XWikiContext context); @Override URL createSkinURL(String filename, String skin, XWikiContext context, Map<String, Object> queryParameters); @Override URL createSkinURL(String filename, String spaces, String name, String xwikidb, XWikiContext context,
        Map<String, Object> queryParameters); @Override URL createResourceURL(String filename, boolean forceSkinAction, XWikiContext context,
        Map<String, Object> queryParameters); URL createTemplateURL(String fileName, XWikiContext context); @Override URL createAttachmentURL(String filename, String spaces, String name, String action, String querystring,
        String xwikidb, XWikiContext context); @Override URL createAttachmentRevisionURL(String filename, String spaces, String name, String revision,
        String querystring, String xwikidb, XWikiContext context); URL createAttachmentRevisionURL(String filename, String spaces, String name, String revision, long recycleId,
        String querystring, String xwikidb, XWikiContext context); @Override String getURL(URL url, XWikiContext context); @Override URL getRequestURL(XWikiContext context); XWikiAttachment findAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename,
        XWikiContext context); long findDeletedAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename,
        XWikiContext context);  }