On Feb 2, 2010, at 4:50 PM, Thomas Mortagne wrote:
On Tue, Feb 2, 2010 at 15:51, vmassol
<platform-notifications(a)xwiki.org> wrote:
> Author: vmassol
> Date: 2010-02-02 15:51:13 +0100 (Tue, 02 Feb 2010)
> New Revision: 26602
>
> Added:
>
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/renderer/AttachURILabelGenerator.java
>
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/renderer/MailtoURILabelGenerator.java
>
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/renderer/URILabelGenerator.java
> Modified:
> platform/core/trunk/xwiki-rendering/xwiki-rendering-api/pom.xml
>
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/renderer/DefaultLinkLabelGenerator.java
>
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/java/org/xwiki/rendering/internal/renderer/xhtml/DefaultXHTMLLinkRenderer.java
>
platform/core/trunk/xwiki-rendering/xwiki-rendering-api/src/main/resources/META-INF/components.txt
>
platform/core/trunk/xwiki-rendering/xwiki-rendering-tests/src/test/java/org/xwiki/rendering/SimpleRenderingTests.java
> Log:
> XWIKI-4839: Improve labels for mailto and attach links
>
> * Refactored to make the implementation more generic...
[snip]
+/**
+ * Generate link labels for MAILTO URIs.
+ *
+ * @version $Id$
+ * @since 2.2RC1
+ */
+@Component("mailto")
+public class MailtoURILabelGenerator implements URILabelGenerator
+{
+ /**
+ * The MAILTO URI prefix (the scheme followed by ":").
+ */
+ private static final String MAILTO = "mailto:";
+
+ /**
+ * {@inheritDoc}
+ * @see
org.xwiki.rendering.renderer.URILabelGenerator#generateLabel(org.xwiki.rendering.listener.Link)
+ */
+ public String generateLabel(Link link)
+ {
+ String label = link.getReference().substring(MAILTO.length());
+ // Also remove the query string part from the label (we only want the email
address).
+ int queryStringPosition = label.indexOf("?");
+ if (queryStringPosition > -1) {
+ label = label.substring(0, queryStringPosition);
+ }
Since it's an URI why don't you use
new URI(link.getReference())
to parse it ?
Actually what would be best is to pass a URI and not a Link. The pb is that
"attach:" may not resolve as a valid URI (since it can contain non encoded
chars, we would need to encode it - which is a possibility).
Thanks
-Vincent
[snip]