Commit 22eac2b1 authored by Thomas Mortagne's avatar Thomas Mortagne
Browse files

XRENDERING-654: Add rendering entry points for the PAGE_ATTACHMENT entity type

parent 2ccc5406
......@@ -64,6 +64,7 @@ public class DefaultResourceReferenceParser extends AbstractResourceReferencePar
ResourceType.SPACE,
ResourceType.PAGE,
ResourceType.ATTACHMENT,
ResourceType.PAGE_ATTACHMENT,
ResourceType.ICON
);
// @formatter:on
......
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.rendering.internal.parser.reference.type;
import javax.inject.Named;
import javax.inject.Singleton;
import org.xwiki.component.annotation.Component;
import org.xwiki.rendering.listener.reference.ResourceType;
/**
* Parses a resource reference to an attachment.
*
* @version $Id$
* @since 13.10.5
* @since 14.3RC1
*/
@Component
@Named("pageAttach")
@Singleton
public class PageAttachmentResourceReferenceTypeParser extends AbstractURIResourceReferenceTypeParser
{
@Override
public ResourceType getType()
{
return ResourceType.PAGE_ATTACHMENT;
}
}
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.rendering.internal.renderer;
import javax.inject.Named;
import javax.inject.Singleton;
import org.xwiki.component.annotation.Component;
import org.xwiki.rendering.listener.reference.ResourceReference;
import org.xwiki.rendering.renderer.reference.link.URILabelGenerator;
/**
* Generate link labels for ATTACH URIs.
*
* @version $Id$
* @since 13.10.5
* @since 14.3RC1
*/
@Component
@Named("pageAttach")
@Singleton
public class DefaultPageAttachmentURILabelGenerator implements URILabelGenerator
{
@Override
public String generateLabel(ResourceReference reference)
{
return reference.getReference();
}
}
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.rendering.listener.reference;
import org.apache.commons.lang3.StringUtils;
/**
* Represents a reference to an Attachment of a Page.
*
* @version $Id$
* @since 13.10.5
* @since 14.3RC1
*/
public class PageAttachmentResourceReference extends ResourceReference
{
/**
* The name of the parameter representing the Query String.
*/
public static final String QUERY_STRING = "queryString";
/**
* The name of the parameter representing the Anchor.
*/
public static final String ANCHOR = "anchor";
/**
* @param reference see {@link #getReference()}
*/
public PageAttachmentResourceReference(String reference)
{
super(reference, ResourceType.PAGE_ATTACHMENT);
}
/**
* @return the query string for specifying parameters that will be used in the rendered URL or null if no query
* string has been specified. Example: {@code mydata1=5&mydata2=Hello}
*/
public String getQueryString()
{
return getParameter(QUERY_STRING);
}
/**
* @param queryString see {@link #getQueryString()}
*/
public void setQueryString(String queryString)
{
if (!StringUtils.isEmpty(queryString)) {
setParameter(QUERY_STRING, queryString);
}
}
/**
* @return the anchor name pointing to an anchor defined in the referenced attachment or null if no anchor has been
* specified (in which case the reference points to the top of the attachment).
*/
public String getAnchor()
{
return getParameter(ANCHOR);
}
/**
* @param anchor see {@link #getAnchor()}
*/
public void setAnchor(String anchor)
{
if (!StringUtils.isEmpty(anchor)) {
setParameter(ANCHOR, anchor);
}
}
}
......@@ -82,10 +82,18 @@
public static final ResourceType MAILTO = new ResourceType("mailto");
/**
* Represents an attachment.
* Represents an attachment of a document.
*/
public static final ResourceType ATTACHMENT = new ResourceType("attach");
/**
* Represents an attachment of a page.
*
* @since 13.10.5
* @since 14.3RC1
*/
public static final ResourceType PAGE_ATTACHMENT = new ResourceType("pageAttach");
/**
* Represents an icon.
*/
......
......@@ -17,6 +17,7 @@ org.xwiki.rendering.internal.parser.reference.type.DocumentResourceReferenceType
org.xwiki.rendering.internal.parser.reference.type.IconResourceReferenceTypeParser
org.xwiki.rendering.internal.parser.reference.type.InterWikiResourceReferenceTypeParser
org.xwiki.rendering.internal.parser.reference.type.MailtoResourceReferenceTypeParser
org.xwiki.rendering.internal.parser.reference.type.PageAttachmentResourceReferenceTypeParser
org.xwiki.rendering.internal.parser.reference.type.PageResourceReferenceTypeParser
org.xwiki.rendering.internal.parser.reference.type.PathResourceReferenceTypeParser
org.xwiki.rendering.internal.parser.reference.type.SpaceResourceReferenceTypeParser
......@@ -26,6 +27,7 @@ org.xwiki.rendering.internal.renderer.DefaultLinkLabelGenerator
org.xwiki.rendering.internal.renderer.DefaultAttachmentURILabelGenerator
org.xwiki.rendering.internal.renderer.MailtoURILabelGenerator
org.xwiki.rendering.internal.renderer.DataURILabelGenerator
org.xwiki.rendering.internal.renderer.DefaultPageAttachmentURILabelGenerator
org.xwiki.rendering.internal.renderer.reference.DefaultResourceReferenceTypeSerializer
org.xwiki.rendering.internal.syntax.SyntaxConverter
org.xwiki.rendering.internal.syntax.DefaultSyntaxRegistry
......
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.rendering.internal.renderer.xhtml.image;
import javax.inject.Named;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.annotation.InstantiationStrategy;
import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
/**
* Handle XHTML rendering for images located in page attachments.
*
* @version $Id$
* @since 13.10.5
* @since 14.3RC1
*/
@Component
@Named("pageAttach")
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
public class PageAttachmentXHTMLImageTypeRenderer extends AttachmentXHTMLImageTypeRenderer
{
}
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.rendering.internal.renderer.xhtml.link;
import javax.inject.Named;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.annotation.InstantiationStrategy;
import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
/**
* Handle XHTML rendering for links to attachments.
*
* @version $Id$
* @since 13.10.5
* @since 14.3RC1
*/
@Component
@Named("pageAttach")
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
public class PageAttachmentXHTMLLinkTypeRenderer extends AttachmentXHTMLLinkTypeRenderer
{
}
......@@ -10,12 +10,14 @@ org.xwiki.rendering.internal.renderer.xhtml.image.DefaultXHTMLImageTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.image.AttachmentXHTMLImageTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.image.IconXHTMLImageTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.image.DataURIXHTMLImageTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.image.PageAttachmentXHTMLImageTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.link.AttachmentXHTMLLinkTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.link.DefaultXHTMLLinkRenderer
org.xwiki.rendering.internal.renderer.xhtml.link.DefaultXHTMLLinkTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.link.DocumentXHTMLLinkTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.link.InterWikiXHTMLLinkTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.link.MailtoXHTMLLinkTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.link.PageAttachmentXHTMLLinkTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.link.PathXHTMLLinkTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.link.SpaceXHTMLLinkTypeRenderer
org.xwiki.rendering.internal.renderer.xhtml.link.UNCXHTMLLinkTypeRenderer
......
......@@ -86,7 +86,7 @@ protected void onReference(ResourceReference reference, String label, boolean fr
if (anchor != null) {
reference.setParameter(DocumentResourceReference.ANCHOR, anchor);
}
} else if (ResourceType.ATTACHMENT.equals(resourceType)) {
} else if (ResourceType.ATTACHMENT.equals(resourceType) || ResourceType.PAGE_ATTACHMENT.equals(resourceType)) {
String queryString = parameters.remove(QUERY_STRING);
if (queryString != null) {
reference.setParameter(AttachmentResourceReference.QUERY_STRING, queryString);
......@@ -100,7 +100,8 @@ protected void onReference(ResourceReference reference, String label, boolean fr
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())) {
if (ResourceType.ATTACHMENT.equals(reference.getType())
|| ResourceType.PAGE_ATTACHMENT.equals(reference.getType())) {
String queryString = parameters.remove(QUERY_STRING);
if (queryString != null) {
reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString);
......
......@@ -66,6 +66,11 @@ private boolean isDocument(ResourceType resourceType)
|| ResourceType.PAGE.equals(resourceType);
}
private boolean isAttachment(ResourceType resourceType)
{
return ResourceType.ATTACHMENT.equals(resourceType) || ResourceType.PAGE_ATTACHMENT.equals(resourceType);
}
@Override
protected void printParameters(XWikiSyntaxEscapeWikiPrinter printer, ResourceReference reference,
Map<String, String> parameters)
......@@ -97,7 +102,7 @@ protected void printParameters(XWikiSyntaxEscapeWikiPrinter printer, ResourceRef
printer.print(this.PARAMETERS_PRINTER.print(ANCHOR, anchor, '~'));
shouldPrintSeparator = false;
}
} else if (ResourceType.ATTACHMENT.equals(resourceType)) {
} else if (isAttachment(resourceType)) {
String queryString = reference.getParameter(AttachmentResourceReference.QUERY_STRING);
if (!StringUtils.isEmpty(queryString)) {
printer.print(PARAMETER_SEPARATOR);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment