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

File DefaultMandatoryDocumentInitializerManager.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

4
10
1
1
81
44
4
0.4
10
1
4

Classes

Class Line # Actions
DefaultMandatoryDocumentInitializerManager 41 10 0% 4 3
0.880%
 

Contributing tests

This file is covered by 12 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 com.xpn.xwiki.internal;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25   
26    import org.slf4j.Logger;
27    import org.xwiki.component.manager.ComponentLookupException;
28    import org.xwiki.component.manager.ComponentManager;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.model.reference.EntityReferenceSerializer;
31   
32    import com.xpn.xwiki.doc.MandatoryDocumentInitializer;
33    import com.xpn.xwiki.doc.MandatoryDocumentInitializerManager;
34   
35    /**
36    * Default implementation of {@link MandatoryDocumentInitializerManager}.
37    *
38    * @version $Id: 230ab2bd4e6ca831b9ba7d101bf91fb0045b30cf $
39    * @since 5.2M2
40    */
 
41    public class DefaultMandatoryDocumentInitializerManager implements MandatoryDocumentInitializerManager
42    {
43    @Inject
44    @Named("context")
45    private Provider<ComponentManager> componentManagerProvider;
46   
47    @Inject
48    private EntityReferenceSerializer<String> serializer;
49   
50    @Inject
51    @Named("local")
52    private EntityReferenceSerializer<String> localSerializer;
53   
54    @Inject
55    private Logger logger;
56   
 
57  153 toggle @Override
58    public MandatoryDocumentInitializer getMandatoryDocumentInitializer(DocumentReference documentReference)
59    {
60  153 ComponentManager componentManager = this.componentManagerProvider.get();
61   
62  153 String fullReference = this.serializer.serialize(documentReference);
63   
64  153 try {
65  153 if (componentManager.hasComponent(MandatoryDocumentInitializer.class, fullReference)) {
66  0 return componentManager.getInstance(MandatoryDocumentInitializer.class, fullReference);
67    } else {
68  153 String localReference = this.localSerializer.serialize(documentReference);
69   
70  153 if (componentManager.hasComponent(MandatoryDocumentInitializer.class, localReference)) {
71  2 return componentManager.getInstance(MandatoryDocumentInitializer.class, localReference);
72    }
73    }
74    } catch (ComponentLookupException e) {
75  0 this.logger.error("Failed to initialize component [{}] for document", MandatoryDocumentInitializer.class,
76    documentReference, e);
77    }
78   
79  151 return null;
80    }
81    }