diff --git a/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/renderer/DefaultWantedLinkTitleGenerator.java b/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/renderer/DefaultWantedLinkTitleGenerator.java new file mode 100644 index 0000000000..6c7e587b82 --- /dev/null +++ b/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/renderer/DefaultWantedLinkTitleGenerator.java @@ -0,0 +1,53 @@ +/* + * 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.Singleton; + +import org.xwiki.component.annotation.Component; +import org.xwiki.rendering.listener.reference.ResourceReference; +import org.xwiki.rendering.renderer.reference.link.WantedLinkTitleGenerator; + +/** + * Generates wanted link titles for resource references. + * Using this implementation should be avoided, another implementation should be used instead. + * E.g. XWikiDocumentWantedLinkTitleGenerator in xwiki-platform which is used to provide translations. + * This implementation is a fallback and should only be used when xwiki-rendering is running by itself. + * This implementation uses the reference as the title. + * @version $Id$ + * @since 16.3.0RC1 + */ +@Component +@Singleton +public class DefaultWantedLinkTitleGenerator implements WantedLinkTitleGenerator +{ + private static final String DEFAULT_TITLE = "Create resource: %s"; + + /** + * Generates wanted link titles for resource references. + * @param reference the reference for which we want to generate a wanted link title + * @return the wanted link title used when rendering a resource reference. + */ + @Override + public String generateWantedLinkTitle(ResourceReference reference) + { + return String.format(DEFAULT_TITLE, reference.getReference()); + } +} diff --git a/xwiki-rendering-api/src/main/java/org/xwiki/rendering/renderer/reference/link/WantedLinkTitleGenerator.java b/xwiki-rendering-api/src/main/java/org/xwiki/rendering/renderer/reference/link/WantedLinkTitleGenerator.java new file mode 100644 index 0000000000..60750bfe8b --- /dev/null +++ b/xwiki-rendering-api/src/main/java/org/xwiki/rendering/renderer/reference/link/WantedLinkTitleGenerator.java @@ -0,0 +1,42 @@ +/* + * 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.renderer.reference.link; + +import org.xwiki.component.annotation.Role; +import org.xwiki.rendering.listener.reference.ResourceReference; +import org.xwiki.stability.Unstable; + +/** + * Generate Resource Reference titles for wanted links. + * The implementations should be named according to the kind of reference they process. + * + * @version $Id$ + * @since 16.3.0RC1 + */ +@Role +@Unstable +public interface WantedLinkTitleGenerator +{ + /** + * @param reference the reference for which we want to generate a wanted link title + * @return the title to display when rendering the resource reference wanted link + */ + String generateWantedLinkTitle(ResourceReference reference); +} diff --git a/xwiki-rendering-api/src/main/resources/META-INF/components.txt b/xwiki-rendering-api/src/main/resources/META-INF/components.txt index 35fe6bb268..ba74f8c394 100644 --- a/xwiki-rendering-api/src/main/resources/META-INF/components.txt +++ b/xwiki-rendering-api/src/main/resources/META-INF/components.txt @@ -29,6 +29,7 @@ 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.DefaultWantedLinkTitleGenerator org.xwiki.rendering.internal.renderer.reference.DefaultResourceReferenceTypeSerializer org.xwiki.rendering.internal.syntax.SyntaxConverter org.xwiki.rendering.internal.syntax.DefaultSyntaxRegistry diff --git a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links20.test b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links20.test index 1369b09032..709600fd7a 100644 --- a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links20.test +++ b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links20.test @@ -15,11 +15,11 @@ endDocument .#----------------------------------------------------- .expect|xhtml/1.0 .#----------------------------------------------------- -

\

+

\

.#----------------------------------------------------- .expect|annotatedxhtml/1.0 .#----------------------------------------------------- -

\

+

\

.#----------------------------------------------------- .expect|xwiki/2.0 .#----------------------------------------------------- @@ -27,4 +27,4 @@ endDocument .#----------------------------------------------------- .input|xhtml/1.0 .#----------------------------------------------------- -

\

\ No newline at end of file +

\

\ No newline at end of file diff --git a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links22.test b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links22.test index dd1d428621..304a598ae8 100644 --- a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links22.test +++ b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links22.test @@ -6,4 +6,4 @@ .#----------------------------------------------------- .expect|xhtml/1.0 .#----------------------------------------------------- -

label

\ No newline at end of file +

label

\ No newline at end of file diff --git a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links3.test b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links3.test index 6838c3bf81..9f47b1177d 100644 --- a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links3.test +++ b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links3.test @@ -15,11 +15,11 @@ endDocument .#----------------------------------------------------- .expect|xhtml/1.0 .#----------------------------------------------------- -

label

+

label

.#----------------------------------------------------- .expect|annotatedxhtml/1.0 .#----------------------------------------------------- -

label

+

label

.#----------------------------------------------------- .expect|xwiki/2.0 .#----------------------------------------------------- @@ -27,7 +27,7 @@ endDocument .#----------------------------------------------------- .input|xhtml/1.0 .#----------------------------------------------------- -

label

+

label

.#----------------------------------------------------- .expect|plain/1.0 .#----------------------------------------------------- diff --git a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links6.test b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links6.test index 2a281b92f7..0c5adf17e0 100644 --- a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links6.test +++ b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links6.test @@ -51,11 +51,11 @@ endDocument .#----------------------------------------------------- .expect|xhtml/1.0 .#----------------------------------------------------- -

{{macro}}
Label>Reference
Reference|Param=Value
[[no link>>Not Reference]]
[[whatever
not:link

+

{{macro}}
Label>Reference
Reference|Param=Value
[[no link>>Not Reference]]
[[whatever
not:link

.#----------------------------------------------------- .expect|annotatedxhtml/1.0 .#----------------------------------------------------- -

{{macro}}
Label>Reference
Reference|Param=Value
[[no link>>Not Reference]]
[[whatever
not:link

+

{{macro}}
Label>Reference
Reference|Param=Value
[[no link>>Not Reference]]
[[whatever
not:link

.#----------------------------------------------------- .expect|xwiki/2.0 .#----------------------------------------------------- @@ -68,4 +68,4 @@ not:link .#----------------------------------------------------- .input|xhtml/1.0 .#----------------------------------------------------- -

{{macro}}
Label>Reference
Reference|Param=Value
[[no link>>Not Reference]]
[[whatever
not:link

\ No newline at end of file +

{{macro}}
Label>Reference
Reference|Param=Value
[[no link>>Not Reference]]
[[whatever
not:link

\ No newline at end of file diff --git a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links7.test b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links7.test index 5f1799092b..208f7cd86b 100644 --- a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links7.test +++ b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links7.test @@ -29,11 +29,11 @@ endDocument .#----------------------------------------------------- .expect|xhtml/1.0 .#----------------------------------------------------- -

hello
= notheader

+

hello
= notheader

.#----------------------------------------------------- .expect|annotatedxhtml/1.0 .#----------------------------------------------------- -

hello
= notheader

+

hello
= notheader

.#----------------------------------------------------- .expect|xwiki/2.0 .#----------------------------------------------------- @@ -43,4 +43,4 @@ endDocument .#----------------------------------------------------- .input|xhtml/1.0 .#----------------------------------------------------- -

hello
= notheader

\ No newline at end of file +

hello
= notheader

\ No newline at end of file diff --git a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links8.test b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links8.test index 17ee7f72b7..3e63591331 100644 --- a/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links8.test +++ b/xwiki-rendering-integration-tests/src/test/resources/wiki/link/links8.test @@ -19,11 +19,11 @@ endDocument .#----------------------------------------------------- .expect|xhtml/1.0 .#----------------------------------------------------- -

Space.ExistingPage
label

+

Space.ExistingPage
label

.#----------------------------------------------------- .expect|annotatedxhtml/1.0 .#----------------------------------------------------- -

Space.ExistingPage
label

+

Space.ExistingPage
label

.#----------------------------------------------------- .expect|xwiki/2.0 .#----------------------------------------------------- @@ -32,4 +32,4 @@ endDocument .#----------------------------------------------------- .input|xhtml/1.0 .#----------------------------------------------------- -

Space.ExistingPage
label

\ No newline at end of file +

Space.ExistingPage
label

\ No newline at end of file diff --git a/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/link/AbstractXHTMLLinkTypeRenderer.java b/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/link/AbstractXHTMLLinkTypeRenderer.java index 6e3e2022e2..3eae74ecc8 100644 --- a/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/link/AbstractXHTMLLinkTypeRenderer.java +++ b/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/link/AbstractXHTMLLinkTypeRenderer.java @@ -47,6 +47,12 @@ public abstract class AbstractXHTMLLinkTypeRenderer implements XHTMLLinkTypeRend */ protected static final String CLASS = "class"; + /** + * The XHTML element {@code title} parameter. + * @since 16.3.0RC1 + */ + protected static final String TITLE = "title"; + /** * The name of the XHTML format element. */ @@ -221,7 +227,10 @@ public void endLink(ResourceReference reference, boolean freestanding, Map spanAttributes, Map anchorAttributes) @@ -126,6 +169,7 @@ private void beginInternalLink(ResourceReference reference, boolean freestanding } else { // The wiki document doesn't exist spanAttributes.put(CLASS, "wikicreatelink"); + spanAttributes.put(TITLE, computeWantedLinkTitle(reference)); anchorAttributes.put(XHTMLLinkRenderer.HREF, this.wikiModel.getDocumentEditURL(reference)); }