/** closes resources and write everything to file */ public void shutdown() { pdb.closeDB(); // save the db if (newWeights == null) { newWeights = origWeights; } writePropertyFile( newWeights, genProps.getProperty("outWeightsLoc", genProps.getProperty("inWeightsLoc"))); userInterface.closeResources(); System.out.println("preferences saved and closed without error."); }
/** * Loads the case history into cache. This is where the background database chosen. * * @param dLoc the location of the database */ public void loadDB() { try { // TODO what about if we want to create a new db? if (!Boolean.parseBoolean(genProps.getProperty("newDB"))) { pdb.loadDB(); } } catch (Exception e) { System.err.println("Something wrong with loading DB"); } try { loadCLPolicies(); } catch (Exception e) { System.err.println("Error. Probably wrong path to P3P folder"); } }
/** loads [additional] policies from commandline (either -p or -f) */ private void loadCLPolicies() { // we already checked to make sure we have one of the options avaliable File pLoc = null; PolicyObject p = null; if (genProps.getProperty("p3pLocation", null) != null) { pLoc = new File(genProps.getProperty("p3pLocation")); if (!pLoc.exists()) { System.err.println( "no file found at p3p policy location specified by the -p3p option: " + genProps.getProperty("p3pLocation")); System.err.println("current location is " + System.getProperty("user.dir")); System.exit(1); } try { p = (new P3PParser()).parse(pLoc.getAbsolutePath()); if (p.getContextDomain() == null) { p.setContext( new Context( new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), genProps.getProperty("p3pLocation"))); } pdb.addPolicy(p); } catch (Exception e) { System.err.println("Error with parsing or database"); e.printStackTrace(); // System.exit(5); } } if (genProps.getProperty("p3pDirLocation", null) != null) { pLoc = new File(genProps.getProperty("p3pDirLocation")); File[] pfiles = pLoc.listFiles(); // System.err.println("pfiles for p3pDirLocation: "+pfiles); for (int i = 0; i < pfiles.length; i++) { pLoc = (pfiles[i]); if (!pLoc.exists()) { System.err.println( "no file found at p3p policy location specified by the -p3pDirLocation option, " + genProps.getProperty("p3pDirLocation")); System.exit(1); } try { p = (new P3PParser()).parse(pLoc.getAbsolutePath()); if (p.getContext().getDomain() == null) { p.setContext( new Context( new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), pfiles[i].getAbsolutePath())); } pdb.addPolicy(p); } catch (Exception e) { System.err.println("Einar needs to fix this parsing error."); e.printStackTrace(); } } } }