Merge branch 'development' of ssh://lightning.omaha.us.ray.com:29418/AWIPS2_baseline into development

Former-commit-id: 503cddcc5e [formerly 503cddcc5e [formerly 6d859accd185300997d14e7daf17f3c3257c348d]]
Former-commit-id: adf25aa707
Former-commit-id: 865fd2f475
This commit is contained in:
Steve Harris 2012-09-11 17:06:26 -05:00
commit dbd228eea2

View file

@ -25,13 +25,12 @@ import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
@ -58,6 +57,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
*/
public class ProtectedFiles {
private static transient IUFStatusHandler statusHandler = UFStatus
.getHandler(ProtectedFiles.class);
@ -83,23 +83,6 @@ public class ProtectedFiles {
private static Map<String, ProtectedFiles> sites = new HashMap<String, ProtectedFiles>();
private Set<String> protectedFiles;
private LocalizationLevel level;
private File file;
private long lastModifiedTime = 0;
private ProtectedFiles(LocalizationContext context) {
level = context.getLocalizationLevel();
file = PathManagerFactory.getPathManager()
.getLocalizationFile(context, PROTECTED_FILE).getFile();
protectedFiles = Collections
.synchronizedSortedSet(new TreeSet<String>());
reloadFile();
}
/**
* Add the list of protected files into protectedFiles.txt for the site with
* siteId
@ -131,7 +114,9 @@ public class ProtectedFiles {
ProtectedFiles site = getSiteLevelFiles(localizedSite);
protectedLevel = site.getProtectedLevelInternal(type, path);
}
if (protectedLevel == null) {
// base can be null when constructing the base ProtectedFile object and
// the ProtectedFiles constructor looks up it's localization file
if (protectedLevel == null && base != null) {
protectedLevel = base.getProtectedLevelInternal(type, path);
}
@ -154,27 +139,42 @@ public class ProtectedFiles {
return site;
}
private Set<String> protectedFiles;
private LocalizationLevel level;
private File file;
private long lastModifiedTime = 0;
private ProtectedFiles(LocalizationContext context) {
this.level = context.getLocalizationLevel();
this.protectedFiles = new LinkedHashSet<String>();
this.file = PathManagerFactory.getPathManager()
.getLocalizationFile(context, PROTECTED_FILE).getFile();
reloadFile();
}
/**
* Write the protectedFiles.txt file.
*/
private synchronized void writeProtectedFile() {
String str;
try {
file.createNewFile();
BufferedWriter out = new BufferedWriter(new FileWriter(file));
out.write(level == LocalizationLevel.BASE ? BASE_HEADER : String
.format(LEVEL_HEADER, level.toString()));
.format(LEVEL_HEADER, level));
Iterator<String> iter = protectedFiles.iterator();
while (iter.hasNext()) {
str = iter.next();
out.write(str + "\n");
out.write(iter.next() + "\n");
}
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
statusHandler.handle(Priority.PROBLEM,
"Error writing protected file list", e);
}
}