1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.url.filesystem

File FilesystemExportContext.java

 

Coverage histogram

../../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

2
13
13
1
171
66
14
1.08
1
13
1.08

Classes

Class Line # Actions
FilesystemExportContext 35 13 0% 14 18
0.3571428735.7%
 

Contributing tests

This file is covered by 3 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.url.filesystem;
21   
22    import java.io.File;
23    import java.util.Collection;
24    import java.util.HashSet;
25    import java.util.Set;
26    import java.util.Stack;
27   
28    /**
29    * Stores states when generating Filesystem URLs. As we generate URLs for passed Resources we also export them to the
30    * filesystem at the same time.
31    *
32    * @version $Id: 50353fff4fab77b9dee4719f31931cf0a799a9b4 $
33    * @since 7.2M1
34    */
 
35    public class FilesystemExportContext
36    {
37    /**
38    * When there are relative links to resources inside CSS files they are resolved based on the location of the CSS
39    * file itself. When we export we put all resources and attachments in the root of the exported directory and thus
40    * in order to have valid relative links we need to make them match. We use this variable to do this.
41    */
42    private Stack<Integer> cssParentDepth = new Stack<>();
43   
44    /**
45    * @see #getExportedPages()
46    */
47    private Set<String> exportedPages = new HashSet<>();
48   
49    /**
50    * @see #getExportDir()
51    */
52    private File exportDir;
53   
54    /**
55    * @see #getNeededSkins()
56    */
57    private Set<String> neededSkins = new HashSet<>();
58   
59    /**
60    * @see #getExportedSkinFiles()
61    */
62    private Set<String> exportedSkinFiles = new HashSet<>();
63   
64    /**
65    * @return the number of relative parent levels in the path to find the CSS file
66    */
 
67  6 toggle public int getCSSParentLevel()
68    {
69  6 return this.cssParentDepth.isEmpty() ? 0 : this.cssParentDepth.peek();
70    }
71   
72    /**
73    * Pushes a new CSS parent's levels.
74    *
75    * @param depth the number of relative parent levels in the path to find the CSS file
76    */
 
77  1 toggle public void pushCSSParentLevels(int depth)
78    {
79  1 this.cssParentDepth.push(depth);
80    }
81   
82    /**
83    * Pops the last CSS parent's levels.
84    */
 
85  0 toggle public void popCSSParentLevels()
86    {
87  0 this.cssParentDepth.pop();
88    }
89   
90    /**
91    * @return the names of skins needed by rendered page(s)
92    */
 
93  0 toggle public Set<String> getNeededSkins()
94    {
95  0 return this.neededSkins;
96    }
97   
98    /**
99    * @param skin see {@link #getNeededSkins()}
100    */
 
101  0 toggle public void addNeededSkin(String skin)
102    {
103  0 this.neededSkins.add(skin);
104    }
105   
106    /**
107    * @return the base directory where the exported files are stored (attachments, resource files, etc)
108    */
 
109  4 toggle public File getExportDir()
110    {
111  4 return this.exportDir;
112    }
113   
114    /**
115    * @return the pages for which to convert URLs to local
116    */
 
117  0 toggle public Set<String> getExportedPages()
118    {
119  0 return this.exportedPages;
120    }
121   
122    /**
123    * @param page see {@link #getExportedPages()}
124    */
 
125  0 toggle public void addExportedPage(String page)
126    {
127  0 this.exportedPages.add(page);
128    }
129   
130    /**
131    * @param page the page to check
132    * @return true if the page URLs should be converted to local references
133    */
 
134  0 toggle public boolean hasExportedPage(String page)
135    {
136  0 return this.exportedPages.contains(page);
137    }
138   
139    /**
140    * @param exportDir See {@link #getExportDir()}
141    */
 
142  3 toggle public void setExportDir(File exportDir)
143    {
144  3 this.exportDir = exportDir;
145    }
146   
147    /**
148    * @return the list of custom skin files
149    */
 
150  0 toggle public Collection<String> getExportedSkinFiles()
151    {
152  0 return this.exportedSkinFiles;
153    }
154   
155    /**
156    * @param filePath the skin file path to check
157    * @return true if the skin file path is a custom skin file
158    */
 
159  0 toggle public boolean hasExportedSkinFile(String filePath)
160    {
161  0 return this.exportedSkinFiles.contains(filePath);
162    }
163   
164    /**
165    * @param filePath see {@link #getExportedPages()}
166    */
 
167  0 toggle public void addExportedSkinFile(String filePath)
168    {
169  0 this.exportedSkinFiles.add(filePath);
170    }
171    }