@Test void renameImage() throws Exception { DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page"); XWikiDocument document = mock(XWikiDocument.class); when(this.xcontext.getWiki().getDocument(documentReference, this.xcontext)).thenReturn(document); when(document.getDocumentReference()).thenReturn(documentReference); when(document.getSyntax()).thenReturn(Syntax.XWIKI_2_1); DocumentReference oldImageTarget = new DocumentReference("wiki", "A", "B"); AttachmentReference oldImageTargetAttachment = new AttachmentReference("attachment.txt", oldImageTarget); DocumentReference newImageTarget = new DocumentReference("wiki", "X", "Y"); AttachmentReference newImageTargetAttachment = new AttachmentReference("attachment.txt", newImageTarget); XDOM xdom = mock(XDOM.class); when(document.getXDOM()).thenReturn(xdom); ResourceReference imageReference = new AttachmentResourceReference("A.B@attachment.txt"); ImageBlock imageBlock = new ImageBlock(imageReference, false); when(xdom.getBlocks(any(), eq(Block.Axes.DESCENDANT))).thenReturn(Arrays.asList(imageBlock)); when(this.resourceReferenceResolver.resolve(imageReference, null, documentReference)) .thenReturn(oldImageTargetAttachment); when(this.defaultReferenceDocumentReferenceResolver.resolve(oldImageTargetAttachment)) .thenReturn(oldImageTarget); when(this.compactEntityReferenceSerializer.serialize(newImageTargetAttachment, documentReference)) .thenReturn("X.Y@attachment.txt"); this.refactoring.renameLinks(documentReference, oldImageTarget, newImageTarget); assertEquals("X.Y@attachment.txt", imageBlock.getReference().getReference()); assertEquals(ResourceType.ATTACHMENT, imageBlock.getReference().getType()); verifyDocumentSave(document, "Renamed back-links.", false, false); }
@Override public void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget, DocumentReference newLinkTarget) { boolean popLevelProgress = false; XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(documentReference.getWikiReference().getName()); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); List<Locale> locales = document.getTranslationLocales(xcontext); this.progressManager.pushLevelProgress(1 + locales.size(), this); popLevelProgress = true; this.progressManager.startStep(this); renameLinks(document, oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); for (Locale locale : locales) { this.progressManager.startStep(this); renameLinks(document.getTranslatedDocument(locale, xcontext), oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); } } catch (XWikiException e) { this.logger.error("Failed to rename the links that target [{}] from [{}].", oldLinkTarget, documentReference, e); } finally { if (popLevelProgress) { this.progressManager.popLevelProgress(this); } xcontext.setWikiId(previousWikiId); } }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget, DocumentReference newLinkTarget) { boolean popLevelProgress = false; XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(documentReference.getWikiReference().getName()); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); List<Locale> locales = document.getTranslationLocales(xcontext); this.progressManager.pushLevelProgress(1 + locales.size(), this); popLevelProgress = true; this.progressManager.startStep(this); renameLinks(document, oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); for (Locale locale : locales) { this.progressManager.startStep(this); renameLinks(document.getTranslatedDocument(locale, xcontext), oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); } } catch (XWikiException e) { this.logger.error("Failed to rename the links that target [{}] from [{}].", oldLinkTarget, documentReference, e); } finally { if (popLevelProgress) { this.progressManager.popLevelProgress(this); } xcontext.setWikiId(previousWikiId); } } }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget, DocumentReference newLinkTarget) { boolean popLevelProgress = false; XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(documentReference.getWikiReference().getName()); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); List<Locale> locales = document.getTranslationLocales(xcontext); this.progressManager.pushLevelProgress(1 + locales.size(), this); popLevelProgress = true; this.progressManager.startStep(this); renameLinks(document, oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); for (Locale locale : locales) { this.progressManager.startStep(this); renameLinks(document.getTranslatedDocument(locale, xcontext), oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); } } catch (XWikiException e) { this.logger.error("Failed to rename the links that target [{}] from [{}].", oldLinkTarget, documentReference, e); } finally { if (popLevelProgress) { this.progressManager.popLevelProgress(this); } xcontext.setWikiId(previousWikiId); } }  }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget, DocumentReference newLinkTarget) { boolean popLevelProgress = false; XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(documentReference.getWikiReference().getName()); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); List<Locale> locales = document.getTranslationLocales(xcontext); this.progressManager.pushLevelProgress(1 + locales.size(), this); popLevelProgress = true; this.progressManager.startStep(this); renameLinks(document, oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); for (Locale locale : locales) { this.progressManager.startStep(this); renameLinks(document.getTranslatedDocument(locale, xcontext), oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); } } catch (XWikiException e) { this.logger.error("Failed to rename the links that target [{}] from [{}].", oldLinkTarget, documentReference, e); } finally { if (popLevelProgress) { this.progressManager.popLevelProgress(this); } xcontext.setWikiId(previousWikiId); } }  @Override void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget,
        DocumentReference newLinkTarget); @Override void updateRelativeLinks(DocumentReference oldReference, DocumentReference newReference); }
DefaultLinkRefactoring implements LinkRefactoring { @Override public void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget, DocumentReference newLinkTarget) { boolean popLevelProgress = false; XWikiContext xcontext = this.xcontextProvider.get(); String previousWikiId = xcontext.getWikiId(); try { xcontext.setWikiId(documentReference.getWikiReference().getName()); XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext); List<Locale> locales = document.getTranslationLocales(xcontext); this.progressManager.pushLevelProgress(1 + locales.size(), this); popLevelProgress = true; this.progressManager.startStep(this); renameLinks(document, oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); for (Locale locale : locales) { this.progressManager.startStep(this); renameLinks(document.getTranslatedDocument(locale, xcontext), oldLinkTarget, newLinkTarget, xcontext, false); this.progressManager.endStep(this); } } catch (XWikiException e) { this.logger.error("Failed to rename the links that target [{}] from [{}].", oldLinkTarget, documentReference, e); } finally { if (popLevelProgress) { this.progressManager.popLevelProgress(this); } xcontext.setWikiId(previousWikiId); } }  @Override void renameLinks(DocumentReference documentReference, DocumentReference oldLinkTarget,
        DocumentReference newLinkTarget); @Override void updateRelativeLinks(DocumentReference oldReference, DocumentReference newReference);  }