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

File TemporaryResourceReferenceHandler.java

 

Coverage histogram

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

Code metrics

0
6
4
1
86
51
5
0.83
1.5
4
1.25

Classes

Class Line # Actions
TemporaryResourceReferenceHandler 50 6 0% 5 10
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 org.xwiki.resource.temporary.internal;
21   
22    import java.io.FileInputStream;
23    import java.io.IOException;
24    import java.io.InputStream;
25    import java.util.Arrays;
26    import java.util.List;
27   
28    import javax.inject.Inject;
29    import javax.inject.Named;
30    import javax.inject.Singleton;
31   
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.resource.ResourceType;
34    import org.xwiki.resource.servlet.AbstractServletResourceReferenceHandler;
35    import org.xwiki.resource.temporary.TemporaryResourceReference;
36    import org.xwiki.resource.temporary.TemporaryResourceStore;
37    import org.xwiki.security.authorization.ContextualAuthorizationManager;
38    import org.xwiki.security.authorization.Right;
39   
40    /**
41    * Resolves and return the temporary resource ({@link org.xwiki.resource.temporary.TemporaryResourceReference}) in the
42    * Servlet Output Stream.
43    *
44    * @version $Id: d41f0e8b79959a552d3a2bc3511716bfa23a448c $
45    * @since 6.1M1
46    */
47    @Component
48    @Named("tmp")
49    @Singleton
 
50    public class TemporaryResourceReferenceHandler
51    extends AbstractServletResourceReferenceHandler<TemporaryResourceReference>
52    {
53    @Inject
54    private TemporaryResourceStore store;
55   
56    @Inject
57    private ContextualAuthorizationManager authorization;
58   
 
59  0 toggle @Override
60    public List<ResourceType> getSupportedResourceReferences()
61    {
62  0 return Arrays.asList(TemporaryResourceReference.TYPE);
63    }
64   
 
65  0 toggle @Override
66    protected boolean isResourceAccessible(TemporaryResourceReference resourceReference)
67    {
68  0 return this.authorization.hasAccess(Right.VIEW, resourceReference.getOwningEntityReference());
69    }
70   
 
71  0 toggle @Override
72    protected InputStream getResourceStream(TemporaryResourceReference resourceReference)
73    {
74  0 try {
75  0 return new FileInputStream(this.store.getTemporaryFile(resourceReference));
76    } catch (IOException e) {
77  0 return null;
78    }
79    }
80   
 
81  0 toggle @Override
82    protected String getResourceName(TemporaryResourceReference resourceReference)
83    {
84  0 return resourceReference.getResourceName();
85    }
86    }