@Test public void createAttachmentURLFindRev() { XWikiContext xwikiContext = this.oldcore.getXWikiContext(); XWikiDocument doc = new XWikiDocument(new DocumentReference("xwiki", "currentspace", "currentpage")); XWikiAttachment attachment = new XWikiAttachment(doc, "file"); attachment.setVersion("1.3"); doc.setAttachment(attachment); xwikiContext.setDoc(doc); URL url = this.urlFactory.createAttachmentURL("file", "currentspace", "currentpage", "download", null, xwikiContext); assertEquals("http: }
@Override public URL createAttachmentURL(String filename, String spaces, String name, String action, String querystring, String xwikidb, XWikiContext context) { XWikiAttachment attachment = null; URL attachmentURL = null; if ((context != null) && "viewrev".equals(context.getAction()) && context.get("rev") != null && isContextDoc(xwikidb, spaces, name, context) && Locale.ROOT.equals(context.getDoc().getLocale())) { try { String docRevision = context.get("rev").toString(); attachment = findAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); if (attachment == null) { action = "viewattachrev"; } else { long arbId = findDeletedAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); attachmentURL = createAttachmentRevisionURL(filename, spaces, name, attachment.getVersion(), arbId, querystring, xwikidb, context); } } catch (XWikiException e) { LOGGER.error( "Failed to create attachment URL for filename [{}] in spaces [{}], page [{}], " + "action [{}], query string [{}] and wiki [{}]", filename, spaces, name, action, querystring, xwikidb, e); } } else if (action.equals("download") && isContextDoc(xwikidb, spaces, name, context) && Locale.ROOT.equals(context.getDoc().getLocale())) { attachment = context.getDoc().getAttachment(filename); } else if (action.equals("download")) { WikiReference originalWikiReference = context.getWikiReference(); context.setWikiId(xwikidb); DocumentReference documentReference = new DocumentReference(name, new SpaceReference( getCurrentEntityReferenceResolver().resolve(spaces, EntityType.SPACE, context.getWikiReference()))); try { XWikiDocument document = context.getWiki().getDocument(documentReference, context); attachment = document.getAttachment(filename); } catch (XWikiException e) { LOGGER.error("Exception while loading doc from wiki [{}] space [{}] and page [{}]", xwikidb, spaces, name, e); } finally { context.setWikiReference(originalWikiReference); } } if (attachment != null) { if (!StringUtils.isEmpty(querystring)) { querystring += "&rev=" + attachment.getVersion(); } else { querystring = "rev=" + attachment.getVersion(); } } if (attachmentURL == null) { attachmentURL = this.internalCreateAttachmentURL(filename, spaces, name, action, querystring, xwikidb, context); } return attachmentURL; }
XWikiServletURLFactory extends XWikiDefaultURLFactory { @Override public URL createAttachmentURL(String filename, String spaces, String name, String action, String querystring, String xwikidb, XWikiContext context) { XWikiAttachment attachment = null; URL attachmentURL = null; if ((context != null) && "viewrev".equals(context.getAction()) && context.get("rev") != null && isContextDoc(xwikidb, spaces, name, context) && Locale.ROOT.equals(context.getDoc().getLocale())) { try { String docRevision = context.get("rev").toString(); attachment = findAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); if (attachment == null) { action = "viewattachrev"; } else { long arbId = findDeletedAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); attachmentURL = createAttachmentRevisionURL(filename, spaces, name, attachment.getVersion(), arbId, querystring, xwikidb, context); } } catch (XWikiException e) { LOGGER.error( "Failed to create attachment URL for filename [{}] in spaces [{}], page [{}], " + "action [{}], query string [{}] and wiki [{}]", filename, spaces, name, action, querystring, xwikidb, e); } } else if (action.equals("download") && isContextDoc(xwikidb, spaces, name, context) && Locale.ROOT.equals(context.getDoc().getLocale())) { attachment = context.getDoc().getAttachment(filename); } else if (action.equals("download")) { WikiReference originalWikiReference = context.getWikiReference(); context.setWikiId(xwikidb); DocumentReference documentReference = new DocumentReference(name, new SpaceReference( getCurrentEntityReferenceResolver().resolve(spaces, EntityType.SPACE, context.getWikiReference()))); try { XWikiDocument document = context.getWiki().getDocument(documentReference, context); attachment = document.getAttachment(filename); } catch (XWikiException e) { LOGGER.error("Exception while loading doc from wiki [{}] space [{}] and page [{}]", xwikidb, spaces, name, e); } finally { context.setWikiReference(originalWikiReference); } } if (attachment != null) { if (!StringUtils.isEmpty(querystring)) { querystring += "&rev=" + attachment.getVersion(); } else { querystring = "rev=" + attachment.getVersion(); } } if (attachmentURL == null) { attachmentURL = this.internalCreateAttachmentURL(filename, spaces, name, action, querystring, xwikidb, context); } return attachmentURL; } }
XWikiServletURLFactory extends XWikiDefaultURLFactory { @Override public URL createAttachmentURL(String filename, String spaces, String name, String action, String querystring, String xwikidb, XWikiContext context) { XWikiAttachment attachment = null; URL attachmentURL = null; if ((context != null) && "viewrev".equals(context.getAction()) && context.get("rev") != null && isContextDoc(xwikidb, spaces, name, context) && Locale.ROOT.equals(context.getDoc().getLocale())) { try { String docRevision = context.get("rev").toString(); attachment = findAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); if (attachment == null) { action = "viewattachrev"; } else { long arbId = findDeletedAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); attachmentURL = createAttachmentRevisionURL(filename, spaces, name, attachment.getVersion(), arbId, querystring, xwikidb, context); } } catch (XWikiException e) { LOGGER.error( "Failed to create attachment URL for filename [{}] in spaces [{}], page [{}], " + "action [{}], query string [{}] and wiki [{}]", filename, spaces, name, action, querystring, xwikidb, e); } } else if (action.equals("download") && isContextDoc(xwikidb, spaces, name, context) && Locale.ROOT.equals(context.getDoc().getLocale())) { attachment = context.getDoc().getAttachment(filename); } else if (action.equals("download")) { WikiReference originalWikiReference = context.getWikiReference(); context.setWikiId(xwikidb); DocumentReference documentReference = new DocumentReference(name, new SpaceReference( getCurrentEntityReferenceResolver().resolve(spaces, EntityType.SPACE, context.getWikiReference()))); try { XWikiDocument document = context.getWiki().getDocument(documentReference, context); attachment = document.getAttachment(filename); } catch (XWikiException e) { LOGGER.error("Exception while loading doc from wiki [{}] space [{}] and page [{}]", xwikidb, spaces, name, e); } finally { context.setWikiReference(originalWikiReference); } } if (attachment != null) { if (!StringUtils.isEmpty(querystring)) { querystring += "&rev=" + attachment.getVersion(); } else { querystring = "rev=" + attachment.getVersion(); } } if (attachmentURL == null) { attachmentURL = this.internalCreateAttachmentURL(filename, spaces, name, action, querystring, xwikidb, context); } return attachmentURL; } XWikiServletURLFactory();  XWikiServletURLFactory(URL defaultURL, String contextPath, String actionPath);  XWikiServletURLFactory(XWikiContext context); }
XWikiServletURLFactory extends XWikiDefaultURLFactory { @Override public URL createAttachmentURL(String filename, String spaces, String name, String action, String querystring, String xwikidb, XWikiContext context) { XWikiAttachment attachment = null; URL attachmentURL = null; if ((context != null) && "viewrev".equals(context.getAction()) && context.get("rev") != null && isContextDoc(xwikidb, spaces, name, context) && Locale.ROOT.equals(context.getDoc().getLocale())) { try { String docRevision = context.get("rev").toString(); attachment = findAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); if (attachment == null) { action = "viewattachrev"; } else { long arbId = findDeletedAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); attachmentURL = createAttachmentRevisionURL(filename, spaces, name, attachment.getVersion(), arbId, querystring, xwikidb, context); } } catch (XWikiException e) { LOGGER.error( "Failed to create attachment URL for filename [{}] in spaces [{}], page [{}], " + "action [{}], query string [{}] and wiki [{}]", filename, spaces, name, action, querystring, xwikidb, e); } } else if (action.equals("download") && isContextDoc(xwikidb, spaces, name, context) && Locale.ROOT.equals(context.getDoc().getLocale())) { attachment = context.getDoc().getAttachment(filename); } else if (action.equals("download")) { WikiReference originalWikiReference = context.getWikiReference(); context.setWikiId(xwikidb); DocumentReference documentReference = new DocumentReference(name, new SpaceReference( getCurrentEntityReferenceResolver().resolve(spaces, EntityType.SPACE, context.getWikiReference()))); try { XWikiDocument document = context.getWiki().getDocument(documentReference, context); attachment = document.getAttachment(filename); } catch (XWikiException e) { LOGGER.error("Exception while loading doc from wiki [{}] space [{}] and page [{}]", xwikidb, spaces, name, e); } finally { context.setWikiReference(originalWikiReference); } } if (attachment != null) { if (!StringUtils.isEmpty(querystring)) { querystring += "&rev=" + attachment.getVersion(); } else { querystring = "rev=" + attachment.getVersion(); } } if (attachmentURL == null) { attachmentURL = this.internalCreateAttachmentURL(filename, spaces, name, action, querystring, xwikidb, context); } return attachmentURL; } 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 URL createAttachmentURL(String filename, String spaces, String name, String action, String querystring, String xwikidb, XWikiContext context) { XWikiAttachment attachment = null; URL attachmentURL = null; if ((context != null) && "viewrev".equals(context.getAction()) && context.get("rev") != null && isContextDoc(xwikidb, spaces, name, context) && Locale.ROOT.equals(context.getDoc().getLocale())) { try { String docRevision = context.get("rev").toString(); attachment = findAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); if (attachment == null) { action = "viewattachrev"; } else { long arbId = findDeletedAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); attachmentURL = createAttachmentRevisionURL(filename, spaces, name, attachment.getVersion(), arbId, querystring, xwikidb, context); } } catch (XWikiException e) { LOGGER.error( "Failed to create attachment URL for filename [{}] in spaces [{}], page [{}], " + "action [{}], query string [{}] and wiki [{}]", filename, spaces, name, action, querystring, xwikidb, e); } } else if (action.equals("download") && isContextDoc(xwikidb, spaces, name, context) && Locale.ROOT.equals(context.getDoc().getLocale())) { attachment = context.getDoc().getAttachment(filename); } else if (action.equals("download")) { WikiReference originalWikiReference = context.getWikiReference(); context.setWikiId(xwikidb); DocumentReference documentReference = new DocumentReference(name, new SpaceReference( getCurrentEntityReferenceResolver().resolve(spaces, EntityType.SPACE, context.getWikiReference()))); try { XWikiDocument document = context.getWiki().getDocument(documentReference, context); attachment = document.getAttachment(filename); } catch (XWikiException e) { LOGGER.error("Exception while loading doc from wiki [{}] space [{}] and page [{}]", xwikidb, spaces, name, e); } finally { context.setWikiReference(originalWikiReference); } } if (attachment != null) { if (!StringUtils.isEmpty(querystring)) { querystring += "&rev=" + attachment.getVersion(); } else { querystring = "rev=" + attachment.getVersion(); } } if (attachmentURL == null) { attachmentURL = this.internalCreateAttachmentURL(filename, spaces, name, action, querystring, xwikidb, context); } return attachmentURL; } 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);  }