/** * {@inheritDoc} * * @see DefaultXWikiGeneratorListener#onReference(String, String, boolean, java.util.Map) */ protected void onReference(ResourceReference reference, String label, boolean isFreeStandingURI, Map<String, String> parameters) { // Since 2.5M2, handle the special case when the link syntax used for a link to a document has the // query string and/or the anchor specified as parameters. This is how the XWiki Syntax 2.1 specifies // query string and anchor (ex: [[label>>doc:docReference||queryString="a=b" anchor="anchor"]]). if (reference.getType().equals(ResourceType.DOCUMENT)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString); } String anchor = parameters.remove(ANCHOR); if (anchor != null) { reference.setParameter(DocumentResourceReference.ANCHOR, anchor); } } super.onReference(reference, label, isFreeStandingURI, parameters); }
@Override protected void onReference(ResourceReference reference, String label, boolean isFreeStandingURI, Map<String, String> parameters) { // Since 2.5M2, handle the special case when the link syntax used for a link to a document has the // query string and/or the anchor specified as parameters. This is how the XWiki Syntax 2.1 specifies // query string and anchor (ex: [[label>>doc:docReference||queryString="a=b" anchor="anchor"]]). if (reference.getType().equals(ResourceType.DOCUMENT)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString); } String anchor = parameters.remove(ANCHOR); if (anchor != null) { reference.setParameter(DocumentResourceReference.ANCHOR, anchor); } } else if (reference.getType().equals(ResourceType.ATTACHMENT)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(AttachmentResourceReference.QUERY_STRING, queryString); } } super.onReference(reference, label, isFreeStandingURI, parameters); }
@Override protected void onImage(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters) { // Since 2.5M2, handle the special case when the image syntax used for an image has a query string specified. if (reference.getType().equals(ResourceType.ATTACHMENT)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString); } } super.onImage(reference, isFreeStandingURI, parameters); } }
@Override protected void onImage(ResourceReference reference, boolean freestanding, Map<String, String> parameters) { // Since 2.5M2, handle the special case when the image syntax used for an image has a query string specified. if (ResourceType.ATTACHMENT.equals(reference.getType())) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString); } } super.onImage(reference, freestanding, parameters); } }
@Override protected void onReference(ResourceReference reference, String label, boolean freestanding, Map<String, String> parameters) { // Since 2.5M2, handle the special case when the link syntax used for a link to a document has the // query string and/or the anchor specified as parameters. This is how the XWiki Syntax 2.1 specifies // query string and anchor (ex: [[label>>doc:docReference||queryString="a=b" anchor="anchor"]]). ResourceType resourceType = reference.getType(); if (ResourceType.DOCUMENT.equals(resourceType) || ResourceType.SPACE.equals(resourceType) || ResourceType.PAGE.equals(resourceType)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString); } String anchor = parameters.remove(ANCHOR); if (anchor != null) { reference.setParameter(DocumentResourceReference.ANCHOR, anchor); } } else if (ResourceType.ATTACHMENT.equals(resourceType)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(AttachmentResourceReference.QUERY_STRING, queryString); } } super.onReference(reference, label, freestanding, parameters); }
/** * {@inheritDoc} * * @see DefaultXWikiGeneratorListener#onImage(org.xwiki.rendering.listener.reference.ResourceReference , boolean, * java.util.Map) */ protected void onImage(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters) { // Since 2.5M2, handle the special case when the image syntax used for an image has a query string specified. if (reference.getType().equals(ResourceType.ATTACHMENT)) { String queryString = parameters.remove(QUERY_STRING); if (queryString != null) { reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString); } } super.onImage(reference, isFreeStandingURI, parameters); } }
@Override public ResourceReference parse(String rawReference) { String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(rawReference, COMMENT_SEPARATOR); boolean isTyped = "true".equalsIgnoreCase(tokens[0]); ResourceType type = new ResourceType(tokens[1]); String reference = tokens[2]; ResourceReference resourceReference = new ResourceReference(reference, type); resourceReference.setTyped(isTyped); if (tokens.length == 4) { for (WikiParameter parameter : WikiParameters.newWikiParameters(tokens[3])) { resourceReference.setParameter(parameter.getKey(), parameter.getValue()); } } return resourceReference; } }
/** * {@inheritDoc} * @see org.xwiki.rendering.parser.ResourceReferenceParser#parse(String) */ public ResourceReference parse(String rawReference) { String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(rawReference, COMMENT_SEPARATOR); boolean isTyped = tokens[0].equalsIgnoreCase("true") ? true : false; ResourceType type = new ResourceType(tokens[1]); String reference = tokens[2]; ResourceReference resourceReference = new ResourceReference(reference, type); resourceReference.setTyped(isTyped); if (tokens.length == 4) { for (WikiParameter parameter : WikiParameters.newWikiParameters(tokens[3])) { resourceReference.setParameter(parameter.getKey(), parameter.getValue()); } } return resourceReference; } }
/** * @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); } } }