1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.renderer.xwiki20.reference

File SpaceReferenceTypeSerializer.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

6
14
1
1
71
33
4
0.29
14
1
4

Classes

Class Line # Actions
SpaceReferenceTypeSerializer 39 14 0% 4 3
0.8571428785.7%
 

Contributing tests

This file is covered by 1 test. .

Source view

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.Named;
23    import javax.inject.Singleton;
24   
25    import org.xwiki.component.annotation.Component;
26    import org.xwiki.rendering.listener.reference.DocumentResourceReference;
27    import org.xwiki.rendering.listener.reference.ResourceReference;
28   
29    /**
30    * Serialize a link reference pointing to a space using the format {@code (space reference)(#anchor)(?query string)}.
31    *
32    * @version $Id: f1940a5ff7d1504b52f9249572c05461e7cfdea1 $
33    * @since 7.4.1
34    * @since 8.0M1
35    */
36    @Component
37    @Named("xwiki/2.0/space")
38    @Singleton
 
39    public class SpaceReferenceTypeSerializer extends DocumentReferenceTypeSerializer
40    {
 
41  1 toggle @Override
42    public String serialize(ResourceReference reference)
43    {
44  1 StringBuilder buffer = new StringBuilder();
45   
46  1 if (reference.getReference() != null) {
47    // Make sure we escape special chars: # and ? as they have special meaning in links, but only for
48    // links to documents. Also escape \ since it's the escape char.
49  1 String normalizedReference = addEscapesToReferencePart(reference.getReference());
50  1 buffer.append(normalizedReference);
51   
52    // Since we don`t have typed references in the 2.0 syntax, we need to reuse the untyped document reference
53    // syntax and make it explicit that it's about the WebHome document of the space.
54    // This is most useful when converting from 2.1 back to 2.0.
55  1 buffer.append(".WebHome");
56    }
57   
58  1 String anchor = reference.getParameter(DocumentResourceReference.ANCHOR);
59  1 if (anchor != null) {
60  1 buffer.append('#');
61  1 buffer.append(addEscapesToExtraParts(anchor));
62    }
63  1 String queryString = reference.getParameter(DocumentResourceReference.QUERY_STRING);
64  1 if (queryString != null) {
65  1 buffer.append('?');
66  1 buffer.append(addEscapesToExtraParts(queryString));
67    }
68   
69  1 return buffer.toString();
70    }
71    }