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

File XWikiURLFactoryServiceImpl.java

 

Coverage histogram

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

Code metrics

2
22
4
1
84
55
7
0.32
5.5
4
1.75

Classes

Class Line # Actions
XWikiURLFactoryServiceImpl 32 22 0% 7 7
0.7575%
 

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  87 toggle public XWikiURLFactoryServiceImpl(XWiki xwiki)
39    {
40  87 init(xwiki);
41    }
42   
 
43  87 toggle private void init(XWiki xwiki)
44    {
45  87 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  87 register(xwiki, XWikiContext.MODE_XMLRPC, ExternalServletURLFactory.class, "xwiki.urlfactory.xmlrpcclass");
48  87 register(xwiki, XWikiContext.MODE_SERVLET, XWikiServletURLFactory.class, "xwiki.urlfactory.servletclass");
49  87 register(xwiki, XWikiContext.MODE_PDF, PdfURLFactory.class, "xwiki.urlfactory.pdfclass");
50  87 register(xwiki, XWikiContext.MODE_GWT, XWikiServletURLFactory.class, "xwiki.urlfactory.servletclass");
51  87 register(xwiki, XWikiContext.MODE_GWT_DEBUG, XWikiDebugGWTURLFactory.class, "xwiki.urlfactory.servletclass");
52    }
53   
 
54  435 toggle protected void register(XWiki xwiki, int mode, Class<? extends XWikiURLFactory> defaultImpl, String propertyName)
55    {
56  435 this.factoryMap.put(mode, defaultImpl);
57  435 String urlFactoryClassName = xwiki.Param(propertyName);
58  435 if (urlFactoryClassName != null) {
59  0 try {
60  0 LOGGER.debug("Using custom url factory [" + urlFactoryClassName + "]");
61  0 @SuppressWarnings("unchecked")
62    Class<? extends XWikiURLFactory> urlFactoryClass =
63    (Class<? extends XWikiURLFactory>) Class.forName(urlFactoryClassName);
64  0 this.factoryMap.put(mode, urlFactoryClass);
65    } catch (Exception e) {
66  0 LOGGER.error("Failed to load custom url factory class [" + urlFactoryClassName + "]");
67    }
68    }
69    }
70   
 
71  11610 toggle @Override
72    public XWikiURLFactory createURLFactory(int mode, XWikiContext context)
73    {
74  11605 XWikiURLFactory urlf = null;
75  11600 try {
76  11606 Class<? extends XWikiURLFactory> urlFactoryClass = this.factoryMap.get(mode);
77  11602 urlf = urlFactoryClass.newInstance();
78  11613 urlf.init(context);
79    } catch (Exception e) {
80  0 LOGGER.error("Failed to create url factory", e);
81    }
82  11612 return urlf;
83    }
84    }