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

File DefaultStringEntityReferenceSerializer.java

 
 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
10
4
1
96
44
7
0.7
2.5
4
1.75

Classes

Class Line # Actions
DefaultStringEntityReferenceSerializer 39 10 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 3111 tests. .

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.model.internal.reference;
21   
22    import javax.inject.Inject;
23    import javax.inject.Singleton;
24   
25    import org.xwiki.component.annotation.Component;
26    import org.xwiki.model.EntityType;
27    import org.xwiki.model.reference.EntityReference;
28    import org.xwiki.text.StringUtils;
29   
30    /**
31    * Generate a string representation of an entity reference (eg "wiki:space.page" for a document reference in the "wiki"
32    * Wiki, the "space" Space and the "page" Page).
33    *
34    * @version $Id: be3b185a9ea1426356411cdeeb88e295817009d2 $
35    * @since 2.2M1
36    */
37    @Component
38    @Singleton
 
39    public class DefaultStringEntityReferenceSerializer extends AbstractStringEntityReferenceSerializer
40    {
41    @Inject
42    private SymbolScheme symbolScheme;
43   
44    /**
45    * Empty constructor, to be used by the Component Manager, which will also inject the Symbol Scheme.
46    */
 
47  1666 toggle public DefaultStringEntityReferenceSerializer()
48    {
49    // Empty constructor, to be used by the Component Manager, which will also inject the Symbol Scheme
50    }
51   
52    /**
53    * Constructor to be used when using this class as a POJO and not as a component.
54    *
55    * @param symbolScheme the scheme to use for serializing the passed references (i.e. defines the separators to use
56    * between the Entity types, and the characters to escape and how to escape them)
57    */
 
58  322 toggle public DefaultStringEntityReferenceSerializer(SymbolScheme symbolScheme)
59    {
60  322 this.symbolScheme = symbolScheme;
61    }
62   
 
63  4305979 toggle @Override
64    protected void serializeEntityReference(EntityReference currentReference, StringBuilder representation,
65    boolean isLastReference, Object... parameters)
66    {
67  4305981 EntityType currentType = currentReference.getType();
68  4305920 EntityReference parentReference = currentReference.getParent();
69   
70    // Since the representation is being built from the root reference (i.e. from left to right), we need to add a
71    // separator if some content has already been added to the representation string (i.e. if a higher level entity
72    // type has already been processed).
73  4306040 if (parentReference != null && representation.length() > 0) {
74    // Get the separator to use between the previous type and the current type
75  2563842 Character separator =
76    getSymbolScheme().getSeparatorSymbols().get(currentType).get(parentReference.getType());
77  2563857 if (separator != null) {
78  2563860 representation.append(separator);
79    } else {
80    // The reference is invalid, the parent type is not an allowed type. Thus there's no valid separator
81    // to separate the 2 types. Use the "???" character to show the user it's invalid.
82  1 representation.append("???");
83    }
84    }
85   
86    // Escape characters that require escaping for the current type
87  4306033 representation.append(StringUtils.replaceEach(currentReference.getName(),
88    Test failure here getSymbolScheme().getSymbolsRequiringEscapes(currentType),
89    getSymbolScheme().getReplacementSymbols(currentType)));
90    }
91   
 
92  11174719 toggle protected SymbolScheme getSymbolScheme()
93    {
94  11174740 return this.symbolScheme;
95    }
96    }