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:ab120dfec6
[formerlyfffe220e05
] [formerlyab120dfec6
[formerlyfffe220e05
] [formerlyc4398c09a4
[formerly edbff1f2b607d53e8247155a5526a7c21e40ac71]]] Former-commit-id:c4398c09a4
Former-commit-id:7d5c82ebfd
[formerlya513b5830a
] Former-commit-id:6c5d3637e1
This commit is contained in:
parent
346b652757
commit
3a0d62686a
1 changed files with 25 additions and 25 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue