1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.component.internal

File UserComponentManager.java

 

Coverage histogram

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

Code metrics

2
4
3
1
105
43
4
1
1.33
3
1.33

Classes

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

Contributing tests

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