From 6c5d3637e15922304f5afff1280c0809b93eb88d Mon Sep 17 00:00:00 2001 From: Max Schenkelberg Date: Tue, 11 Sep 2012 14:04:14 -0500 Subject: [PATCH] Issue #1138 Added null check to base ProtectedFile object since will be null when called recursively first time when constructing the base object. Organized static functions together from member functions. Change-Id: I5dbef82932c9dc8623061361fad64fd0e8706546 Former-commit-id: fffe220e0528f85a4f04d783571f23bbdcf45ea0 [formerly fffe220e0528f85a4f04d783571f23bbdcf45ea0 [formerly edbff1f2b607d53e8247155a5526a7c21e40ac71]] Former-commit-id: c4398c09a4c8cf1f7c37fa4d7386a69fe14cb6b1 Former-commit-id: a513b5830ad60dca095ed8fcf4a51dc48394dce9 --- .../raytheon/edex/utility/ProtectedFiles.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) 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); } }