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

File UserComponentManager.java

 

Coverage histogram

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

Code metrics

2
4
3
1
108
42
4
1
1.33
3
1.33

Classes

Class Line # Actions
UserComponentManager 45 4 0% 4 1
0.888888988.9%
 

Contributing tests

This file is covered by 199 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.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.bridge.DocumentAccessBridge;
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.component.manager.ComponentManager;
29    import org.xwiki.component.phase.Initializable;
30    import org.xwiki.component.phase.InitializationException;
31    import org.xwiki.model.reference.DocumentReference;
32    import org.xwiki.model.reference.EntityReferenceSerializer;
33   
34    /**
35    * Proxy Component Manager that creates and queries individual Component Managers specific to the current user in the
36    * Execution Context. These Component Managers are created on the fly the first time a component is registered for the
37    * current user.
38    *
39    * @version $Id: d4055df12ed67b6d591f82bfe1c813b177ba4cd2 $
40    * @since 2.1RC1
41    */
42    @Component
43    @Named(UserComponentManager.ID)
44    @Singleton
 
45    public class UserComponentManager extends AbstractEntityComponentManager implements Initializable
46    {
47    /**
48    * The identifier of this {@link ComponentManager}.
49    */
50    public static final String ID = "user";
51   
52    /**
53    * The prefix of user namespace.
54    *
55    * @since 8.4RC1
56    */
57    public static final String NAMESPACE_PREFIX = ID + ':';
58   
59    /**
60    * Used to access the current user in the Execution Context.
61    */
62    @Inject
63    private DocumentAccessBridge documentAccessBridge;
64   
65    /**
66    * Used to serialize the user reference.
67    */
68    @Inject
69    private EntityReferenceSerializer<String> referenceSerializer;
70   
71    /**
72    * The Component Manager to be used as parent when a component is not found in the current Component Manager.
73    */
74    @Inject
75    @Named(DocumentComponentManager.ID)
76    private ComponentManager documentComponentManager;
77   
 
78  271 toggle @Override
79    public void initialize() throws InitializationException
80    {
81    // Set the parent to the Wiki Component Manager since if a component isn't found for a particular user
82    // we want to check if it's available in the current wiki and if not then in the Wiki Component Manager's
83    // parent.
84  271 setInternalParent(this.documentComponentManager);
85    }
86   
87    /**
88    * {@inheritDoc}
89    * <p>
90    * Override {@link AbstractEntityComponentManager#getKey()} because the prefix is not the reference type here.
91    * </p>
92    *
93    * @see org.xwiki.component.internal.AbstractEntityComponentManager#getKey()
94    */
 
95  25267 toggle @Override
96    protected String getKey()
97    {
98  25284 DocumentReference userReference = getCurrentReference();
99   
100  25290 return userReference != null ? NAMESPACE_PREFIX + this.referenceSerializer.serialize(userReference) : null;
101    }
102   
 
103  2847709 toggle @Override
104    protected DocumentReference getCurrentReference()
105    {
106  2847691 return this.documentAccessBridge.getCurrentUserReference();
107    }
108    }