/** * Test of runCommand method, of class SystemUtils. This test will only work on a unix based * operating system. */ @Test public void testRunCommandHappy() throws Exception { /* TODO Add a check to make sure the current operating system is a unix * based one. */ LoggerFactory.getLogger("utils." + SystemUtilsTest.class.getSimpleName()) .debug("SystemUtilsTest.testRunCommandHappy"); /* Create a script that will create a text file with the text 'yay' and * then output the text in the file. */ try (PrintWriter writer = new PrintWriter("script.sh", "UTF-8")) { String create = "echo yay > yay.txt"; String cat = "cat yay.txt"; writer.println(create); writer.println(cat); } /* Run the newly created script, it should output the text in the file * yay.txt */ String expResult = SystemUtils.runCommand("bash script.sh"); String result = SystemUtils.runCommand("cat yay.txt"); assertEquals(expResult, result); SystemUtils.runCommand("rm script.sh yay.txt"); assertFalse(FileUtils.fileExists("script.sh")); assertFalse(FileUtils.fileExists("yay.txt")); }
public void testJavaVersionAtLeastFloat() { float version = SystemUtils.JAVA_VERSION_FLOAT; assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); version -= 0.1f; assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); version += 0.2f; assertEquals(false, SystemUtils.isJavaVersionAtLeast(version)); }
public void testJavaVersionAtLeastInt() { int version = SystemUtils.JAVA_VERSION_INT; assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); version -= 10; assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); version += 20; assertEquals(false, SystemUtils.isJavaVersionAtLeast(version)); }
public static HttpResponseCache install(Context context) throws IOException { ResponseCache installed = ResponseCache.getDefault(); if (installed instanceof Closeable) { ((Closeable) installed).close(); } File directory = SystemUtils.getCacheDir(context, "http"); long maxSize = SystemUtils.calculateDiskCacheSize(directory, MIN_DISK_CACHE_SIZE, MAX_DISK_CACHE_SIZE); return new HttpResponseCache(android.net.http.HttpResponseCache.install(directory, maxSize)); }
private ImageLoader(Context context) { File directory = SystemUtils.getCacheDir(context, "picasso"); long diskSize = SystemUtils.calculateDiskCacheSize(directory, MIN_DISK_CACHE_SIZE, MAX_DISK_CACHE_SIZE); int memSize = SystemUtils.calculateMemoryCacheSize(context); this.cache = new ImageCache(directory, diskSize, memSize); this.picasso = new Builder(context) .downloader(new ImageDownloader(context.getApplicationContext())) .memoryCache(cache) .build(); picasso.setIndicatorsEnabled(false); }
/** * Get specified unit test property. * * @param key Name of property * @return Property value */ public static String getUnitTestProperty(final String key) { Properties props = SystemUtils.loadProperties(UNIT_TEST_PROPS_FILE); if (props == null) { throw new WebGenomeSystemException("Cannot find 'unit_test.properties' file"); } return props.getProperty(key); }
public void testJavaAwtHeadless() { boolean atLeastJava14 = SystemUtils.isJavaVersionAtLeast(140); String expectedStringValue = System.getProperty("java.awt.headless"); String expectedStringValueWithDefault = System.getProperty("java.awt.headless", "false"); assertNotNull(expectedStringValueWithDefault); if (atLeastJava14) { boolean expectedValue = Boolean.valueOf(expectedStringValue).booleanValue(); if (expectedStringValue != null) { assertEquals(expectedStringValue, SystemUtils.JAVA_AWT_HEADLESS); } assertEquals(expectedValue, SystemUtils.isJavaAwtHeadless()); } else { assertNull(expectedStringValue); assertNull(SystemUtils.JAVA_AWT_HEADLESS); assertEquals(expectedStringValueWithDefault, "" + SystemUtils.isJavaAwtHeadless()); } assertEquals(expectedStringValueWithDefault, "" + SystemUtils.isJavaAwtHeadless()); }
/** * Gets Label font name awaylable on current running os * * @return label font name */ private static String getLabelFontName() { GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] names = g.getAvailableFontFamilyNames(); Arrays.sort(names); if (SystemUtils.isMac() && Arrays.binarySearch(names, "Helvetica Neue") >= 0) return "Helvetica Neue"; else if (Arrays.binarySearch(names, "Helvetica") >= 0) return "Helvetica"; else if (Arrays.binarySearch(names, "Arial") >= 0) return "Arial"; return getMonospacedFontName(); }
private void invalidUser(PrintWriter out) { out.println(SystemUtils.HeadTitle("Access Error - Redirect")); out.println("<BODY><CENTER><img src=\"/v5/images/foretees.gif\"><BR>"); out.println("<hr width=\"40%\">"); out.println("<BR><H2>Access Error</H2><BR>"); out.println("<BR><BR>Sorry, you must login before attempting to access these features.<BR>"); out.println("<BR><BR>Please <A HREF=\"Logout\">login</A>"); out.println("</CENTER></BODY></HTML>"); }
public void run() { timer.cancel(); // kill the timer thread // // call inactTimer to process timer scan of teecurr // SystemUtils.inactTimer(); // new newThreadMinT().start(); // spawn a new thread to process the timer // expiration }
/** * This method will test if you can connect and query something before handing over the * connection, This is required for our retry logic. * * @return */ private static boolean testConnection() { // connecting first time hence return false. if (tool == null) return false; try { tool.isInitialized(); } catch (Throwable ex) { SystemUtils.closeQuietly(tool); return false; } return true; }
/** * Send mailNotications. * * @param message The message body itself * @param eventType Type of notification * @param e An exception (can be null) */ private void sendMailNotifications(String message, NotificationType eventType, Throwable e) { String subjectPrefix = SUBJECT_PREFIX + "-" + eventType + ": "; // Subject is a specified string + first line of error message String subject = subjectPrefix + message.split("\n")[0]; // Body consists of four parts. StringBuffer body = new StringBuffer(); // 1: The host of the message body.append("Host: " + SystemUtils.getLocalHostName() + "\n"); body.append("Date: " + new Date().toString() + "\n"); // 2: The origin of the message, found by inspecting stack trace for (StackTraceElement elm : Thread.currentThread().getStackTrace()) { if (!elm.toString().startsWith(getClass().getName()) && !elm.toString().startsWith(Notifications.class.getName()) && !elm.toString().startsWith(Thread.class.getName())) { body.append(elm.toString() + "\n"); break; } } // 3: The given message body.append(message + "\n"); // 4: Optionally the exception if (e != null) { body.append(ExceptionUtils.getStackTrace(e)); } try { // Send the mail EMailUtils.sendEmail(MAIL_RECEIVER, MAIL_SENDER, subject, body.toString()); // Log as error log.error("Mailing {}{}", subjectPrefix, message, e); } catch (Exception e1) { // On trouble: Log and print it to system out, it's the best we can // do! String msg = "Could not send email on " + eventType.toString().toLowerCase() + " notification:\n" + body.toString() + "\n"; System.err.println(msg); e1.printStackTrace(System.err); log.error(msg, e1); } }
public static String getReportLocation() { String s = System.getProperty("erlide.logDirectory"); if (s == null) { if (SystemUtils.isOnWindows()) { s = "\\\\vhub\\tecsas\\shade\\erlide\\reports"; } else { s = "/proj/tecsas/SHADE/erlide/reports"; } } final File dir = new File(s); if (!dir.exists()) { s = System.getProperty("user.home"); } return s; }
/** * Gets Monospaced font name awailable on current running os * * @return monospaced font name */ public static String getMonospacedFontName() { String name = null; GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment(); String[] names = g.getAvailableFontFamilyNames(); Arrays.sort(names); if (SystemUtils.isMac() && Arrays.binarySearch(names, "Tahoma") >= 0) name = "Tahoma"; else if (Arrays.binarySearch(names, "Courier New") >= 0) name = "Courier New"; else if (Arrays.binarySearch(names, "Courier") >= 0) name = "Courier"; else if (Arrays.binarySearch(names, "Nimbus Mono L") >= 0) name = "Nimbus Mono L"; else if (Arrays.binarySearch(names, "Lucida Sans Typewriter") >= 0) name = "Lucida Sans Typewriter"; else if (Arrays.binarySearch(names, "Bitstream Vera Sans Mono") >= 0) name = "Bitstream Vera Sans Mono"; return (name == null) ? "Terminal" : name; }
private static void installNatives(File folder) throws Exception { OperatingSystem os = SystemUtils.getOS(); if (os == OperatingSystem.WINDOWS) { if (!new File(folder.getPath() + "/jinput-dx8_64.dll").exists()) { extractFromClasspath("/windows/jinput-dx8_64.dll", folder); extractFromClasspath("/windows/jinput-dx8.dll", folder); extractFromClasspath("/windows/jinput-raw_64.dll", folder); extractFromClasspath("/windows/jinput-raw.dll", folder); extractFromClasspath("/windows/lwjgl.dll", folder); extractFromClasspath("/windows/lwjgl64.dll", folder); extractFromClasspath("/windows/OpenAL32.dll", folder); extractFromClasspath("/windows/OpenAL64.dll", folder); } else { Log.message("Natives already exist."); } } else if (os == OperatingSystem.SOLARIS) { if (!new File(folder.getPath() + "/liblwjgl.so").exists()) { extractFromClasspath("/solaris/liblwjgl.so", folder); extractFromClasspath("/solaris/liblwjgl64.so", folder); extractFromClasspath("/solaris/libopenal.so", folder); extractFromClasspath("/solaris/libopenal64.so", folder); } else { Log.message("Natives already exist."); } } else if (os == OperatingSystem.LINUX) { if (!new File(folder.getPath() + "/liblwjgl.so").exists()) { extractFromClasspath("/linux/liblwjgl.so", folder); extractFromClasspath("/linux/liblwjgl64.so", folder); extractFromClasspath("/linux/libopenal.so", folder); extractFromClasspath("/linux/libopenal64.so", folder); } else { Log.message("Natives already exist."); } } else if (os == OperatingSystem.MACOSX) { if (!new File(folder.getPath() + "/openal.dylib").exists()) { extractFromClasspath("/macosx/liblwjgl.jnilib", folder); extractFromClasspath("/macosx/liblwjgl-osx.jnilib", folder); extractFromClasspath("/macosx/openal.dylib", folder); } else { Log.message("Natives already exist."); } } else { } System.setProperty("net.java.games.input.librarypath", folder.getAbsolutePath()); }
/** * Return a FileItem which is going to be automatically destroyed upon destruction of the request, * session or application. */ public static FileItem prepareFileItem(PipelineContext pipelineContext, int scope) { // We use the commons file upload utilities to save a file if (fileItemFactory == null) fileItemFactory = new DiskFileItemFactory(0, SystemUtils.getTemporaryDirectory()); final FileItem fileItem = fileItemFactory.createItem("dummy", "dummy", false, null); // Make sure the file is deleted appropriately if (scope == REQUEST_SCOPE) { deleteFileOnRequestEnd(pipelineContext, fileItem); } else if (scope == SESSION_SCOPE) { deleteFileOnSessionTermination(pipelineContext, fileItem); } else if (scope == APPLICATION_SCOPE) { deleteFileOnContextDestroyed(pipelineContext, fileItem); } else { throw new OXFException("Invalid context requested: " + scope); } // Return FileItem object return fileItem; }
// New -- returns data in HashMap private static Map viewSignups( HttpServletRequest req, PrintWriter out, Connection con, boolean json_mode) { int wait_list_id = 0; int wait_list_signup_id = 0; int sum_players = 0; int date = 0; int pos = 1; int time = SystemUtils.getTime(con); int today_date = (int) SystemUtils.getDate(con); int start_time = 0; int end_time = 0; int count = 0; int index = 0; int player_index = 0; Map waitlist_map = new HashMap(); waitlist_map.put("options", new HashMap()); waitlist_map.put("signups", new LinkedHashMap()); String sindex = req.getParameter( "index"); // index value of day (needed by Proshop_waitlist_slot when returning) String id = req.getParameter("waitListId"); // uid of the wait list we are working with String course = (req.getParameter("course") == null) ? "" : req.getParameter("course"); String returnCourse = (req.getParameter("returnCourse") == null) ? "" : req.getParameter("returnCourse"); String sdate = (req.getParameter("sdate") == null) ? "" : req.getParameter("sdate"); String name = (req.getParameter("name") == null) ? "" : req.getParameter("name"); String day_name = (req.getParameter("day_name") == null) ? "" : req.getParameter("day_name"); String sstart_time = (req.getParameter("start_time") == null) ? "" : req.getParameter("start_time"); String send_time = (req.getParameter("end_time") == null) ? "" : req.getParameter("end_time"); // String count = (req.getParameter("count") == null) ? "" : req.getParameter("count"); String jump = req.getParameter("jump"); String fullName = ""; String cw = ""; String notes = ""; String nineHole = ""; PreparedStatement pstmt = null; PreparedStatement pstmt2 = null; boolean tmp_found = false; boolean tmp_found2 = false; boolean master = (req.getParameter("view") != null && req.getParameter("view").equals("master")); boolean show_notes = (req.getParameter("show_notes") != null && req.getParameter("show_notes").equals("yes")); boolean alt_row = false; boolean tmp_converted = false; try { date = Integer.parseInt(sdate); index = Integer.parseInt(sindex); wait_list_id = Integer.parseInt(id); start_time = Integer.parseInt(sstart_time); end_time = Integer.parseInt(send_time); } catch (NumberFormatException e) { } try { count = getWaitList.getListCount(wait_list_id, date, index, time, !master, con); } catch (Exception exp) { out.println(exp.getMessage()); } // // isolate yy, mm, dd // int yy = date / 10000; int temp = yy * 10000; int mm = date - temp; temp = mm / 100; temp = temp * 100; int dd = mm - temp; mm = mm / 100; String report_date = SystemUtils.getLongDateTime(today_date, time, " at ", con); if (!json_mode) { out.println("<br>"); out.println( "<h3 align=center>" + ((master) ? "Master Wait List Sign-up Sheet" : "Current Wait List Sign-ups") + "</h3>"); out.println("<p align=center><font size=3><b><i>\"" + name + "\"</i></b></font></p>"); out.println("<table border=0 align=center>"); out.println("<tr><td><font size=\"2\">"); out.println( "Date: <b>" + day_name + " " + mm + "/" + dd + "/" + yy + "</b></td>"); out.println("<td> </td><td>"); if (!course.equals("")) { out.println("<font size=\"2\">Course: <b>" + course + "</b></font>"); } out.println("</td></tr>"); out.println( "<tr><td><font size=\"2\">Time: <b>" + SystemUtils.getSimpleTime(start_time) + " to " + SystemUtils.getSimpleTime(end_time) + "</b></font></td>"); out.println("<td></td>"); out.println("<td><font size=\"2\">Signups: <b>" + count + "</b></font></td>"); out.println("</table>"); out.println( "<p align=center><font size=2><b><i>List Generated on " + report_date + "</i></b></font></p>"); out.println("<table align=center border=1 bgcolor=\"#F5F5DC\">"); if (master) { out.println( "<tr bgcolor=\"#8B8970\" align=center style=\"color: black; font-weight: bold\">" + "<td height=35> Pos </td>" + "<td>Sign-up Time</td>" + "<td>Members</td>" + "<td>Desired Time</td>" + "<td> Players </td>" + "<td> On Sheet </td>" + "<td>Converted At</td>" + "<td> Converted By </td>" + ((show_notes) ? "<td> Notes </td>" : "") + "</tr>"); } else { out.println( "<tr bgcolor=\"#8B8970\" align=center style=\"color: black; font-weight: bold\">" + "<td height=35> Pos </td>" + "<td>Members</td>" + "<td>Desired Time</td>" + "<td> Players </td>" + ((show_notes) ? "<td> Notes </td>" : "") + "</tr>"); // + // "<td> On Sheet </td>" + // "</tr>"); // ((multi == 0) ? "" : "<td>Course</td>") + } out.println( "<!-- wait_list_id=" + wait_list_id + ", date=" + date + ", time=" + time + " -->"); } try { pstmt = con.prepareStatement( "" + "SELECT *, " + "DATE_FORMAT(created_datetime, '%c/%e/%y %r') AS created_time, " + "DATE_FORMAT(converted_at, '%c/%e/%y %r') AS converted_time " + // %l:%i %p "FROM wait_list_signups " + "WHERE wait_list_id = ? AND date = ? " + ((master) ? "" : "AND converted = 0 ") + ((!master && sindex.equals("0")) ? "AND ok_etime > ? " : "") + "ORDER BY created_datetime"); pstmt.clearParameters(); pstmt.setInt(1, wait_list_id); pstmt.setInt(2, date); if (!master && sindex.equals("0")) { pstmt.setInt(3, time); } ResultSet rs = pstmt.executeQuery(); while (rs.next()) { wait_list_signup_id = rs.getInt("wait_list_signup_id"); if (json_mode) { ((Map) waitlist_map.get("signups")) .put("signup_id_" + wait_list_signup_id, new LinkedHashMap()); ((Map) ((Map) waitlist_map.get("signups")).get("signup_id_" + wait_list_signup_id)) .put("players", new LinkedHashMap()); ((Map) ((Map) waitlist_map.get("signups")).get("signup_id_" + wait_list_signup_id)) .put("options", new HashMap()); } else { out.print( "<tr align=center" + ((alt_row) ? " style=\"background-color:white\"" : "") + "><td>" + pos + "</td>"); if (master) { out.println("<td> " + rs.getString("created_time") + " </td>"); } out.print("<td align=left>"); } // if (multi == 1) out.println("<td>" + rs.getString("course") + "</td>"); // // Display players in this signup // pstmt2 = con.prepareStatement( "" + "SELECT * " + "FROM wait_list_signups_players " + "WHERE wait_list_signup_id = ? " + "ORDER BY pos"); pstmt2.clearParameters(); pstmt2.setInt(1, wait_list_signup_id); ResultSet rs2 = pstmt2.executeQuery(); tmp_found2 = false; player_index = 0; while (rs2.next()) { if (json_mode) { player_index++; ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("players")) .put("player_" + player_index, new HashMap()); ((Map) ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("players")) .get("player_" + player_index)) .put("player_name", rs2.getString("player_name")); ((Map) ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("players")) .get("player_" + player_index)) .put("player_name", rs2.getString("player_name")); ((Map) ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("players")) .get("player_" + player_index)) .put("cw", rs2.getString("cw")); ((Map) ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("players")) .get("player_" + player_index)) .put("9hole", rs2.getInt("9hole")); } else { fullName = rs2.getString("player_name"); cw = rs2.getString("cw"); if (rs2.getInt("9hole") == 1) { cw = cw + "9"; } if (tmp_found2) { out.print(", "); } else { out.print(" "); } out.print(fullName + " <font style=\"font-size:9px\">(" + cw + ")</font>"); tmp_found2 = true; } sum_players++; nineHole = ""; // reset } pstmt2.close(); if (json_mode) { ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("options")) .put("notes", notes); ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("options")) .put("created_time", rs.getInt("created_time")); ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("options")) .put("converted", rs.getInt("converted")); ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("options")) .put("converted_time", rs.getString("converted_time")); ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("options")) .put("converted_by", rs.getString("converted_by")); ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("options")) .put("start_time", SystemUtils.getSimpleTime(rs.getInt("ok_stime"))); ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("options")) .put("end_time", SystemUtils.getSimpleTime(rs.getInt("ok_etime"))); ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("options")) .put("wait_list_signup_id", wait_list_signup_id); ((Map) ((Map) ((Map) waitlist_map.get("signups")) .get("signup_id_" + wait_list_signup_id)) .get("options")) .put("player_count", sum_players); } else { out.print("</td>"); out.println( "<td> " + SystemUtils.getSimpleTime(rs.getInt("ok_stime")) + " - " + SystemUtils.getSimpleTime(rs.getInt("ok_etime")) + " </td>"); out.println("<td>" + sum_players + "</td>"); if (master) { tmp_converted = rs.getInt("converted") == 1; out.println("<td>" + ((tmp_converted) ? "Yes" : "No") + "</td>"); out.println( "<td>" + ((tmp_converted) ? rs.getString("converted_time") : " ") + "</td>"); out.println( "<td>" + ((tmp_converted) ? rs.getString("converted_by") : " ") + "</td>"); } if (show_notes) { notes = rs.getString("notes").trim(); if (notes.equals("")) { notes = " "; } out.println("<td>" + notes + "</td>"); } out.print("</tr>"); } pos++; sum_players = 0; alt_row = alt_row == false; } pstmt.close(); } catch (Exception exc) { SystemUtils.buildDatabaseErrMsg( "Error loading wait list signups.", exc.toString(), out, false); } if (json_mode) { ((Map) waitlist_map.get("options")).put("index", sindex); ((Map) waitlist_map.get("options")).put("wait_list_id", wait_list_id); ((Map) waitlist_map.get("options")).put("date", "" + mm + "/" + dd + "/" + yy); ((Map) waitlist_map.get("options")).put("name", name); ((Map) waitlist_map.get("options")).put("time", time); ((Map) waitlist_map.get("options")).put("jump", jump); ((Map) waitlist_map.get("options")).put("returnCourse", returnCourse); ((Map) waitlist_map.get("options")).put("course", course); ((Map) waitlist_map.get("options")).put("master", master); ((Map) waitlist_map.get("options")).put("report_date", report_date); ((Map) waitlist_map.get("options")).put("show_notes", show_notes); } else { out.println("</table><br>"); out.println("<table align=center><tr>"); out.println("<form action=\"Member_jump\" method=\"POST\" target=\"_top\">"); out.println("<input type=\"hidden\" name=\"jump\" value=\"0\">"); out.println("<input type=\"hidden\" name=\"index\" value=" + sindex + ">"); out.println( "<input type=\"hidden\" name=\"course\" value=\"" + ((!returnCourse.equals("")) ? returnCourse : course) + "\">"); out.println("<td><input type=\"submit\" value=\"Tee Sheet\"></td></form>"); out.println("<td> </td>"); out.println("<form action=\"Member_waitlist\" method=\"POST\">"); out.println("<input type=\"hidden\" name=\"waitListId\" value=\"" + wait_list_id + "\">"); out.println("<input type=\"hidden\" name=\"date\" value=\"" + date + "\">"); out.println("<input type=\"hidden\" name=\"day\" value=\"" + day_name + "\">"); out.println("<input type=\"hidden\" name=\"index\" value=\"" + sindex + "\">"); out.println("<input type=\"hidden\" name=\"course\" value=\"" + course + "\">"); out.println("<input type=\"hidden\" name=\"returnCourse\" value=\"" + returnCourse + "\">"); out.println("<input type=\"hidden\" name=\"jump\" value=\"" + jump + "\">"); out.println("<td><input type=\"submit\" value=\"Return\"></td></form>"); out.println("</tr></table></form>"); out.println("<br>"); } return waitlist_map; } // end viewSignups
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); PreparedStatement pstmt = null; Statement stmt = null; ResultSet rs = null; HttpSession session = SystemUtils.verifyMem(req, out); // check for intruder if (session == null) return; Connection con = Connect.getCon(req); // get DB connection if (con == null) { resp.setContentType("text/html"); out.println(SystemUtils.HeadTitle("DB Connection Error")); out.println("<BODY><CENTER><BR>"); out.println("<BR><BR><H3>Database Connection Error</H3>"); out.println("<BR><BR>Unable to connect to the Database."); out.println("<BR>Please try again later."); out.println("<BR><BR>If problem persists, contact customer support."); out.println("<BR><BR>"); out.println("<a href=\"javascript:history.back(1)\">Return</a>"); out.println("</CENTER></BODY></HTML>"); out.close(); return; } // // Get needed vars out of session obj // String club = (String) session.getAttribute("club"); String user = (String) session.getAttribute("user"); String caller = (String) session.getAttribute("caller"); int activity_id = (Integer) session.getAttribute("activity_id"); int foretees_mode = 0; String stype_id = req.getParameter("type_id"); int type_id = 0; String sgroup_id = req.getParameter("group_id"); int group_id = 0; String sitem_id = req.getParameter("item_id"); int item_id = 0; try { type_id = Integer.parseInt(stype_id); } catch (NumberFormatException ignore) { } try { group_id = Integer.parseInt(sgroup_id); } catch (NumberFormatException ignore) { } try { item_id = Integer.parseInt(sitem_id); } catch (NumberFormatException ignore) { } out.println( "<!-- type_id=" + type_id + ", group_id=" + group_id + ", item_id=" + item_id + " -->"); // // START PAGE OUTPUT // out.println(SystemUtils.HeadTitle("Member Acivities")); out.println("<style>"); out.println(".actLink { color: black }"); out.println(".actLink:hover { color: #336633 }"); // out.println(".playerTD {width:125px}"); out.println("</style>"); out.println( "<body bgcolor=\"#CCCCAA\" text=\"#000000\" link=\"#336633\" vlink=\"#8B8970\" alink=\"#8B8970\">"); SystemUtils.getMemberSubMenu(req, out, caller); // required to allow submenus on this page // // DISPLAY A LIST OF AVAILABLE ACTIVITIES // out.println( "<p align=center><b><font size=5 color=#336633><BR><BR>Available Activities</font></b></p>"); out.println( "<p align=center><b><font size=3 color=#000000>Select your desired activity from the list below.<br>NOTE: You can set your default activity under <a href=\"Member_services\" class=actLink>Settings</a>.</font></b></p>"); out.println("<table align=center>"); try { stmt = con.createStatement(); rs = stmt.executeQuery("SELECT foretees_mode FROM club5 WHERE clubName <> '';"); if (rs.next()) { foretees_mode = rs.getInt(1); } // if they have foretees then give a link in to the golf system if (foretees_mode != 0) { out.println( "<tr><td align=center><b><a href=\"Member_jump?switch&activity_id=0\" class=linkA style=\"color:#336633\" target=_top>Golf</a></b></td></tr>"); // ForeTees } // build a link to any activities they have access to rs = stmt.executeQuery( "SELECT * FROM activities " + "WHERE parent_id = 0 " + "ORDER BY activity_name"); while (rs.next()) { out.println( "<tr><td align=center><b><a href=\"Member_jump?switch&activity_id=" + rs.getInt("activity_id") + "\" class=linkA style=\"color:#336633\" target=_top>" + rs.getString("activity_name") + "</a></b></td></tr>"); } stmt.close(); } catch (Exception exc) { out.println("<p>ERROR:" + exc.toString() + "</p>"); } finally { try { rs.close(); } catch (Exception ignore) { } try { stmt.close(); } catch (Exception ignore) { } } out.println("</table>"); out.println("</body></html>"); /* out.println("<script>"); out.println("function load_types() {"); out.println(" try {document.forms['frmSelect'].item_id.selectedIndex = -1; } catch (err) {}"); out.println(" document.forms['frmSelect'].group_id.selectedIndex = -1;"); out.println(" document.forms['frmSelect'].submit();"); out.println("}"); out.println("function load_groups() {"); out.println(" document.forms['frmSelect'].submit();"); out.println("}"); out.println("function load_times(id) {"); out.println(" top.bot.location.href='Member_gensheets?id=' + id;"); out.println("}"); out.println("</script>"); out.println("<form name=frmSelect>"); // LOAD ACTIVITY TYPES out.println("<select name=type_id onchange=\"load_types()\">"); if (type_id == 0) { out.println("<option>CHOOSE TYPE</option>"); } try { stmt = con.createStatement(); rs = stmt.executeQuery("SELECT * FROM activities WHERE parent_id = 0"); while (rs.next()) { Common_Config.buildOption(rs.getInt("activity_id"), rs.getString("activity_name"), type_id, out); } stmt.close(); } catch (Exception exc) { out.println("<p>ERROR:" + exc.toString() + "</p>"); } out.println(""); out.println("</select>"); // LOAD ACTIVITIES BY GROUP TYPE out.println("<select name=group_id onchange=\"load_groups()\">"); if (type_id == 0) { out.println("<option>CHOOSE TYPE</option>"); } else { try { stmt = con.createStatement(); rs = stmt.executeQuery("SELECT activity_id, activity_name FROM activities WHERE parent_id = " + type_id); rs.last(); if (rs.getRow() == 1) { group_id = rs.getInt("activity_id"); out.println("<!-- ONLY FOUND 1 GROUP -->"); } else { out.println("<option value=\"0\">CHOOSE...</option>"); } rs.beforeFirst(); while (rs.next()) { Common_Config.buildOption(rs.getInt("activity_id"), rs.getString("activity_name"), group_id, out); } stmt.close(); } catch (Exception exc) { out.println("<p>ERROR:" + exc.toString() + "</p>"); } } out.println(""); out.println("</select>"); boolean do_load = false; if (group_id > 0 ) { //|| sitem_id != null // LOAD ACTIVITIES BY ITEM TYPE try { stmt = con.createStatement(); rs = stmt.executeQuery("SELECT activity_id, activity_name FROM activities WHERE parent_id = " + group_id); rs.last(); if (rs.getRow() == 0) { // no sub groups found do_load = true; item_id = group_id; } else if (rs.getRow() == 1) { // single sub group found (pre select it) item_id = rs.getInt("activity_id"); out.println("<!-- ONLY FOUND 1 ITEM -->"); } else { out.println("<select name=item_id onchange=\"load_times(this.options[this.selectedIndex].value)\">"); out.println("<option value=\"0\">CHOOSE...</option>"); } if (!do_load) { rs.beforeFirst(); while (rs.next()) { Common_Config.buildOption(rs.getInt("activity_id"), rs.getString("activity_name"), item_id, out); } } stmt.close(); out.println(""); out.println("</select>"); } catch (Exception exc) { out.println("<p>ERROR:" + exc.toString() + "</p>"); } } out.println("</form>"); out.println("<p><a href=\"Member_genrez\">Reset</a></p>"); try { con.close(); } catch (Exception ignore) {} if (do_load) out.println("<script>load_times(" + item_id + ")</script>"); //out.println("<iframe name=ifSheet src=\"\" style=\"width:640px height:480px\"></iframe>"); */ out.close(); }
public static void initializeLookAndFeel() throws InitializationException { if (lookAndFeelInitialized) { return; } try { LogManager.log("... initializing look and feel"); LogManager.indent(); switch (UiMode.getCurrentUiMode()) { case SWING: String className = System.getProperty(LAF_CLASS_NAME_PROPERTY); if (className == null) { LogManager.log( "... custom look and feel class name was not specified, using system default"); className = UiUtils.getDefaultLookAndFeelClassName(); } else if (!className.contains(StringUtils.DOT)) { // short name of the L&F class className = UiUtils.getLookAndFeelClassNameByShortName(className); } LogManager.log("... class name: " + className); if (Boolean.getBoolean(LAF_DECORATED_WINDOWS_PROPERTY)) { JFrame.setDefaultLookAndFeelDecorated(true); } try { Thread jdkFileChooserWarningLogThread = null; try { // this helps to avoid some GTK L&F bugs for some locales LogManager.log("... get installed L&Fs"); UIManager.getInstalledLookAndFeels(); LogManager.log("... set specified L&F"); UIManager.setLookAndFeel(className); LogManager.log("... check headless"); if (GraphicsEnvironment.isHeadless()) { HeadlessException e = new HeadlessException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_INIT_UI_HEADLESS)); System.err.println( ResourceUtils.getString(UiUtils.class, RESOURCE_FAILED_TO_INIT_UI)); System.err.println(e.getMessage()); throw new InitializationException( ResourceUtils.getString(UiUtils.class, RESOURCE_FAILED_TO_INIT_UI), e); } if (System.getProperty("os.name").startsWith("Windows")) { // workaround for the issue with further using JFileChooser // in case of missing system icons // Java Issue : // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6210674 // NBI Issue : // http://www.netbeans.org/issues/show_bug.cgi?id=105065 // it also a workaround for two more bugs // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6449933 // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6489447 LogManager.log("... creating JFileChooser object to check possible issues with UI"); if (System.getProperty("java.version").startsWith("1.6")) { File desktop = new File(SystemUtils.getUserHomeDirectory(), "Desktop"); File[] zips = null; final List<String> names = new ArrayList<String>(); if (FileUtils.exists(desktop)) { zips = desktop.listFiles( new FileFilter() { public boolean accept(File pathname) { boolean result = pathname.getName().endsWith(".zip") && pathname.length() > 1000000L; if (result) { names.add(pathname.getName()); } return result; } }); } if (zips != null && zips.length > 0) { jdkFileChooserWarningLogThread = new NbiThread() { @Override public void run() { try { sleep(8000); // 8 seconds } catch (InterruptedException e) { return; } final File lock = new File( Installer.getInstance().getLocalDirectory(), Installer.LOCK_FILE_NAME); LogManager.log("\n... !!! WARNING !!!"); LogManager.log( "... There are some big zip files on your desktop: " + StringUtils.asString(names)); LogManager.log( "... In case installer UI does not appear for a long time:"); LogManager.log("... 1) kill the installer process"); LogManager.log( "... 2) move those zip files somewhere from the desktop"); LogManager.log("... 3) delete " + lock); LogManager.log("... 4) run installer again"); LogManager.log( "... For more details see the following bugs descriptions: "); LogManager.log( "... http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6372808"); LogManager.log( "... http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050516"); } }; jdkFileChooserWarningLogThread.start(); } } if (SwingUtilities.isEventDispatchThread()) { new JFileChooser(); } else { try { SwingUtilities.invokeAndWait( new Runnable() { public void run() { new JFileChooser(); } }); } catch (InvocationTargetException e) { throw (e.getCause() != null) ? e.getCause() : e; } } if (jdkFileChooserWarningLogThread != null) { jdkFileChooserWarningLogThread.interrupt(); jdkFileChooserWarningLogThread = null; } LogManager.log("... getting default Toolkit to check possible issues with UI"); Toolkit.getDefaultToolkit(); // workaround for JDK issue with JProgressBar using StyleXP // http://www.netbeans.org/issues/show_bug.cgi?id=106876 // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337517 LogManager.log("... creating JProgressBar object to check possible issues with UI"); new JProgressBar().getMaximumSize(); LogManager.log("... all UI checks done"); } LogManager.log("... L&F is set"); } catch (Throwable e) { if (jdkFileChooserWarningLogThread != null) { jdkFileChooserWarningLogThread.interrupt(); jdkFileChooserWarningLogThread = null; } // we're catching Throwable here as pretty much anything can happen // while setting the look and feel and we have no control over it // if something wrong happens we should fall back to the default // cross-platform look and feel which is assumed to be working // correctly LogManager.log( "... could not activate defined L&F, initializing cross-platfrom one", e); if (e instanceof InternalError) { System.err.println(e.getMessage()); } else if (e instanceof ExceptionInInitializerError) { final Throwable cause = e.getCause(); if ((cause != null) && (cause instanceof HeadlessException)) { System.err.println(cause.getMessage()); } } className = UIManager.getCrossPlatformLookAndFeelClassName(); LogManager.log("... cross-platform L&F class-name : " + className); UIManager.setLookAndFeel(className); if (System.getProperty(LAF_CLASS_NAME_PROPERTY) != null) { // Throw exception only if user specified custom L&F, // otherwise just go to initialization of cross-platfrom L&F // (Exception e is already logged above) // See also http://www.netbeans.org/issues/show_bug.cgi?id=122557 // This exception would be thrown only if cross-platform LAF is successfully // installed throw new InitializationException( ResourceUtils.getString(UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_DEFINED_LAF), e); } } } catch (NoClassDefFoundError e) { throw new InitializationException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_CROSSPLATFORM_LAF), e); } catch (ClassNotFoundException e) { throw new InitializationException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_CROSSPLATFORM_LAF), e); } catch (InstantiationException e) { throw new InitializationException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_CROSSPLATFORM_LAF), e); } catch (IllegalAccessException e) { throw new InitializationException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_CROSSPLATFORM_LAF), e); } catch (UnsupportedLookAndFeelException e) { throw new InitializationException( ResourceUtils.getString( UiUtils.class, RESOURCE_FAILED_TO_ACTIVATE_CROSSPLATFORM_LAF), e); } break; } } finally { LogManager.unindent(); LogManager.log("... initializing L&F finished"); if (Boolean.getBoolean("nbi.look.and.feel.dump.defaults")) { try { LogManager.logIndent("... dumping UIManger L&F defaults: "); Hashtable hash = (Hashtable) UIManager.getLookAndFeelDefaults(); Enumeration keys = hash.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); LogManager.log("" + key + " = " + hash.get(key)); } } catch (Exception e) { LogManager.log(e); } finally { LogManager.unindent(); } } lookAndFeelInitialized = true; lookAndFeelType = getLAF(); } }
/** * Checks if one {@code Class} can be assigned to a variable of another {@code Class}. * * <p>Unlike the {@link Class#isAssignableFrom(java.lang.Class)} method, this method takes into * account widenings of primitive classes and {@code null}s. * * <p>Primitive widenings allow an int to be assigned to a long, float or double. This method * returns the correct result for these cases. * * <p>{@code Null} may be assigned to any reference type. This method will return {@code true} if * {@code null} is passed in and the toClass is non-primitive. * * <p>Specifically, this method tests whether the type represented by the specified {@code Class} * parameter can be converted to the type represented by this {@code Class} object via an identity * conversion widening primitive or widening reference conversion. See <em><a * href="http://docs.oracle.com/javase/specs/">The Java Language Specification</a></em>, sections * 5.1.1, 5.1.2 and 5.1.4 for details. * * <p><strong>Since Lang 3.0,</strong> this method will default behavior for calculating * assignability between primitive and wrapper types <em>corresponding to the running Java * version</em>; i.e. autoboxing will be the default behavior in VMs running Java versions > * 1.5. * * @param cls the Class to check, may be null * @param toClass the Class to try to assign into, returns false if null * @return {@code true} if assignment possible */ public static boolean isAssignable(final Class<?> cls, final Class<?> toClass) { return isAssignable(cls, toClass, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5)); }
@Test(expected = Exception.class) public void testRunCommandFail() throws Exception { LoggerFactory.getLogger("utils." + SystemUtilsTest.class.getSimpleName()) .debug("SystemUtilsTest.testRunCommandFail"); SystemUtils.runCommand("cp doesnt_exists.txt yay.txt"); }
/** * Utility method to decode a multipart/fomr-data stream and return a Map of parameters of type * Object[], each of which can be a String or FileData. */ public static Map<String, Object[]> getParameterMapMultipart( PipelineContext pipelineContext, final ExternalContext.Request request, String headerEncoding) { final Map<String, Object[]> uploadParameterMap = new HashMap<String, Object[]>(); try { // Setup commons upload // Read properties // NOTE: We use properties scoped in the Request generator for historical reasons. Not too // good. int maxSize = RequestGenerator.getMaxSizeProperty(); int maxMemorySize = RequestGenerator.getMaxMemorySizeProperty(); final DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory(maxMemorySize, SystemUtils.getTemporaryDirectory()); final ServletFileUpload upload = new ServletFileUpload(diskFileItemFactory) { protected FileItem createItem(Map headers, boolean isFormField) throws FileUploadException { if (isFormField) { // Handle externalized values final String externalizeFormValuesPrefix = org.orbeon.oxf.properties.Properties.instance() .getPropertySet() .getString(ServletExternalContext.EXTERNALIZE_FORM_VALUES_PREFIX_PROPERTY); final String fieldName = getFieldName(headers); if (externalizeFormValuesPrefix != null && fieldName.startsWith(externalizeFormValuesPrefix)) { // In this case, we do as if the value content is an uploaded file so that it can // be externalized return super.createItem(headers, false); } else { // Just create the FileItem using the default way return super.createItem(headers, isFormField); } } else { // Just create the FileItem using the default way return super.createItem(headers, isFormField); } } }; upload.setHeaderEncoding(headerEncoding); upload.setSizeMax(maxSize); // Add a listener to destroy file items when the pipeline context is destroyed pipelineContext.addContextListener( new PipelineContext.ContextListenerAdapter() { public void contextDestroyed(boolean success) { for (final String name : uploadParameterMap.keySet()) { final Object values[] = uploadParameterMap.get(name); for (final Object currentValue : values) { if (currentValue instanceof FileItem) { final FileItem fileItem = (FileItem) currentValue; fileItem.delete(); } } } } }); // Wrap and implement just the required methods for the upload code final InputStream inputStream; try { inputStream = request.getInputStream(); } catch (IOException e) { throw new OXFException(e); } final RequestContext requestContext = new RequestContext() { public int getContentLength() { return request.getContentLength(); } public InputStream getInputStream() { // NOTE: The upload code does not actually check that it doesn't read more than the // content-length // sent by the client! Maybe here would be a good place to put an interceptor and make // sure we // don't read too much. return new InputStream() { public int read() throws IOException { return inputStream.read(); } }; } public String getContentType() { return request.getContentType(); } public String getCharacterEncoding() { return request.getCharacterEncoding(); } }; // Parse the request and add file information try { for (Object o : upload.parseRequest(requestContext)) { final FileItem fileItem = (FileItem) o; // Add value to existing values if any if (fileItem.isFormField()) { // Simple form field // Assume that form fields are in UTF-8. Can they have another encoding? If so, how is // it specified? StringUtils.addValueToObjectArrayMap( uploadParameterMap, fileItem.getFieldName(), fileItem.getString(STANDARD_PARAMETER_ENCODING)); } else { // File StringUtils.addValueToObjectArrayMap( uploadParameterMap, fileItem.getFieldName(), fileItem); } } } catch (FileUploadBase.SizeLimitExceededException e) { // Should we do something smart so we can use the Presentation // Server error page anyway? Right now, this is going to fail // miserably with an error. throw e; } catch (UnsupportedEncodingException e) { // Should not happen throw new OXFException(e); } finally { // Close the input stream; if we don't nobody does, and if this stream is // associated with a temporary file, that file may resist deletion if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { throw new OXFException(e); } } } return uploadParameterMap; } catch (FileUploadException e) { throw new OXFException(e); } }
// ***************************************************** // Process the request from Member_sheet // ***************************************************** // public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); PreparedStatement pstmt3 = null; Statement stmt = null; ResultSet rs = null; HttpSession session = SystemUtils.verifyMem(req, out); // check for intruder if (session == null) { return; } Connection con = SystemUtils.getCon(session); // get DB connection if (con == null) { out.println(SystemUtils.HeadTitle("DB Connection Error")); out.println( "<BODY bgcolor=\"#ccccaa\"><CENTER><img src=\"/" + rev + "/images/foretees.gif\"><BR>"); out.println("<hr width=\"40%\">"); out.println("<BR><BR><H3>Database Connection Error</H3>"); out.println("<BR><BR>Unable to connect to the Database."); out.println("<BR>Please try again later."); out.println("<BR><BR>If problem persists, please contact customer support."); out.println("<BR><BR>"); out.println("<font size=\"2\">"); out.println("<form method=\"get\" action=\"javascript:history.back(1)\">"); out.println("<input type=\"submit\" value=\"Return\" style=\"text-decoration:underline;\">"); out.println("</form></font>"); out.println("</CENTER></BODY></HTML>"); out.close(); return; } // Create Json response for later use Gson gson_obj = new Gson(); // HashMap for later use by gson Map<String, Object> hashMap = new HashMap<String, Object>(); // Check if we will only be return json data boolean json_mode = (req.getParameter("jsonMode")) != null; // // See if we are here to VIEW a wait list // if (req.getParameter("view") != null && req.getParameter("waitListId") != null) { if (json_mode) { out.print(gson_obj.toJson(viewSignups(req, out, con, true))); } else { viewSignups(req, out, con); } return; } String jump = "0"; // jump index - default to zero (for _sheet) if (req.getParameter("jump") != null) { // if jump index provided jump = req.getParameter("jump"); } // // Get this session's username // String club = (String) session.getAttribute("club"); String user = (String) session.getAttribute("user"); String name = (String) session.getAttribute("name"); // get users full name String sindex = req.getParameter("index"); // index value of day (needed by Member_sheet when returning) String course = req.getParameter("course"); // Name of Course String id = req.getParameter("waitListId"); // uid of the wait list we are working with String returnCourse = ""; if (req.getParameter("returnCourse") != null) { // if returnCourse provided returnCourse = req.getParameter("returnCourse"); } String sdate = req.getParameter("date"); // date of the request (yyyymmdd) String day_name = req.getParameter("day"); // name of the day String p5 = req.getParameter("p5"); // 5-somes supported int index = 0; int wait_list_id = 0; int count = 0; int mm = 0; int dd = 0; int yy = 0; int date = 0; int time = SystemUtils.getTime(con); // // Convert the values from string to int // try { wait_list_id = Integer.parseInt(id); index = Integer.parseInt(sindex); date = Integer.parseInt(sdate); } catch (NumberFormatException e) { } // get our date parts yy = date / 10000; mm = date - (yy * 10000); dd = mm - (mm / 100) * 100; mm = mm / 100; // // parm block to hold the wait list parameters // parmWaitList parmWL = new parmWaitList(); // allocate a parm block parmWL.wait_list_id = wait_list_id; try { getWaitList.getParms(con, parmWL); // get the wait list config // if members can see the wait list then get the count if (parmWL.member_view == 1) { count = getWaitList.getListCount(wait_list_id, date, index, time, true, con); } } catch (Exception exp) { out.println(exp.getMessage()); } int onlist = 0; try { onlist = getWaitList.onList(user, wait_list_id, date, con); } catch (Exception exp) { out.println(exp.toString()); } String waitlist_notice = ""; if (onlist == 0) { // not on the list try { // out.println("<pre>"); waitlist_notice = getWaitList.getNotice(wait_list_id, con); // out.println("</pre>"); } catch (Exception exp) { } } if (json_mode) { // If in json mode, add data to hashmap // New skin uses Member_waitlist in json mode exclusively. // Group the data we want to send to javascript in a hash map hashMap.put("wait_list_id", wait_list_id); hashMap.put("waitlist_notice", waitlist_notice); hashMap.put("date", "" + mm + "/" + dd + "/" + yy); hashMap.put("start_time", SystemUtils.getSimpleTime(parmWL.start_time)); hashMap.put("end_time", SystemUtils.getSimpleTime(parmWL.end_time)); hashMap.put("member_access", parmWL.member_access); hashMap.put("member_view", parmWL.member_view); hashMap.put("onlist", onlist); hashMap.put("index", index); hashMap.put("course", course); hashMap.put("count", count); hashMap.put("name", parmWL.name); out.print(gson_obj.toJson(hashMap)); return; } else { // If not in json mode, output data directly to user out.println( "<!-- wait_list_id=" + wait_list_id + ", date=" + date + ", count=" + count + " -->"); // // ******************************************************************** // Build a page to display Wait List details to member // ******************************************************************** // out.println("<html>"); out.println("<head>"); out.println( "<link rel=\"stylesheet\" href=\"/" + rev + "/web utilities/foretees2.css\" type=\"text/css\">"); out.println("<title>Member Wait List Registration Page</title>"); out.println("</head>"); out.println( "<body bgcolor=\"#ccccaa\" text=\"#000000\" link=\"#FFFFFF\" vlink=\"#FFFFFF\" alink=\"#FF0000\" topmargin=\"0\">"); out.println("<font face=\"Arial, Helvetica, Sans-serif\"><center>"); out.println( "<table border=\"0\" width=\"100%\" align=\"center\" valign=\"top\">"); // large table for // whole page out.println("<tr><td valign=\"top\" align=\"center\">"); out.println( "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#336633\" align=\"center\" valign=\"top\">"); out.println("<tr><td align=\"left\" width=\"300\"> "); out.println("<img src=\"/" + rev + "/images/foretees.gif\" border=0>"); out.println("</td>"); out.println("<td align=\"center\">"); out.println("<font color=\"ffffff\" size=\"5\">Member Wait List Registration</font>"); out.println("</font></td>"); out.println("<td align=\"center\" width=\"300\">"); out.println("<font size=\"1\" color=\"#ffffff\">Copyright </font>"); out.println("<font size=\"2\" color=\"#ffffff\">© </font>"); out.println( "<font size=\"1\" color=\"#ffffff\">ForeTees, LLC <br> 2009 All rights reserved."); out.println("</font><font size=\"3\">"); out.println( "<br><br><a href=\"/" + rev + "/member_help.htm\" target=\"_blank\"><b>Help</b></a>"); out.println("</font></td>"); out.println("</tr></table>"); out.println("<br>"); out.println("<table border=\"1\" cols=\"1\" bgcolor=\"#f5f5dc\" cellpadding=\"3\">"); out.println("<tr>"); out.println("<td width=\"620\" align=\"center\">"); out.println("<font size=\"3\">"); out.println("<b>Wait List Registration</b><br></font>"); out.println("<font size=\"2\">"); out.println( "The golf shop is running a wait list " + ((index == 0) ? "today" : "on this day") + ". "); out.println( "The wait list you've selected is running from <nobr>" + SystemUtils.getSimpleTime(parmWL.start_time) + "</nobr> till <nobr>" + SystemUtils.getSimpleTime(parmWL.end_time) + ".</nobr> "); out.println("Review the information below and click on 'Continue With Request' to continue."); out.println( "<br>OR click on 'Cancel Request' to delete the request. To return without changes click on 'Go Back'."); // out.println("<br><br><b>NOTE:</b> Only the person that originates the request will be // allowed to cancel it or change these values."); out.println("</font></td></tr>"); out.println("</table>"); out.println("<br><br>"); out.println("<table border=0>"); out.println("<tr><td><font size=\"2\">"); out.println( "Date: <b>" + day_name + " " + mm + "/" + dd + "/" + yy + "</b></td>"); out.println("<td> </td><td>"); if (!course.equals("")) { out.println("<font size=\"2\">Course: <b>" + course + "</b></font>"); } out.println("</td></tr>"); out.println( "<tr><td><font size=\"2\">Wait List: <b>" + SystemUtils.getSimpleTime(parmWL.start_time) + " to " + SystemUtils.getSimpleTime(parmWL.end_time) + "</b></font></td>"); out.println("<td></td>"); out.println("<td><font size=\"2\">Signups:<b>"); out.print(((parmWL.member_view == 1) ? count : "N/A")); out.println("</b></font></td>"); out.println("</table>"); out.println("<br>"); out.println("<table border=\"0\" align=\"center\">"); // table to contain 2 tables below out.println("<tr>"); out.println("<td align=\"center\" valign=\"top\">"); out.println( "<table border=\"1\" bgcolor=\"#f5f5dc\" align=\"center\" width=\"500\" cellpadding=\"5\" cellspacing=\"5\">"); // table for request details out.println("<tr bgcolor=\"#336633\"><td align=\"center\">"); out.println("<font color=\"ffffff\" size=\"3\">"); out.println( "<b>" + ((!parmWL.name.equals("")) ? parmWL.name : "Wait List Information") + "</b>"); out.println("</font></td></tr>"); out.println("<tr>"); out.println("<form action=\"Member_waitlist_slot\" method=\"post\">"); out.println("<input type=\"hidden\" name=\"waitListId\" value=\"" + wait_list_id + "\">"); out.println("<input type=\"hidden\" name=\"sdate\" value=\"" + date + "\">"); out.println("<input type=\"hidden\" name=\"day\" value=\"" + day_name + "\">"); out.println("<input type=\"hidden\" name=\"index\" value=\"" + sindex + "\">"); out.println("<input type=\"hidden\" name=\"course\" value=\"" + course + "\">"); out.println("<input type=\"hidden\" name=\"returnCourse\" value=\"" + returnCourse + "\">"); out.println("<input type=\"hidden\" name=\"jump\" value=\"" + jump + "\">"); out.println("<td><font size=\"2\"><br>"); // see if they are already on the wait list out.println("<input type=\"hidden\" name=\"signupId\" value=\"" + onlist + "\">"); if (onlist == 0) { // not on the list // out.println("The golf shop is running a wait list " + ((index == 0) ? "today": "on this // day") + ". "); // out.println("The wait list you've selected is running from " + // SystemUtils.getSimpleTime(parmWL.start_time) + " till " + // SystemUtils.getSimpleTime(parmWL.end_time) + ". "); // try { // out.println("<pre>"); // out.print(getWaitList.getNotice(wait_list_id, con)); // out.println("</pre>"); out.print(waitlist_notice); // } catch (Exception exp) { } if (parmWL.member_access == 1) { out.println( "<br><p align=center><input type=submit value=\"Continue With Sign-up\" name=\"continue\"></p>"); } else { out.println("<p align=center><b>Contact the golf shop to get on the wait list.</b></p>"); } } else { // already on this list out.println( "<p align=center><b><i>You are already signed up for this wait list.</b></i></p>"); if (parmWL.member_access == 1) { out.println( "<br><p align=center><input type=submit value=\"Modify Your Sign-up\" name=\"continue\"></p>"); } else { out.println( "<p align=center><b>Contact the golf shop to make changes or cancel your entry.</b></p>"); } } if (parmWL.member_view == 1 && count > 0) { out.println( "<p align=center><input type=button value=\"View Wait List\" name=\"view\" onclick=\"document.forms['frmView'].submit();\"></p>"); } out.println("<br></font></td>"); out.println("</table>"); out.println("</form>"); out.println("<br>"); if (index == 999) { // out.println("<form action=\"Member_teelist\" method=\"GET\">"); out.println("<form action=\"/" + rev + "/member_teemain.htm\" method=\"GET\">"); } else if (index == 995) { // out.println("<form action=\"Member_teelist_list\" method=\"GET\">"); out.println("<form action=\"/" + rev + "/member_teemain2.htm\" method=\"GET\">"); } else { out.println("<form action=\"Member_jump\" method=\"POST\">"); out.println("<input type=\"hidden\" name=\"jump\" value=" + jump + ">"); out.println("<input type=\"hidden\" name=\"index\" value=" + index + ">"); out.println( "<input type=\"hidden\" name=\"course\" value=\"" + ((!returnCourse.equals("")) ? returnCourse : course) + "\">"); } out.println("<font size=2>Return w/o Changes:</font><br>"); out.println("<input type=\"submit\" value=\"Go Back\" name=\"cancel\"></form>"); out.println("<form action=\"Member_waitlist\" method=\"GET\" name=frmView>"); out.println("<input type=\"hidden\" name=\"view\" value=\"current\">"); out.println("<input type=\"hidden\" name=\"waitListId\" value=\"" + wait_list_id + "\">"); out.println("<input type=\"hidden\" name=\"sdate\" value=\"" + date + "\">"); out.println("<input type=\"hidden\" name=\"name\" value=\"" + parmWL.name + "\">"); // out.println("<input type=\"hidden\" name=\"day\" value=\"" + day_name + "\">"); out.println("<input type=\"hidden\" name=\"index\" value=\"" + sindex + "\">"); out.println("<input type=\"hidden\" name=\"course\" value=\"" + parmWL.course + "\">"); out.println("<input type=\"hidden\" name=\"returnCourse\" value=\"" + returnCourse + "\">"); out.println("<input type=\"hidden\" name=\"jump\" value=\"" + jump + "\">"); ; out.println( "<input type=\"hidden\" name=\"start_time\" value=\"" + parmWL.start_time + "\">"); out.println("<input type=\"hidden\" name=\"end_time\" value=\"" + parmWL.end_time + "\">"); out.println("<input type=\"hidden\" name=\"day_name\" value=\"" + day_name + "\">"); // out.println("<input type=submit value=\"View Sign-ups\" name=\"view\">"); out.println("</form>"); } // end json check } // end doPost
// ***************************************************** // Process the initial request from Proshop_main // ***************************************************** // @SuppressWarnings("deprecation") public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // // Prevent caching so sessions are not mangled // resp.setHeader("Pragma", "no-cache"); // for HTTP 1.0 resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); // for HTTP 1.1 resp.setDateHeader("Expires", 0); // prevents caching at the proxy server resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); HttpSession session = SystemUtils.verifyPro(req, out); // check for intruder if (session == null) { return; } String club = (String) session.getAttribute("club"); // get club name String templott = (String) session.getAttribute("lottery"); // get lottery support indicator int lottery = Integer.parseInt(templott); // // Call is to display the new features page. // // Display a page to provide a link to the new feature page // out.println("<html><head>"); out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">"); out.println("<meta http-equiv=\"Content-Language\" content=\"en-us\">"); out.println("<title> \"ForeTees Proshop Announcement Page\"</title>"); // out.println("<link rel=\"stylesheet\" href=\"/" +rev+ "/web utilities/foretees.css\" // type=\"text/css\"></link>"); out.println( "<script language=\"JavaScript\" src=\"/" + rev + "/web utilities/foretees.js\"></script>"); out.println("</head>"); out.println("<body bgcolor=\"#FFFFFF\" text=\"#000000\">"); SystemUtils.getProshopSubMenu(req, out, lottery); File f; FileReader fr; BufferedReader br; String tmp = ""; String path = ""; try { path = req.getRealPath(""); tmp = "/proshop_features.htm"; // "/" +rev+ f = new File(path + tmp); fr = new FileReader(f); br = new BufferedReader(fr); if (!f.isFile()) { // do nothing } } catch (FileNotFoundException e) { out.println("<br><br><p align=center>Missing New Features Page.</p>"); out.println("</BODY></HTML>"); out.close(); return; } catch (SecurityException se) { out.println("<br><br><p align=center>Access Denied.</p>"); out.println("</BODY></HTML>"); out.close(); return; } while ((tmp = br.readLine()) != null) out.println(tmp); br.close(); out.println("</BODY></HTML>"); out.close(); } // end of doGet
/** Assums no security manager exists. */ public void testGetJavaIoTmpDir() { File dir = SystemUtils.getJavaIoTmpDir(); Assert.assertNotNull(dir); Assert.assertTrue(dir.exists()); }
// ***************************************************** // Process the initial request from Proshop_main // ***************************************************** // public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // // Prevent caching so sessions are not mangled // resp.setHeader("Pragma", "no-cache"); // for HTTP 1.0 resp.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); // for HTTP 1.1 resp.setDateHeader("Expires", 0); // prevents caching at the proxy server resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); HttpSession session = SystemUtils.verifyHotel(req, out); // check for intruder if (session == null) { return; } String club = (String) session.getAttribute("club"); // get club name String user = (String) session.getAttribute("user"); if (req.getParameter("clubswitch") != null && req.getParameter("clubswitch").equals("1") && req.getParameter("club") != null) { // // Request is to switch clubs - switch the db (TPC or Demo sites) // String newClub = req.getParameter("club"); Connection con = null; // // release the old connection // ConnHolder holder = (ConnHolder) session.getAttribute("connect"); if (holder != null) { con = holder.getConn(); // get the connection for previous club } if (con != null) { /* // abandon any unfinished transactions try { con.rollback(); } catch (Exception ignore) {} */ // close/release the connection try { con.close(); } catch (Exception ignore) { } } // // Connect to the new club // try { con = dbConn.Connect(newClub); // get connection to this club's db } catch (Exception ignore) { } holder = new ConnHolder(con); session.setAttribute("club", newClub); session.setAttribute("connect", holder); out.println("<HTML><HEAD><Title>Switching Sites</Title>"); out.println("<meta http-equiv=\"Refresh\" content=\"0; url=/" + rev + "/hotel_home.htm\">"); out.println("</HEAD>"); out.println("<BODY><CENTER><BR>"); out.println("<BR><H2>Switching Sites</H2><BR>"); out.println("<a href=\"/" + rev + "/hotel_home.htm\" target=_top>Continue</a><br>"); out.println("</CENTER></BODY></HTML>"); out.close(); return; } // // Call is to display the Home page. // out.println("<html><head>"); out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">"); out.println("<meta http-equiv=\"Content-Language\" content=\"en-us\">"); out.println("<title> \"ForeTees Hotel Home Page\"</title>"); out.println( "<script language=\"JavaScript\" src=\"/" + rev + "/web utilities/foretees.js\"></script>"); out.println( "<style type=\"text/css\"> body {text-align: center} </style>"); // so body will align on // center out.println("</head>"); out.println("<body bgcolor=\"#CCCCAA\" text=\"#000000\">"); out.println("<div style=\"align:center; margin:0px auto;\">"); if (club.startsWith("tpc") && user.startsWith("passport")) { // if TPC Passport user out.println("<br><H3>Welcome to ForeTees</H3><br>"); String clubname = ""; String fullname = ""; Connection con = null; try { con = dbConn.Connect(rev); // get connection to the Vx db // // Get the club names for each TPC club // PreparedStatement pstmt = con.prepareStatement("SELECT fullname FROM clubs WHERE clubname=?"); pstmt.clearParameters(); pstmt.setString(1, club); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { fullname = rs.getString("fullname"); // get the club's full name } out.println("<p>You are currently connected to: <b>" + fullname + "</b><br><br>"); out.println("To continue with this site, simply use the navigation menus above.<br><br>"); out.println("To switch sites, click on the desired club name below.</p><br>"); // // Get the club names for each TPC club // pstmt = con.prepareStatement( "SELECT clubname, fullname FROM clubs WHERE inactive=0 AND clubname LIKE 'tpc%' ORDER BY fullname"); pstmt.clearParameters(); rs = pstmt.executeQuery(); while (rs.next()) { clubname = rs.getString("clubname"); // get a club name if (clubname.startsWith("tpc")) { fullname = rs.getString("fullname"); // get the club's full name out.println( "<a href=\"Hotel_home?clubswitch=1&club=" + clubname + "\" target=_top>" + fullname + "</a><br>"); } } pstmt.close(); } catch (Exception e) { // Error connecting to db.... out.println( "<BR><BR>Sorry, we encountered an error while trying to connect to the database."); // out.println("<br><br>Error: " + e.toString() + "<br>"); out.println("<BR><BR> <A HREF=\"Hotel_home\">Return</A>."); out.println("</BODY></HTML>"); return; } } else { out.println( "<BR><BR> You have entered here by mistake. Please contact ForeTees Support at 651-765-6006."); out.println("</BODY></HTML>"); } out.println("</div></BODY></HTML>"); } // end of doGet
public void setUp() { mockSysUtils = new MockSystemUtils(); mockSysUtils.setCurrentTimeMinutes(CREATION_TIME_MINUTES); mockSysUtils.setCurrentTimeMillis(CREATION_TIME_MINUTES * 60 * 1000); SystemUtils.set(mockSysUtils); }
/** Assums no security manager exists. */ public void testGetUserHome() { File dir = SystemUtils.getUserHome(); Assert.assertNotNull(dir); Assert.assertTrue(dir.exists()); }
// ----------------------------------------------------------------------- public void testJavaVersion() { assertEquals(SystemUtils.JAVA_VERSION_FLOAT, SystemUtils.getJavaVersion(), 0f); }
@Override public String getSDataBasePath() { // TODO Auto-generated method stub return new ZJXHFileStruct().getDBFileAbsolutePath(SystemUtils.ExtendSDpath()); }