Modify gateway class to handle a directory override argument

This commit is contained in:
chubtub 2023-04-04 10:02:18 -04:00
parent 32edd6ce48
commit fd32c9fc8c
3 changed files with 18 additions and 4 deletions

View File

@ -80,9 +80,7 @@ public class Main {
"are required, or the default key (-d) must be indicated.");
System.exit(1);
}
if (!directory.isEmpty()) {
}
gateway.setDirectoryOverride(directory);
gateway.generateSwidTag(commander.getOutFile());
break;
default:

View File

@ -82,6 +82,7 @@ public class SwidTagGateway {
private String pemCertificateFile;
private boolean embeddedCert;
private String rimEventLog;
private String directoryOverride;
private String errorRequiredFields;
/**
@ -96,6 +97,7 @@ public class SwidTagGateway {
pemCertificateFile = "";
embeddedCert = false;
rimEventLog = "";
directoryOverride = "";
errorRequiredFields = "";
} catch (JAXBException e) {
System.out.println("Error initializing jaxbcontext: " + e.getMessage());
@ -166,6 +168,15 @@ public class SwidTagGateway {
this.rimEventLog = rimEventLog;
}
/**
* Setter for directory path to search for required files
*
* @param directoryOverride
*/
public void setDirectoryOverride(String directoryOverride) {
this.directoryOverride = directoryOverride;
}
/**
* This method generates a base RIM from the values in a JSON file.
*
@ -495,7 +506,7 @@ public class SwidTagGateway {
jsonObject.getString(SwidTagConstants.SUPPORT_RIM_TYPE, ""));
addNonNullAttribute(attributes, SwidTagConstants._SUPPORT_RIM_URI_GLOBAL,
jsonObject.getString(SwidTagConstants.SUPPORT_RIM_URI_GLOBAL, ""));
String filepath = jsonObject.getString(SwidTagConstants.NAME);
String filepath = directoryOverride + jsonObject.getString(SwidTagConstants.NAME);
File fileToAdd = new File(filepath);
file.setName(filepath);
file.setSize(new BigInteger(Long.toString(fileToAdd.length())));

View File

@ -5,6 +5,11 @@ import com.beust.jcommander.ParameterException;
import java.io.File;
/**
* This class validates a directory argument. If the directory is neither valid nor
* read-accessible then an error is thrown.
*/
public class DirectoryArgumentValidator implements IParameterValidator {
public void validate(String name, String value) throws ParameterException {
try {