/* * @(#)Index.java 1.0 03/04/11 * * You can modify the template of this file in the * directory ..\JCreator\Templates\Template_1\Project_Name.java * * You can also create your own project template by making a new * folder in the directory ..\JCreator\Template\. Use the other * templates as examples. * */ import java.io.*; import java.util.*; import pds.label.*; class Index{ // private static ArrayList lbl_files = new ArrayList(); // private static ArrayList catalog_files = new ArrayList(); private static ArrayList non_quoted_keywords = new ArrayList(); private static ArrayList lines = new ArrayList(); public static ArrayList manifestOptions = null; public static ArrayList indexOptions = null; private static File optionsFile = null; private static BufferedReader fin = null; public static ArrayList manifestColumns = new ArrayList(); public static ArrayList indexColumns = new ArrayList(); public static LinkedList indexInitValues = new LinkedList(); public static File path = null; public static String volId = ""; public static String[] mandatoryIndexColumns = {"DATA_SET_ID","FILE_SPECIFICATION_NAME","PRODUCT_ID","VOLUME_ID","PRODUCT_CREATION_TIME"}; // private static String[] mandatoryIndexColumns = {"DATA_SET_ID","FILE_SPECIFICATION_NAME","PRODUCT_ID","PRODUCT_TYPE","TARGET_NAME","START_TIME","STOP_TIME"}; public static String[] invalidIndexDirectories = {"CATALOG","DOCUMENT","EXTRAS","GAZETTER","INDEX","SOFTWARE","BROWSE"}; // private static String[] mandatoryManifestColumns = {"DATA_SET_ID","FILE_SPECIFICATION_NAME"}; public static String[] invalidManifestDirectories = {"INDEX"}; public static void main(String args[]) { //make sure only one argument is entered if(args.length > 1 || args.length == 0){ System.out.println("Please type the location of the options file."); System.exit(1); } //creates an object of type file that has the location of the options file optionsFile = new File(args[0]); //see if file exists and if not it prints an error and exits //it also checks to see that what you entered is a file and not a directory if(!optionsFile.exists()){ System.err.println("The file " + optionsFile + " does not exist"); System.err.println("Please check that the file exists and that the"); System.err.println("drive is properly mapped and logged into."); System.exit(1); } else if(!optionsFile.isFile()) { System.err.println(optionsFile + " is not a file"); System.exit(1); } readInOptionsFile(); parseOptionsFile(); createIndex.run(path, indexOptions, "INDEX"); } public static void readInOptionsFile(){ //Reads the options file into an arraylist called lines try{ fin = new BufferedReader(new FileReader(optionsFile.toString())); String line = ""; while((line = fin.readLine()) != null){ lines.add(line); } } catch(Exception e) {} //Reads the list of non_quoted_keywords try{ fin = new BufferedReader(new FileReader("list_of_non_quoted_keywords.txt")); String line = ""; while((line = fin.readLine()) != null){ non_quoted_keywords.add(line); } }catch(Exception e){} } public static void parseOptionsFile(){ String value = ""; //this just checks to see what index it will be creating or if it will //be creating both types. for(int lineIndex = 0; lineIndex < lines.size(); lineIndex++){ value = lines.get(lineIndex).toString(); if(value.trim().toUpperCase().equals("")){ path = new File(lines.get(++lineIndex).toString().trim()); } else if(value.trim().toUpperCase().equals("")){ manifestOptions = new ArrayList(); while(!lines.get(++lineIndex).toString().trim().equals("")){ manifestOptions.add(lines.get(lineIndex).trim()); if(lines.get(lineIndex).toString().trim().startsWith("COLUMN")){ String valuesList = lines.get(lineIndex).substring(lines.get(lineIndex).indexOf("=")+1); String[] values = valuesList.split(","); for(int i = 0; i < values.length; i++){ manifestColumns.add(values[i]); } } } } else if(value.trim().toUpperCase().equals("")){ indexOptions = new ArrayList(); while(!lines.get(++lineIndex).toString().trim().equals("")){ value = lines.get(lineIndex).toString().trim(); if(value.startsWith("VOLUME_ID")){ volId = "\"" + value.substring(value.indexOf("=") + 1) + "\""; } if(value.startsWith("COLUMN")){ boolean isFound = false; String valuesList = value.substring(value.indexOf("=")+1); String[] values = valuesList.split(","); for(int colIndex = 0; colIndex < values.length; colIndex++){ indexColumns.add(values[colIndex]); } for(int mandIndex = 0; mandIndex < mandatoryIndexColumns.length; mandIndex++){ isFound = false; for(int colIndex = 0; colIndex < values.length; colIndex++){ if(mandatoryIndexColumns[mandIndex].equals(values[colIndex])){ isFound = true; } } if(isFound == false){ indexColumns.add(mandatoryIndexColumns[mandIndex]); } } } indexOptions.add(value); } for(int colIndex = 0; colIndex < indexColumns.size(); colIndex++){ boolean foundNonQuotedVal = false; for(int nonQuoteInd = 0; nonQuoteInd < non_quoted_keywords.size(); nonQuoteInd++){ if(indexColumns.get(colIndex).toString().equals(non_quoted_keywords.get(nonQuoteInd).toString())){ indexInitValues.add("N/A"); foundNonQuotedVal = true; } } if(!foundNonQuotedVal){ indexInitValues.add("\"N/A\""); } } } } } }