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

File DefaultLinkCheckerTransformationConfiguration.java

 

Coverage histogram

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

Code metrics

4
18
5
1
135
72
8
0.44
3.6
5
1.6

Classes

Class Line # Actions
DefaultLinkCheckerTransformationConfiguration 47 18 0% 8 4
0.851851985.2%
 

Contributing tests

This file is covered by 7 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.internal.transformation.linkchecker;
21   
22    import java.util.ArrayList;
23    import java.util.Collections;
24    import java.util.List;
25    import java.util.regex.Pattern;
26   
27    import javax.inject.Inject;
28    import javax.inject.Singleton;
29   
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.component.manager.ComponentLookupException;
32    import org.xwiki.component.manager.ComponentManager;
33    import org.xwiki.component.phase.Initializable;
34    import org.xwiki.component.phase.InitializationException;
35    import org.xwiki.configuration.ConfigurationSource;
36    import org.xwiki.configuration.internal.MemoryConfigurationSource;
37    import org.xwiki.rendering.transformation.linkchecker.LinkCheckerTransformationConfiguration;
38   
39    /**
40    * Default implementation, by default rechecks for link validity every hour.
41    *
42    * @version $Id: 404c177cbb92077188e187e0dd57bcbc6ae4cd5a $
43    * @since 3.3M2
44    */
45    @Component
46    @Singleton
 
47    public class DefaultLinkCheckerTransformationConfiguration implements LinkCheckerTransformationConfiguration,
48    Initializable
49    {
50    /**
51    * Prefix for configuration keys for the Icon transformation module.
52    */
53    private static final String PREFIX = "rendering.transformation.linkchecker.";
54   
55    /**
56    * Wait 1 hour before rechecking a link.
57    */
58    private static final long TIMEOUT = 3600000L;
59   
60    /**
61    * Overridden default timeout to be used if set.
62    */
63    private Long checkTimeout;
64   
65    /**
66    * Used to dynamically lookup a ConfigurationSource implementation since we want to make it work even if there's
67    * none available.
68    */
69    @Inject
70    private ComponentManager componentManager;
71   
72    private ConfigurationSource configurationSource;
73   
 
74  8 toggle @Override
75    public void initialize() throws InitializationException
76    {
77  8 try {
78  8 this.configurationSource = this.componentManager.getInstance(ConfigurationSource.class);
79    } catch (ComponentLookupException e) {
80  7 this.configurationSource = new MemoryConfigurationSource();
81    }
82    }
83   
 
84  64 toggle @Override
85    public long getCheckTimeout()
86    {
87  64 long result;
88   
89  64 if (this.checkTimeout != null) {
90  3 result = this.checkTimeout;
91    } else {
92  61 result = this.configurationSource.getProperty(PREFIX + "timeout", TIMEOUT);
93    }
94   
95  63 return result;
96    }
97   
98    /**
99    * @param checkTimeout the time after which a link should be checked again for validity
100    */
 
101  1 toggle @Override
102    public void setCheckTimeout(long checkTimeout)
103    {
104  1 this.checkTimeout = checkTimeout;
105    }
106   
107    /**
108    * Allows extending classes to override it.
109    *
110    * @return the list of page reference patterns to exclude from link checking
111    */
 
112  12 toggle protected List<Pattern> getDefaultExcludedReferencePatterns()
113    {
114  12 return Collections.emptyList();
115    }
116   
 
117  64 toggle @Override
118    public List<Pattern> getExcludedReferencePatterns()
119    {
120  64 List<Pattern> patterns;
121   
122  64 List<String> patternsAsString =
123    this.configurationSource.getProperty(PREFIX + "excludedReferencePatterns", List.class);
124  64 if (patternsAsString.isEmpty()) {
125  64 patterns = getDefaultExcludedReferencePatterns();
126    } else {
127  0 patterns = new ArrayList<Pattern>();
128  0 for (String patternAsString : patternsAsString) {
129  0 patterns.add(Pattern.compile(patternAsString));
130    }
131    }
132   
133  64 return patterns;
134    }
135    }