-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4570 from hmislk/Issue#3917
- Loading branch information
Showing
5 changed files
with
98 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template | ||
*/ | ||
package com.divudi.bean.common; | ||
|
||
import javax.inject.Named; | ||
|
@@ -10,7 +6,6 @@ | |
import java.nio.file.Paths; | ||
import java.io.IOException; | ||
|
||
|
||
/** | ||
* | ||
* @author L C J Samarasekara <[email protected]> | ||
|
@@ -26,30 +21,34 @@ public VersionController() { | |
readFirstLine(); // Load first line content upon bean instantiation | ||
} | ||
|
||
/** | ||
* Reads the first line of the text file and checks if it contains the system version. | ||
*/ | ||
public void readFirstLine() { | ||
try { | ||
// Read the first line from the file | ||
String firstLine = Files.lines(Paths.get(fileName)).findFirst().orElse(null); | ||
if (firstLine != null && !firstLine.isEmpty()) { | ||
// Set systemVersion to the content of the first line | ||
systemVersion = firstLine.trim(); | ||
} else { | ||
// If the first line is empty or the file does not exist, set systemVersion to "0.0.0.0" | ||
try { | ||
// Check if the file exists, if not, create it | ||
java.nio.file.Path path = Paths.get(fileName); | ||
if (!Files.exists(path)) { | ||
Files.createFile(path); | ||
} | ||
|
||
// Read the first line from the file | ||
String firstLine = Files.lines(path).findFirst().orElse(null); | ||
if (firstLine != null && !firstLine.isEmpty()) { | ||
// Set systemVersion to the content of the first line | ||
systemVersion = firstLine.trim(); | ||
} else { | ||
// If the first line is empty or the file does not exist, set systemVersion to null | ||
systemVersion = null; | ||
} | ||
} catch (IOException e) { | ||
// Handle IOException by printing the stack trace | ||
e.printStackTrace(); | ||
// Set systemVersion to null if an IOException occurs | ||
systemVersion = null; | ||
} | ||
} catch (IOException e) { | ||
// Handle IOException by printing the stack trace | ||
e.printStackTrace(); | ||
// Set systemVersion to "0.0.0.0" if an IOException occurs | ||
systemVersion = null; | ||
} | ||
} | ||
|
||
// Getter for systemVersion (to make it accessible from XHTML) | ||
public String getSystemVersion() { | ||
return systemVersion; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters