diff --git a/edexOsgi/com.raytheon.edex.common/src/com/raytheon/edex/utility/ProtectedFiles.java b/edexOsgi/com.raytheon.edex.common/src/com/raytheon/edex/utility/ProtectedFiles.java index 6cfd33865f..59046214e7 100644 --- a/edexOsgi/com.raytheon.edex.common/src/com/raytheon/edex/utility/ProtectedFiles.java +++ b/edexOsgi/com.raytheon.edex.common/src/com/raytheon/edex/utility/ProtectedFiles.java @@ -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 sites = new HashMap(); - private Set 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()); - 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 protectedFiles; + + private LocalizationLevel level; + + private File file; + + private long lastModifiedTime = 0; + + private ProtectedFiles(LocalizationContext context) { + this.level = context.getLocalizationLevel(); + this.protectedFiles = new LinkedHashSet(); + 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 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); } }