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

File UidStringEntityReferenceSerializer.java

 

Coverage histogram

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

Code metrics

6
8
1
1
70
29
4
0.5
8
1
4

Classes

Class Line # Actions
UidStringEntityReferenceSerializer 49 8 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 19 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   
21    package org.xwiki.model.internal.reference;
22   
23    import java.util.Locale;
24   
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.model.reference.EntityReference;
31   
32    /**
33    * Serialize a reference into a unique identifier string. This is faster compare to the human readable default
34    * string serializer and it provide unique reversible string without requiring complex escaping. Compare to default
35    * string serializers, it is aimed to be used only by computer and it will be kept stable over time. These strings are
36    * comparable and could be used when an string identifier is required (ie: hashmap, caches, storage...). These strings
37    * are also a better source for hashing algorithms.
38    *
39    * ie: The string created looks like 4:wiki5:space3:doc for the wiki:space.doc document
40    * and 4:wiki5:space3:doc20:wiki:xspace.class[0] for the wiki:space.doc^wiki:xspace.class[0] object.
41    *
42    * @version $Id: 3a4e6d561070751bcfb27c92b3896bd9a1081882 $
43    * @since 4.0M1
44    * @see LocalUidStringEntityReferenceSerializer
45    */
46    @Component
47    @Named("uid")
48    @Singleton
 
49    public class UidStringEntityReferenceSerializer extends AbstractStringEntityReferenceSerializer
50    {
 
51  2008703 toggle @Override
52    protected void serializeEntityReference(EntityReference currentReference, StringBuilder representation,
53    boolean isLastReference, Object... parameters)
54    {
55    // Append name
56  2008703 String name = currentReference.getName();
57  2008704 representation.append(name.length()).append(':').append(name);
58   
59    // Append Locale
60  2008803 if (currentReference instanceof DocumentReference) {
61  644918 Locale locale = ((DocumentReference) currentReference).getLocale();
62  644911 if (locale != null) {
63  644384 String localeString = locale.toString();
64  644375 if (!localeString.isEmpty()) {
65  52002 representation.append(localeString.length()).append(':').append(localeString);
66    }
67    }
68    }
69    }
70    }