|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DiskPersistenceListener.java | 75% | 90.9% | 100% | 87.5% |
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2003 by OpenSymphony
|
|
3 |
* All rights reserved.
|
|
4 |
*/
|
|
5 |
package com.opensymphony.oscache.plugins.diskpersistence;
|
|
6 |
|
|
7 |
import com.opensymphony.oscache.base.Config;
|
|
8 |
import com.opensymphony.oscache.base.persistence.CachePersistenceException;
|
|
9 |
import com.opensymphony.oscache.base.persistence.PersistenceListener;
|
|
10 |
import com.opensymphony.oscache.web.ServletCacheAdministrator;
|
|
11 |
|
|
12 |
import org.apache.commons.logging.Log;
|
|
13 |
import org.apache.commons.logging.LogFactory;
|
|
14 |
|
|
15 |
import java.io.*;
|
|
16 |
|
|
17 |
import java.util.Set;
|
|
18 |
|
|
19 |
import javax.servlet.jsp.PageContext;
|
|
20 |
|
|
21 |
/**
|
|
22 |
* Persist the cache data to disk.
|
|
23 |
*
|
|
24 |
* The code in this class is totally not thread safe it is the resonsibility
|
|
25 |
* of the cache using this persistence listener to handle the concurrency.
|
|
26 |
*
|
|
27 |
* @version $Revision: 1.1 $
|
|
28 |
* @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
|
|
29 |
* @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
|
|
30 |
* @author <a href="mailto:chris@swebtec.com">Chris Miller</a>
|
|
31 |
*/
|
|
32 |
public class DiskPersistenceListener extends AbstractDiskPersistenceListener { |
|
33 |
/**
|
|
34 |
* Build cache file name for the specified cache entry key.
|
|
35 |
*
|
|
36 |
* @param key Cache Entry Key.
|
|
37 |
* @return char[] file name.
|
|
38 |
*/
|
|
39 | 639 |
protected char[] getCacheFileName(String key) { |
40 | 639 |
if ((key == null) || (key.length() == 0)) { |
41 | 0 |
throw new IllegalArgumentException("Invalid key '" + key + "' specified to getCacheFile."); |
42 |
} |
|
43 |
|
|
44 | 639 |
char[] chars = key.toCharArray();
|
45 | 639 |
char[] fileChars = new char[chars.length]; |
46 |
|
|
47 | 639 |
for (int i = 0; i < chars.length; i++) { |
48 | 9520 |
char c = chars[i];
|
49 |
|
|
50 | 9520 |
switch (c) {
|
51 |
case '.':
|
|
52 |
case '/':
|
|
53 |
case '\\':
|
|
54 |
case ' ':
|
|
55 |
case ':':
|
|
56 |
case ';':
|
|
57 |
case '"': |
|
58 |
case '\'':
|
|
59 | 1140 |
fileChars[i] = '_'; |
60 | 1140 |
break;
|
61 |
default:
|
|
62 | 8380 |
fileChars[i] = c; |
63 |
} |
|
64 |
} |
|
65 |
|
|
66 | 639 |
return fileChars;
|
67 |
} |
|
68 |
} |
|
69 |
|
|