/** * @param reference see {@link #getReference()} * @param type see {@link #getType()} */ public ResourceReference(String reference, ResourceType type) { setReference(reference); setType(type); }
/** * @param document the document whose anchors to update * @param fragments see {@link #collectDocumentFragments(List)} */ private void updateAnchors(WikiDocument document, Map<String, String> fragments) { for (LinkBlock linkBlock : document.getXdom().<LinkBlock> getBlocks(new ClassBlockMatcher(LinkBlock.class), Axes.DESCENDANT)) { ResourceReference reference = linkBlock.getReference(); ResourceType resoureceType = reference.getType(); String fragment = null; if (isDocument(resoureceType) && StringUtils.isEmpty(reference.getReference())) { fragment = reference.getParameter(ANCHOR_PARAMETER); } else if (StringUtils.startsWith(reference.getReference(), "#") && (ResourceType.PATH.equals(resoureceType) || ResourceType.URL.equals(resoureceType))) { fragment = reference.getReference().substring(1); } String targetDocument = fragments.get(fragment); if (targetDocument != null && !targetDocument.equals(document.getFullName())) { // The fragment has been moved so we need to update the link. reference.setType(ResourceType.DOCUMENT); reference.setReference(targetDocument); reference.setParameter(ANCHOR_PARAMETER, fragment); } } }
/** * @since 2.2M1 */ private void refactorDocumentLinks(DocumentReference oldDocumentReference, DocumentReference newDocumentReference, XWikiContext context) throws XWikiException { XDOM xdom = getXDOM(); List<LinkBlock> linkBlockList = xdom.getChildrenByType(LinkBlock.class, true); for (LinkBlock linkBlock : linkBlockList) { ResourceReference linkReference = linkBlock.getReference(); if (linkReference.getType().equals(ResourceType.DOCUMENT)) { DocumentReference documentReference = this.explicitDocumentReferenceResolver.resolve( linkReference.getReference(), getDocumentReference()); if (documentReference.equals(oldDocumentReference)) { linkReference.setReference(this.compactEntityReferenceSerializer.serialize(newDocumentReference, getDocumentReference())); } } } setContent(xdom); }
linkReference.setReference(this.compactWikiEntityReferenceSerializer.serialize( currentLinkReference, newDocument.getDocumentReference()));