1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.component.namespace

File NamespaceUtils.java

 

Coverage histogram

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

Code metrics

20
26
3
1
94
48
13
0.5
8.67
3
4.33

Classes

Class Line # Actions
NamespaceUtils 28 26 0% 13 3
0.9387755493.9%
 

Contributing tests

This file is covered by 50 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.component.namespace;
21   
22    /**
23    * Various namespaces utilities.
24    *
25    * @version $Id: c72e535b9a7e5833b293c6abcfcf367cb34af73c $
26    * @since 8.0M1
27    */
 
28    public final class NamespaceUtils
29    {
30    /**
31    * Utility class.
32    */
 
33  0 toggle private NamespaceUtils()
34    {
35    // Utility class
36    }
37   
38    /**
39    * Extract prefix of the id used to find custom factory.
40    *
41    * @param namespaceString the namespace as a {@link String}
42    * @return the type of the namespace or null if none is provided
43    */
 
44  107 toggle public static String getPrefix(String namespaceString)
45    {
46  107 Namespace namespace = toNamespace(namespaceString);
47   
48  107 return namespace != null ? namespace.getType() : null;
49    }
50   
51    /**
52    * @param namespace the {@link String} namespace to parse
53    * @return the parsed {@link Namespace} or null if null is passed
54    * @since 9.0RC1
55    */
 
56  373 toggle public static Namespace toNamespace(String namespace)
57    {
58  373 if (namespace == null) {
59  43 return null;
60    }
61   
62  330 boolean escaped = false;
63  330 StringBuilder typeBuilder = null;
64  2952 for (int i = 0; i < namespace.length(); ++i) {
65  2839 char c = namespace.charAt(i);
66  2839 if (escaped) {
67  2 typeBuilder.append(c);
68  2 escaped = false;
69    } else {
70  2837 if (c == '\\') {
71  2 if (typeBuilder == null) {
72  2 typeBuilder = new StringBuilder();
73  2 if (i > 0) {
74  2 typeBuilder.append(namespace.substring(0, i));
75    }
76    }
77  2 escaped = true;
78  2835 } else if (c == ':') {
79  217 String type;
80  217 if (typeBuilder != null) {
81  2 type = typeBuilder.toString();
82    } else {
83  215 type = namespace.substring(0, i);
84    }
85  217 return new Namespace(type, namespace.substring(i + 1, namespace.length()));
86  2618 } else if (typeBuilder != null) {
87  4 typeBuilder.append(c);
88    }
89    }
90    }
91   
92  113 return new Namespace(null, namespace);
93    }
94    }