27 package org.nexusformat.nxvalidate;
30 import java.io.FileInputStream;
31 import java.io.FileNotFoundException;
32 import java.io.FileOutputStream;
33 import java.io.IOException;
35 import java.util.Properties;
36 import java.util.ResourceBundle;
37 import java.util.logging.Level;
38 import javax.swing.JOptionPane;
39 import java.util.logging.Logger;
46 private Properties props = null;
47 private String nxconvertCommand = null;
48 private ResourceBundle bundle = null;
53 props =
new Properties();
54 bundle = ResourceBundle.getBundle(
55 "org/nexusformat/nxvalidate/resources/nxvalidate");
60 props =
new Properties();
62 Map<String, String> env = System.getenv();
63 for (String envName : env.keySet()) {
64 System.out.format(
"%s=%s%n", envName, env.get(envName));
67 File settings =
new File(System.getProperty(
"user.home")
68 + System.getProperty(
"file.separator")
69 +
".nxvalidate.properties");
71 if (settings.exists()) {
72 props.load(
new FileInputStream(settings));
73 if (props.getProperty(
"nxconvert") != null) {
75 if(chechExists(props.getProperty(
"nxconvert"))){
76 nxconvertCommand = props.getProperty(
"nxconvert");
87 settings.createNewFile();
95 File settings =
new File(System.getProperty(
"user.home")
96 + System.getProperty(
"file.separator") +
".nxvalidate.properties");
98 if (settings.exists()) {
100 props.setProperty(
"nxconvert", nxconvertCommand);
101 props.store(
new FileOutputStream(settings),
"NXvalidate");
104 settings.createNewFile();
105 props.setProperty(
"nxconvert", nxconvertCommand);
106 props.store(
new FileOutputStream(settings),
"NXvalidate");
109 }
catch (FileNotFoundException ex) {
112 "saveUserSettings(): The settings file cannot be found.", ex);
113 }
catch (IOException ex) {
116 "saveUserSettings(): The settings file IO error.", ex);
121 return nxconvertCommand;
125 this.nxconvertCommand = nxconvertCommand;
126 if(testPath(nxconvertCommand)){
138 private void defaultNXconvert(){
142 nxconvertCommand = bundle.getString(
"defaultWindowsNXconvert");
143 }
else if(os.
isMac()){
144 nxconvertCommand = bundle.getString(
"defaultMacNXconvert");
146 nxconvertCommand = bundle.getString(
"defaultUNIXNXconvert");
147 if(!chechExists(nxconvertCommand)){
148 nxconvertCommand = bundle.getString(
"defaultUNIXNXconvert2");
152 if(!chechExists(nxconvertCommand)){
153 nxconvertCommand =
"nxconvert";
156 if(testPath(nxconvertCommand)){
157 System.out.println(
"defaultNXconvert foundNXconvert:" +
foundNXconvert);
163 private boolean chechExists(String filename){
166 boolean exists =
false;
169 if(!filename.equals(
"")){
170 file =
new File(filename);
185 private boolean testPath(String path){
187 boolean result =
false;
198 Runtime rt = Runtime.getRuntime();
199 Process proc = rt.exec(path +
" --help");
202 }
catch (IOException ex) {