@Override public boolean isDocumentAvailable(ResourceReference documentReference) { ResourceType resourceType = documentReference.getType(); String resourceValue = documentReference.getReference(); if (ResourceType.DOCUMENT.equals(resourceType)) { return "Space.ExistingPage".equals(resourceValue); } else if (ResourceType.SPACE.equals(resourceType)) { return "ExistingSpace".equals(resourceValue); } else if (ResourceType.PAGE.equals(resourceType)) { return "ExistingPage".equals(resourceValue); } return false; } }
private XDOMOfficeDocument createXDOM(DocumentReference ownerDocument, ResourceReference resourceReference, Map<String, ?> parameters) throws Exception { InputStream officeFileStream; String officeFileName; if (resourceReference.getType().equals(ResourceType.URL)) { URL url = new URL(resourceReference.getReference()); officeFileStream = url.openStream(); officeFileName = StringUtils.substringAfterLast(url.getPath(), "/"); } else { throw new Exception(String.format("Unsupported resource type [%s].", resourceReference.getType())); } return createXDOM(ownerDocument, officeFileStream, officeFileName, 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); }
@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 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); } }
/** * {@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); } }
/** * {@inheritDoc} * @see ResourceReferenceParser#parse(String) */ public ResourceReference parse(String rawReference) { ResourceReference reference = this.defaultResourceReferenceParser.parse(rawReference); if (reference.getType().equals(ResourceType.UNKNOWN)) { reference = this.untypedImageReferenceParser.parse(rawReference); } return reference; } }
/** * {@inheritDoc} * @see ResourceReferenceParser#parse(String) */ public ResourceReference parse(String rawReference) { ResourceReference reference = this.defaultResourceReferenceParser.parse(rawReference); if (reference.getType().equals(ResourceType.UNKNOWN)) { reference = this.untypedLinkReferenceParser.parse(rawReference); } return reference; } }
@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); }
/** * {@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); }
String label; if (reference.getType().equals(ResourceType.DOCUMENT)) { label = this.linkLabelGenerator.generate(reference); } else {
@Override public XDOM createView(ResourceReference reference, Map<String, ?> parameters) throws Exception { OfficeDocumentView view; if (reference.getType().equals(ResourceType.ATTACHMENT) || reference.getType().equals(ResourceType.UNKNOWN)) { AttachmentReference attachmentReference = this.attachmentResolver.resolve(reference.getReference()); view = getView(reference, attachmentReference, parameters); } else { view = getView(reference, parameters); } // We have to clone the cached XDOM to protect it from the rendering transformations. For instance, macro // transformations must be executed even when the XDOM is taken from the cache. return view.getXDOM().clone(); }
/** * @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); } } }
/** * @param parameters the macro parameters in the form of a bean defined by the {@link Macro} implementation * @param content the content of the macro * @param context the context of the macros transformation process * @return the image reference to be displayed in the box * @since 10.10 */ @Unstable protected ResourceReference getImageReference(P parameters, String content, MacroTransformationContext context) { // TODO: Refactor this when it'll possible to have a specific converter associated to a macro parameter. ResourceReference imageReference = parameters.getImage(); // If the image reference is unknown then resolve it with the untyped resource reference parser // (this happens when the user doesn't specify a type for the image reference). if (imageReference != null && imageReference.getType().equals(ResourceType.UNKNOWN)) { imageReference = this.untypedImageReferenceParser.parse(imageReference.getReference()); } return imageReference; }
if (resourceReference == null || resourceReference.getType().equals(ResourceType.ATTACHMENT) || !resourceReference.isTyped()) { AttachmentReference attachmentReference;
/** * {@inheritDoc} * * @see org.xwiki.rendering.listener.chaining.AbstractChainingListener#endLink( * org.xwiki.rendering.listener.reference.ResourceReference , boolean, java.util.Map) */ @Override public void endLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters) { if (getEmptyBlockState().isCurrentContainerBlockEmpty()) { if (reference.getType().equals(ResourceType.DOCUMENT) && this.linkLabelGenerator != null) { getPrinter().print(this.linkLabelGenerator.generate(reference)); } else { getPrinter().print(reference.getReference()); } } }
/** * @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); }