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

File CoreWikiMacroBindingInitializer.java

 

Coverage histogram

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

Code metrics

0
5
2
1
88
41
3
0.6
2.5
2
1.5

Classes

Class Line # Actions
CoreWikiMacroBindingInitializer 49 5 0% 3 1
0.8571428785.7%
 

Contributing tests

This file is covered by 2 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.rendering.wikimacro.internal;
21   
22    import java.util.Map;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.slf4j.Logger;
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.context.Execution;
31    import org.xwiki.model.reference.DocumentReference;
32    import org.xwiki.rendering.internal.macro.wikibridge.WikiMacroBindingInitializer;
33    import org.xwiki.rendering.macro.wikibridge.WikiMacroParameters;
34    import org.xwiki.rendering.transformation.MacroTransformationContext;
35   
36    import com.xpn.xwiki.XWikiContext;
37    import com.xpn.xwiki.XWikiException;
38    import com.xpn.xwiki.doc.XWikiDocument;
39   
40    /**
41    * Provide old core related wiki macro bindings.
42    *
43    * @version $Id: 0c41157f4dbf031e1dce72a47074d2ee0e6ec79e $
44    * @since 2.5M1
45    */
46    @Component
47    @Singleton
48    @Named("core")
 
49    public class CoreWikiMacroBindingInitializer implements WikiMacroBindingInitializer
50    {
51    /**
52    * The key under which macro can access the document where it's defined. Same as CONTEXT_DOCUMENT_KEY (Check style
53    * fix).
54    */
55    private static final String MACRO_DOC_KEY = "doc";
56   
57    /**
58    * Execution context handler, needed for accessing the XWikiContext.
59    */
60    @Inject
61    private Execution execution;
62   
63    /**
64    * The logger to log.
65    */
66    @Inject
67    private Logger logger;
68   
69    /**
70    * @return the XWiki context
71    */
 
72  438 toggle private XWikiContext getContext()
73    {
74  438 return (XWikiContext) this.execution.getContext().getProperty("xwikicontext");
75    }
76   
 
77  146 toggle @Override
78    public void initialize(DocumentReference macroDocumentReference, WikiMacroParameters parameters,
79    String macroContent, MacroTransformationContext context, Map<String, Object> macroBinding)
80    {
81  146 try {
82  146 XWikiDocument document = getContext().getWiki().getDocument(macroDocumentReference, getContext());
83  146 macroBinding.put(MACRO_DOC_KEY, document.newDocument(getContext()));
84    } catch (XWikiException e) {
85  0 this.logger.error("Failed to get document " + macroDocumentReference, e);
86    }
87    }
88    }