Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../../../img/srcFileCovDistChart9.png 55% of files have more coverage
8   101   4   4
0   46   0.5   2
2     2  
1    
 
  XWikiSyntaxLinkReferenceSerializer       Line # 49 8 0% 4 1 90% 0.9
 
  (57)
 
1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.internal.renderer.xwiki20.reference;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.component.manager.ComponentLookupException;
28    import org.xwiki.component.manager.ComponentManager;
29    import org.xwiki.rendering.listener.reference.ResourceReference;
30    import org.xwiki.rendering.renderer.reference.ResourceReferenceSerializer;
31    import org.xwiki.rendering.renderer.reference.ResourceReferenceTypeSerializer;
32   
33    /**
34    * Generate a string representation of a Link reference, in XWiki Syntax 2.0. This implementation is pluggable by using
35    * internally implementations of {@link org.xwiki.rendering.renderer.reference.ResourceReferenceTypeSerializer}, each in
36    * charge of serializing a given {@link org.xwiki.rendering.listener.reference.ResourceType}.
37    * <p>
38    * Note that {@link org.xwiki.rendering.renderer.reference.ResourceReferenceTypeSerializer} component implementations
39    * must use a role hint equal to the XWiki Syntax id followed by "/" and then Link Type name (eg "doc" for document
40    * links, "attach" for attachment links, etc).
41    * </p>
42    *
43    * @version $Id: d5548406e42e481d035a4efc7da2710f78229131 $
44    * @since 2.5RC1
45    */
46    @Component
47    @Named("xwiki/2.0/link")
48    @Singleton
 
49    public class XWikiSyntaxLinkReferenceSerializer implements ResourceReferenceSerializer
50    {
51    /**
52    * Prefix to use for {@link org.xwiki.rendering.renderer.reference.ResourceReferenceTypeSerializer} role hints.
53    */
54    private static final String COMPONENT_PREFIX = "xwiki/2.0";
55   
56    /**
57    * Used to lookup {@link org.xwiki.rendering.renderer.reference.ResourceReferenceTypeSerializer} implementations.
58    */
59    @Inject
60    private ComponentManager componentManager;
61   
62    /**
63    * Default serializer to use when no serializer is found for the link type.
64    */
65    @Inject
66    @Named("xwiki/2.0")
67    private ResourceReferenceTypeSerializer defaultResourceReferenceTypeSerializer;
68   
 
69  117 toggle @Override
70    public String serialize(ResourceReference reference)
71    {
72  117 String result;
73   
74  117 try {
75  117 result =
76    this.componentManager.lookup(ResourceReferenceTypeSerializer.class,
77    getLinkTypeSerializerComponentPrefix() + "/" + reference.getType().getScheme())
78    .serialize(reference);
79    } catch (ComponentLookupException e) {
80  94 try {
81    // Failed to find serializer for the passed link type. Use the default serializer.
82  94 result =
83    this.componentManager.lookup(ResourceReferenceTypeSerializer.class,
84    getLinkTypeSerializerComponentPrefix()).serialize(reference);
85    } catch (ComponentLookupException e2) {
86    // Failed to find a default serializer for the current syntax. Use xwiki/2.0 default serializer.
87  0 result = this.defaultResourceReferenceTypeSerializer.serialize(reference);
88    }
89    }
90  117 return result;
91    }
92   
93    /**
94    * @return the role hint prefix to use when looking up
95    * {@link org.xwiki.rendering.renderer.reference.ResourceReferenceTypeSerializer} implementations.
96    */
 
97  171 toggle protected String getLinkTypeSerializerComponentPrefix()
98    {
99  171 return COMPONENT_PREFIX;
100    }
101    }