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

File SxResourceSource.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

0
9
4
1
78
35
6
0.67
2.25
4
1.5

Classes

Class Line # Actions
SxResourceSource 33 9 0% 6 13
0.00%
 

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.sx;
21   
22    import java.io.IOException;
23    import java.io.InputStream;
24   
25    import org.apache.commons.io.IOUtils;
26   
27    /**
28    * JAR resource source for Skin Extensions.
29    *
30    * @version $Id: f567c28bc758f945e616645fb5a9df85163be33d $
31    * @since 1.7M2
32    */
 
33    public class SxResourceSource implements SxSource
34    {
35    /** The full path of the resource to use as extension. Example: {@code path/to/hello.js}. */
36    private String resourceName;
37   
38    /**
39    * Constructor of this source.
40    *
41    * @param resourceName the full path of the resource to use as extension. Example: {@code path/to/hello.js}
42    */
 
43  0 toggle public SxResourceSource(String resourceName)
44    {
45  0 this.resourceName = resourceName;
46    }
47   
 
48  0 toggle @Override
49    public CachePolicy getCachePolicy()
50    {
51  0 return CachePolicy.DEFAULT;
52    }
53   
 
54  0 toggle @Override
55    public String getContent()
56    {
57  0 try {
58    // Load from the current context class loader to allow extensions to contribute skin extensions.
59  0 ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
60  0 InputStream in = contextClassLoader.getResourceAsStream(this.resourceName);
61  0 return IOUtils.toString(in);
62    } catch (NullPointerException e) {
63    // This happens when the file was not found. Forward an IAE so that the sx action returns 404
64  0 throw new IllegalArgumentException(e);
65    } catch (IOException e) {
66  0 return "";
67    }
68    }
69   
 
70  0 toggle @Override
71    public long getLastModifiedDate()
72    {
73    // There is no easy way to know the last modification date of a resource file.
74    // return 0, which will make the action not set any Last-Modified date in the response.
75  0 return 0;
76    }
77   
78    }