Skip to content

Commit 60c8c67

Browse files
committed
XWIKI-19383: Display a title on createlink
* Fixed types and names TODO: * Fix tests * Check DocumentXHTMLLinkTypeRenderer.java L105
1 parent 043ab77 commit 60c8c67

File tree

5 files changed

+46
-46
lines changed

5 files changed

+46
-46
lines changed
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,30 @@
2323

2424
import org.xwiki.component.annotation.Component;
2525
import org.xwiki.rendering.listener.reference.ResourceReference;
26-
import org.xwiki.rendering.renderer.reference.link.URITitleGenerator;
26+
import org.xwiki.rendering.renderer.reference.link.WantedLinkTitleGenerator;
2727

2828
/**
29-
* Generate link titles for DOC URIs.
30-
*
29+
* Generates wanted link titles for resource references.
30+
* Using this implementation should be avoided, another implementation should be used instead.
31+
* E.g. XWikiDocumentURITitleGenerator in xwiki-platform which is used to provide proper translations.
32+
* This implementation is a fallback and should only be used when xwiki-rendering is running by itself.
33+
* This implementation uses the reference as the title.
3134
* @version $Id$
32-
* @since 15.2RC1
35+
* @since 15.3RC1
3336
*/
34-
@Component(hints = {"doc", "page"})
37+
@Component
3538
@Singleton
36-
public class DefaultDocumentURITitleGenerator implements URITitleGenerator
39+
public class DefaultWantedLinkTitleGenerator implements WantedLinkTitleGenerator
3740
{
38-
private static final String DEFAULT_TITLE = "Create page: %s";
41+
private static final String DEFAULT_TITLE = "Create resource: %s";
3942

4043
/**
41-
* Generate the title of a Document URI. Using this implementation should be avoided, another implementation should
42-
* be used instead, e.g. XWikiDocumentURITitleGenerator in xwiki-platform which is used to provide proper
43-
* translations. This implementation should only be used when xwiki-rendering is running by itself.
44-
* @param reference the reference pointing to a document URI for which we want to generate a create link title
45-
* @return the URI title to display when rendering a document reference.
44+
* Generates wanted link titles for resource references.
45+
* @param reference the reference for which we want to generate a wanted link title
46+
* @return the wanted link title used when rendering a resource reference.
4647
*/
4748
@Override
48-
public String generateCreateTitle(ResourceReference reference)
49+
public String generateWantedLinkTitle(ResourceReference reference)
4950
{
5051
return String.format(DEFAULT_TITLE, reference.getReference());
5152
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424
import org.xwiki.stability.Unstable;
2525

2626
/**
27-
* Generate Resource Reference titles for URIs.
27+
* Generate Resource Reference titles for wanted links.
2828
* The implementations should be named according to the kind of reference they process.
2929
*
3030
* @version $Id$
31-
* @since 15.2RC1
31+
* @since 15.3RC1
3232
*/
3333
@Role
3434
@Unstable
35-
public interface URITitleGenerator
35+
public interface WantedLinkTitleGenerator
3636
{
3737
/**
38-
* @param reference the reference pointing to a URI for which we want to generate a create link title
39-
* @return the URI title to display when rendering resource references
38+
* @param reference the reference for which we want to generate a wanted link title
39+
* @return the title to display when rendering the resource reference wanted link
4040
*/
41-
String generateCreateTitle(ResourceReference reference);
41+
String generateWantedLinkTitle(ResourceReference reference);
4242
}

xwiki-rendering-api/src/main/resources/META-INF/components.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ org.xwiki.rendering.internal.renderer.DefaultAttachmentURILabelGenerator
2929
org.xwiki.rendering.internal.renderer.MailtoURILabelGenerator
3030
org.xwiki.rendering.internal.renderer.DataURILabelGenerator
3131
org.xwiki.rendering.internal.renderer.DefaultPageAttachmentURILabelGenerator
32-
org.xwiki.rendering.internal.renderer.DefaultDocumentURITitleGenerator
32+
org.xwiki.rendering.internal.renderer.DefaultWantedLinkTitleGenerator
3333
org.xwiki.rendering.internal.renderer.reference.DefaultResourceReferenceTypeSerializer
3434
org.xwiki.rendering.internal.syntax.SyntaxConverter
3535
org.xwiki.rendering.internal.syntax.DefaultSyntaxRegistry

xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/link/AbstractXHTMLLinkTypeRenderer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public abstract class AbstractXHTMLLinkTypeRenderer implements XHTMLLinkTypeRend
4949

5050
/**
5151
* The XHTML element {@code title} parameter.
52-
* @since 15.2RC1
52+
* @since 15.3RC1
5353
*/
5454
protected static final String TITLE = "title";
5555

@@ -227,10 +227,7 @@ public void endLink(ResourceReference reference, boolean freestanding, Map<Strin
227227
{
228228
// If there was no link content then generate it based on the passed reference
229229
if (!hasLabel()) {
230-
getXHTMLWikiPrinter().printXMLStartElement(SPAN, new String[][]
231-
{
232-
{ CLASS, "wikigeneratedlinkcontent" }
233-
});
230+
getXHTMLWikiPrinter().printXMLStartElement(SPAN, new String[][] { { CLASS, "wikigeneratedlinkcontent" } });
234231
getXHTMLWikiPrinter().printXML(computeLabel(reference));
235232
getXHTMLWikiPrinter().printXMLEndElement(SPAN);
236233
}

xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/link/DocumentXHTMLLinkTypeRenderer.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import org.xwiki.rendering.listener.reference.DocumentResourceReference;
3737
import org.xwiki.rendering.listener.reference.ResourceReference;
3838
import org.xwiki.rendering.renderer.reference.link.LinkLabelGenerator;
39-
import org.xwiki.rendering.renderer.reference.link.URITitleGenerator;
39+
import org.xwiki.rendering.renderer.reference.link.WantedLinkTitleGenerator;
4040
import org.xwiki.rendering.wiki.WikiModel;
4141

4242
/**
@@ -72,7 +72,7 @@ public class DocumentXHTMLLinkTypeRenderer extends AbstractXHTMLLinkTypeRenderer
7272
* Used to generate a link title.
7373
*/
7474
@Inject
75-
private URITitleGenerator defaultTitleGenerator;
75+
private WantedLinkTitleGenerator defaultTitleGenerator;
7676

7777
@Override
7878
public void initialize() throws InitializationException
@@ -102,33 +102,35 @@ protected String computeLabel(ResourceReference reference)
102102
return this.linkLabelGenerator.generate(reference);
103103
}
104104

105-
private URITitleGenerator getTitleGenerator(ResourceReference reference)
105+
private WantedLinkTitleGenerator getTitleGenerator(ResourceReference reference)
106106
{
107-
URITitleGenerator titleGenerator = this.defaultTitleGenerator;
108-
if (this.componentManager.hasComponent(URITitleGenerator.class, reference.getType().getScheme())) {
109-
try {
110-
titleGenerator = this.componentManager.getInstance(URITitleGenerator.class,
111-
reference.getType().getScheme());
112-
} catch (Exception e) {
113-
logger.warn("Error while loading component for generating URI title: [{}]",
114-
ExceptionUtils.getRootCauseMessage(e));
115-
logger.debug("Full stack trace: ", e);
107+
WantedLinkTitleGenerator titleGenerator = this.defaultTitleGenerator;
108+
try {
109+
titleGenerator = this.componentManager.getInstance(WantedLinkTitleGenerator.class,
110+
reference.getType().getScheme());
111+
} catch (Exception e) {
112+
String message = "Could not find a [WantedLinkTitleGenerator] component to generate the wanted "
113+
+ "link title for [{}].";
114+
if (logger.isDebugEnabled()) {
115+
logger.debug(message, reference, e);
116+
} else {
117+
logger.warn(String.format("%s: [{}]", message), reference, ExceptionUtils.getRootCauseMessage(e));
116118
}
117119
}
118120
return titleGenerator;
119121
}
120122

121123
/**
122-
* Implementation for computing a document link title when no title has been specified.
123-
* Looks for a component implementing URITitleGenerator with a role hint matching the reference scheme.
124-
* @param reference the reference of the link for which to compute the label
125-
* @return the computed title
126-
* @since 15.2RC1
124+
* Implementation for computing a wanted link title.
125+
* Looks for a component implementing WantedLinkTitleGenerator with a role hint matching the reference scheme.
126+
* @param reference the reference for which to compute the title
127+
* @return the wanted link title
128+
* @since 15.3RC1
127129
*/
128-
private String computeCreateTitle(ResourceReference reference)
130+
private String computeWantedLinkTitle(ResourceReference reference)
129131
{
130-
URITitleGenerator titleGenerator = getTitleGenerator(reference);
131-
return titleGenerator.generateCreateTitle(reference);
132+
WantedLinkTitleGenerator titleGenerator = getTitleGenerator(reference);
133+
return titleGenerator.generateWantedLinkTitle(reference);
132134
}
133135

134136
@Override
@@ -167,7 +169,7 @@ private void beginInternalLink(ResourceReference reference, boolean freestanding
167169
} else {
168170
// The wiki document doesn't exist
169171
spanAttributes.put(CLASS, "wikicreatelink");
170-
spanAttributes.put(TITLE, computeCreateTitle(reference));
172+
spanAttributes.put(TITLE, computeWantedLinkTitle(reference));
171173
anchorAttributes.put(XHTMLLinkRenderer.HREF, this.wikiModel.getDocumentEditURL(reference));
172174
}
173175

0 commit comments

Comments
 (0)