1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.web

File XWikiURLFactoryServiceImpl.java

 

Coverage histogram

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

Code metrics

2
20
4
1
82
53
7
0.35
5
4
1.75

Classes

Class Line # Actions
XWikiURLFactoryServiceImpl 32 20 0% 7 7
0.730769273.1%
 

Contributing tests

No tests hitting this source file were found.

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.web;
21   
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import org.slf4j.Logger;
26    import org.slf4j.LoggerFactory;
27   
28    import com.xpn.xwiki.XWiki;
29    import com.xpn.xwiki.XWikiContext;
30    import com.xpn.xwiki.pdf.impl.PdfURLFactory;
31   
 
32    public class XWikiURLFactoryServiceImpl implements XWikiURLFactoryService
33    {
34    private static final Logger LOGGER = LoggerFactory.getLogger(XWikiURLFactoryService.class);
35   
36    private Map<Integer, Class<? extends XWikiURLFactory>> factoryMap;
37   
 
38  106 toggle public XWikiURLFactoryServiceImpl(XWiki xwiki)
39    {
40  106 init(xwiki);
41    }
42   
 
43  106 toggle private void init(XWiki xwiki)
44    {
45  106 this.factoryMap = new HashMap<>();
46    // TODO: This mode is still used by the REST module (in web.xml). We need to get rid of it.
47  106 register(xwiki, XWikiContext.MODE_XMLRPC, ExternalServletURLFactory.class, "xwiki.urlfactory.xmlrpcclass");
48  106 register(xwiki, XWikiContext.MODE_SERVLET, XWikiServletURLFactory.class, "xwiki.urlfactory.servletclass");
49  106 register(xwiki, XWikiContext.MODE_PDF, PdfURLFactory.class, "xwiki.urlfactory.pdfclass");
50    }
51   
 
52  318 toggle protected void register(XWiki xwiki, int mode, Class<? extends XWikiURLFactory> defaultImpl, String propertyName)
53    {
54  318 this.factoryMap.put(mode, defaultImpl);
55  318 String urlFactoryClassName = xwiki.Param(propertyName);
56  318 if (urlFactoryClassName != null) {
57  0 try {
58  0 LOGGER.debug("Using custom url factory [" + urlFactoryClassName + "]");
59  0 @SuppressWarnings("unchecked")
60    Class<? extends XWikiURLFactory> urlFactoryClass =
61    (Class<? extends XWikiURLFactory>) Class.forName(urlFactoryClassName);
62  0 this.factoryMap.put(mode, urlFactoryClass);
63    } catch (Exception e) {
64  0 LOGGER.error("Failed to load custom url factory class [" + urlFactoryClassName + "]");
65    }
66    }
67    }
68   
 
69  43584 toggle @Override
70    public XWikiURLFactory createURLFactory(int mode, XWikiContext context)
71    {
72  43585 XWikiURLFactory urlf = null;
73  43603 try {
74  43601 Class<? extends XWikiURLFactory> urlFactoryClass = this.factoryMap.get(mode);
75  43585 urlf = urlFactoryClass.newInstance();
76  43597 urlf.init(context);
77    } catch (Exception e) {
78  0 LOGGER.error("Failed to create url factory", e);
79    }
80  43584 return urlf;
81    }
82    }