Skip to content

Commit

Permalink
Refactored to make module compatible with play 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed Jul 29, 2010
1 parent 0f0c9e5 commit 92414b7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/press/Compressor.java
Expand Up @@ -18,6 +18,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import play.Play;
import play.PlayPlugin;
import play.cache.Cache;
import play.exceptions.UnexpectedException;
Expand Down Expand Up @@ -201,7 +202,7 @@ public List<FileInfo> getFileListOrder() {
public void addFileListToCache(String cacheKey, List<FileInfo> originalList) {
List<FileInfo> newList = new ArrayList<FileInfo>();
for (FileInfo fileInfo : originalList) {
VirtualFile file = VirtualFile.fromRelativePath(srcDir + fileInfo.fileName);
VirtualFile file = getVirtualFile(srcDir + fileInfo.fileName);

// Check the file exists
if (!file.exists()) {
Expand Down Expand Up @@ -252,7 +253,7 @@ protected static VirtualFile getCompressedFile(FileCompressor compressor,
String fileName = Crypto.passwordHash(joinedFileNames);
fileName = lettersOnly(fileName);
String filePath = compressedDir + fileName + extension;
VirtualFile file = VirtualFile.fromRelativePath(filePath);
VirtualFile file = getVirtualFile(filePath);

// If the file already exists in the cache, return it
if (useCache(componentFiles, file, extension)) {
Expand All @@ -269,7 +270,7 @@ protected static VirtualFile getCompressedFile(FileCompressor compressor,
componentFiles.size());

// Create the directory if it doesn't already exist
VirtualFile dir = VirtualFile.fromRelativePath(compressedDir);
VirtualFile dir = getVirtualFile(compressedDir);
if (!dir.exists()) {
if (!dir.getRealFile().mkdirs()) {
throw new PressException("Could not create directory for compressed file output "
Expand Down Expand Up @@ -323,7 +324,7 @@ public static List<File> clearCache(String compressedDir, String extension) {
PressLogger.trace("Deleting cached files");

// Get the cache directory
VirtualFile dir = VirtualFile.fromRelativePath(compressedDir);
VirtualFile dir = getVirtualFile(compressedDir);
if (!dir.exists() || !dir.isDirectory()) {
return new ArrayList<File>();
}
Expand Down Expand Up @@ -535,6 +536,14 @@ protected List<String> getFilesInResponse(String content) {
return filesInOrder;
}

/**
* Gets the file at the given path, relative to the application root, even
* if the file doesn't exist
*/
private static VirtualFile getVirtualFile(String filePath) {
return VirtualFile.open(Play.getFile(filePath));
}

protected static class FileInfo {
String fileName;
boolean compress;
Expand Down

0 comments on commit 92414b7

Please sign in to comment.