Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XWIKI-19383: Display a title on createlink #256

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ endDocument
.#-----------------------------------------------------
.expect|xhtml/1.0
.#-----------------------------------------------------
<p><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">\</span></a></span></p>
<p><span class="wikicreatelink" title="Create resource: \"><a href="editurl"><span class="wikigeneratedlinkcontent">\</span></a></span></p>
.#-----------------------------------------------------
.expect|annotatedxhtml/1.0
.#-----------------------------------------------------
<p><!--startwikilink:false|-|doc|-|\\--><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">\</span></a></span><!--stopwikilink--></p>
<p><!--startwikilink:false|-|doc|-|\\--><span class="wikicreatelink" title="Create resource: \"><a href="editurl"><span class="wikigeneratedlinkcontent">\</span></a></span><!--stopwikilink--></p>
.#-----------------------------------------------------
.expect|xwiki/2.0
.#-----------------------------------------------------
[[\]]
.#-----------------------------------------------------
.input|xhtml/1.0
.#-----------------------------------------------------
<p><!--startwikilink:false|-|doc|-|\\--><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">\</span></a></span><!--stopwikilink--></p>
<p><!--startwikilink:false|-|doc|-|\\--><span class="wikicreatelink" title="Create resource: \"><a href="editurl"><span class="wikigeneratedlinkcontent">\</span></a></span><!--stopwikilink--></p>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
.#-----------------------------------------------------
.expect|xhtml/1.0
.#-----------------------------------------------------
<p><span class="wikicreatelink"><a href="editurl">label</a></span></p>
<p><span class="wikicreatelink" title="Create resource: Spa ce.Pa ge "><a href="editurl">label</a></span></p>
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ endDocument
.#-----------------------------------------------------
.expect|xhtml/1.0
.#-----------------------------------------------------
<p><span class="wikicreatelink"><a href="editurl">label</a></span></p>
<p><span class="wikicreatelink" title="Create resource: Space.UnknownPage"><a href="editurl">label</a></span></p>
.#-----------------------------------------------------
.expect|annotatedxhtml/1.0
.#-----------------------------------------------------
<p><!--startwikilink:false|-|doc|-|Space.UnknownPage--><span class="wikicreatelink"><a href="editurl">label</a></span><!--stopwikilink--></p>
<p><!--startwikilink:false|-|doc|-|Space.UnknownPage--><span class="wikicreatelink" title="Create resource: Space.UnknownPage"><a href="editurl">label</a></span><!--stopwikilink--></p>
.#-----------------------------------------------------
.expect|xwiki/2.0
.#-----------------------------------------------------
[[label>>Space.UnknownPage]]
.#-----------------------------------------------------
.input|xhtml/1.0
.#-----------------------------------------------------
<p><!--startwikilink:false|-|doc|-|Space.UnknownPage--><span class="wikicreatelink"><a href="editurl">label</a></span><!--stopwikilink--></p>
<p><!--startwikilink:false|-|doc|-|Space.UnknownPage--><span class="wikicreatelink" title="Create resource: Space.UnknownPage"><a href="editurl">label</a></span><!--stopwikilink--></p>
.#-----------------------------------------------------
.expect|plain/1.0
.#-----------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ endDocument
.#-----------------------------------------------------
.expect|xhtml/1.0
.#-----------------------------------------------------
<p><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">&#123;&#123;macro}}</span></a></span><br/><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">Label&gt;Reference</span></a></span><br/><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">Reference|Param=Value</span></a></span><br/><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">[[no link</span></a></span>&gt;&gt;Not Reference]]<br/><span class="wikicreatelink"><a href="editurl">[[<img src="imageurl" class="wikimodel-freestanding wikigeneratedid" id="Iwhatever" alt="whatever"/></a></span><br/>not:link</p>
<p><span class="wikicreatelink" title="Create resource: &#123;&#123;macro}}"><a href="editurl"><span class="wikigeneratedlinkcontent">&#123;&#123;macro}}</span></a></span><br/><span class="wikicreatelink" title="Create resource: Label&gt;Reference"><a href="editurl"><span class="wikigeneratedlinkcontent">Label&gt;Reference</span></a></span><br/><span class="wikicreatelink" title="Create resource: Reference|Param=Value"><a href="editurl"><span class="wikigeneratedlinkcontent">Reference|Param=Value</span></a></span><br/><span class="wikicreatelink" title="Create resource: [[no link"><a href="editurl"><span class="wikigeneratedlinkcontent">[[no link</span></a></span>&gt;&gt;Not Reference]]<br/><span class="wikicreatelink" title="Create resource: Reference"><a href="editurl">[[<img src="imageurl" class="wikimodel-freestanding wikigeneratedid" id="Iwhatever" alt="whatever"/></a></span><br/>not:link</p>
.#-----------------------------------------------------
.expect|annotatedxhtml/1.0
.#-----------------------------------------------------
<p><!--startwikilink:false|-|doc|-|\{\{macro}}--><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">&#123;&#123;macro}}</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Label>Reference--><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">Label&gt;Reference</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Reference|Param=Value--><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">Reference|Param=Value</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|[[no link--><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">[[no link</span></a></span><!--stopwikilink-->&gt;&gt;Not Reference]]<br/><!--startwikilink:false|-|doc|-|Reference--><span class="wikicreatelink"><a href="editurl">[[<!--startimage:false|-|attach|-|whatever--><img src="imageurl" class="wikimodel-freestanding wikigeneratedid" id="Iwhatever" alt="whatever"/><!--stopimage--></a></span><!--stopwikilink--><br/>not:link</p>
<p><!--startwikilink:false|-|doc|-|\{\{macro}}--><span class="wikicreatelink" title="Create resource: &#123;&#123;macro}}"><a href="editurl"><span class="wikigeneratedlinkcontent">&#123;&#123;macro}}</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Label>Reference--><span class="wikicreatelink" title="Create resource: Label&gt;Reference"><a href="editurl"><span class="wikigeneratedlinkcontent">Label&gt;Reference</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Reference|Param=Value--><span class="wikicreatelink" title="Create resource: Reference|Param=Value"><a href="editurl"><span class="wikigeneratedlinkcontent">Reference|Param=Value</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|[[no link--><span class="wikicreatelink" title="Create resource: [[no link"><a href="editurl"><span class="wikigeneratedlinkcontent">[[no link</span></a></span><!--stopwikilink-->&gt;&gt;Not Reference]]<br/><!--startwikilink:false|-|doc|-|Reference--><span class="wikicreatelink" title="Create resource: Reference"><a href="editurl">[[<!--startimage:false|-|attach|-|whatever--><img src="imageurl" class="wikimodel-freestanding wikigeneratedid" id="Iwhatever" alt="whatever"/><!--stopimage--></a></span><!--stopwikilink--><br/>not:link</p>
.#-----------------------------------------------------
.expect|xwiki/2.0
.#-----------------------------------------------------
Expand All @@ -68,4 +68,4 @@ not:link
.#-----------------------------------------------------
.input|xhtml/1.0
.#-----------------------------------------------------
<p><!--startwikilink:false|-|doc|-|{{macro}}--><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">&#123;&#123;macro}}</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Label>Reference--><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">Label&gt;Reference</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Reference|Param=Value--><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">Reference|Param=Value</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|[[no link--><span class="wikicreatelink"><a href="editurl"><span class="wikigeneratedlinkcontent">[[no link</span></a></span><!--stopwikilink-->&gt;&gt;Not Reference]]<br/><!--startwikilink:false|-|doc|-|Reference--><span class="wikicreatelink"><a href="editurl">[[<!--startimage:false|-|attach|-|whatever--><img src="imageurl" class="wikimodel-freestanding wikigeneratedid" id="Iwhatever" alt="whatever"/><!--stopimage--></a></span><!--stopwikilink--><br/>not:link</p>
<p><!--startwikilink:false|-|doc|-|{{macro}}--><span class="wikicreatelink" title="Create resource: &#123;&#123;macro}}"><a href="editurl"><span class="wikigeneratedlinkcontent">&#123;&#123;macro}}</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Label>Reference--><span class="wikicreatelink" title="Create resource: Label&gt;Reference"><a href="editurl"><span class="wikigeneratedlinkcontent">Label&gt;Reference</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Reference|Param=Value--><span class="wikicreatelink" title="Create resource: Reference|Param=Value"><a href="editurl"><span class="wikigeneratedlinkcontent">Reference|Param=Value</span></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|[[no link--><span class="wikicreatelink" title="Create resource: [[no link"><a href="editurl"><span class="wikigeneratedlinkcontent">[[no link</span></a></span><!--stopwikilink-->&gt;&gt;Not Reference]]<br/><!--startwikilink:false|-|doc|-|Reference--><span class="wikicreatelink" title="Create resource: Reference"><a href="editurl">[[<!--startimage:false|-|attach|-|whatever--><img src="imageurl" class="wikimodel-freestanding wikigeneratedid" id="Iwhatever" alt="whatever"/><!--stopimage--></a></span><!--stopwikilink--><br/>not:link</p>
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ endDocument
.#-----------------------------------------------------
.expect|xhtml/1.0
.#-----------------------------------------------------
<p><span class="wikicreatelink"><a href="editurl"><strong>hello</strong></a></span><br/><span class="wikicreatelink"><a href="editurl">= notheader</a></span><br/><span class="wikicreatelink"><a href="editurl"></a></span></p>
<p><span class="wikicreatelink" title="Create resource: Page"><a href="editurl"><strong>hello</strong></a></span><br/><span class="wikicreatelink" title="Create resource: Page"><a href="editurl">= notheader</a></span><br/><span class="wikicreatelink" title="Create resource: Page"><a href="editurl"></a></span></p>
.#-----------------------------------------------------
.expect|annotatedxhtml/1.0
.#-----------------------------------------------------
<p><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink"><a href="editurl"><strong>hello</strong></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink"><a href="editurl">= notheader</a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink"><a href="editurl"><!--startmacro:testsimplemacro|-||-|label--><!--stopmacro--></a></span><!--stopwikilink--></p>
<p><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink" title="Create resource: Page"><a href="editurl"><strong>hello</strong></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink" title="Create resource: Page"><a href="editurl">= notheader</a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink" title="Create resource: Page"><a href="editurl"><!--startmacro:testsimplemacro|-||-|label--><!--stopmacro--></a></span><!--stopwikilink--></p>
.#-----------------------------------------------------
.expect|xwiki/2.0
.#-----------------------------------------------------
Expand All @@ -43,4 +43,4 @@ endDocument
.#-----------------------------------------------------
.input|xhtml/1.0
.#-----------------------------------------------------
<p><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink"><a href="editurl"><strong>hello</strong></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink"><a href="editurl">= notheader</a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink"><a href="editurl"><!--startmacro:testsimplemacro|-||-|label--><!--stopmacro--></a></span><!--stopwikilink--></p>
<p><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink" title="Create resource: Page"><a href="editurl"><strong>hello</strong></a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink" title="Create resource: Page"><a href="editurl">= notheader</a></span><!--stopwikilink--><br/><!--startwikilink:false|-|doc|-|Page--><span class="wikicreatelink" title="Create resource: Page"><a href="editurl"><!--startmacro:testsimplemacro|-||-|label--><!--stopmacro--></a></span><!--stopwikilink--></p>
Loading