<%-- #FILE: updated.jsp - Version 1.0 # # This jsp script will automatically determine and print an #"updated" image and/or the date a specified file was last "updated". # #INSTALLATION: # There are many ways this script can be installed and used. The procedure #is what I recommend for jsp beginners. If you're more advanced and know #what you're doing, by all means feel free to install this script however #you wish. # # 1) Save the JSP code in a separate file entitled "updated.jsp" #in your root web directory # # 2) In your JSP files where you will have the "updated" information #displayed, be sure to "include" the "updated.jsp" file. # EXAMPLE: <%@ include file="updated.jsp" %> # # 3) If the file you have the "include" statement in does not #import the java util or java.io packages, you will need to import these # similar to the following: # <%@ page import="java.io.*,java.util.*;" %> # # 4) Set the value for UPDATED_IMAGE_URL to be the URL to the #"updated" image you wish to have displayed. # # 5) Call the method "PrintUpdatedInfo" with the appropriate #parameters as described below wherever you wish to have the "updated" #notification displayed. # # PrintUpdatedInfo (files,days,mode,out) # # EXAMPLES: # PrintUpdatedInfo ("F:/Inetpub/wwwroot/test.jsp",3,2,out) # PrintUpdatedInfo ("F:/Inetpub/wwwroot/test.jsp|F:/Inetpub/wwwroot/default.asp",7,0,out) # #RUNNING: # The function "PrintUpdatedInfo" requires 4 parameters: # PrintUpdatedInfo (files,days,mode,out) # described below: # # 1) files # the actual file or files to test for their last modification date. This parameter #should be the FULL OPERATING SYSTEM PATH, AND NOT A URL!!! The file(s) to test can #be ANY file. # To test multiple files, separate each file with a pipe "|" character. This is especially #useful for HTML "frame" pages. That is, suppose you have a table of contents page and the main #information page, and you want "updated" printed whenever either one of those two pages is updated. # EXAMPLES: # F:/Inetpub/wwwroot/scripts/some_file.jsp # F:/Inetpub/wwwroot/images/myself.jpg|F:/Inetpub/wwwroot/index.html # F:/Inetpub/wwwroot/default.jsp # # 2) days # the number of days previous to today's date files should have been updated # to have the "updated" info displayed. Specifying "-1" means no limit and the # "updated" info will always be printed. # EXAMPLES: # i) If "today" is the 27th, the file "test.html" was updated on the 21st, and days #is specified to be 4, the "updated" would NOT be displayed because test.html was not #updated within the last 4 days. # ii) If "today" is the 27th, the file "test.html" was updated on the 21st, and days #is specified to be 7, the "updated" WOULD be displayed because test.html was #updated within the last 7 days. # iii) If "today" is the 27th, the file "test.html" was updated on the 21st, and days #is specified to be -1, the "updated" WOULD always be displayed. # # 3) mode # Can only be one of three integer values: # 0 : Print both the "updated" image and the textual date # 1 : Print the "updated" image only # 2 : Print the textual date only of the file's last update # #EXAMPLE USES (last two show testing of multiple files) : #PrintUpdatedInfo("F:/Inetpub/wwwroot/scripts/updated/updated.jsp",3,1,out) #PrintUpdatedInfo("/usr/local/public_html/menu.html",-1,1,out) #PrintUpdatedInfo("F:/Inetpub/wwwroot/default.asp|F:/Inetpub/wwwroot/info/index.html|F:/Inetpub/wwwroot/whatever.html",5,0,out) #PrintUpdatedInfo("/var/usr/public_html/images/logo.gif|/var/usr/public_html/images/me.jpg",8,2,out) # # 4) out # The JSP "out" object. # #LICENSE: # Finally, this "basic" code is free, and comes with absolutely NO #warranties, either expressed or implied. Feel free to do what you want #with it. Feel free to build upon it. If you did not get this code #from http://www.davelozinski.com, you don't have the original. # #REVISION HISTORY: # 05/29/04 1.0 Original Version # #CONTACT INFORMATION: # http://www.davelozinski.com/cgi-bin/email_lozinski.pl ############################################################## --%> <%! public void PrintUpdatedInfo (String files,int days,int mode, javax.servlet.jsp.JspWriter out) throws java.io.IOException { //#the URL to the "updated" image you wish to have displayed. final String UPDATED_IMAGE_URL = "/gfx/updated.gif"; //##################################################################### //######## NOTHING FROM HERE DOWN SHOULD NEED TO BE CONFIGURED ######## //##################################################################### boolean error = false; int x = 0; StringTokenizer fileList = new StringTokenizer(files,"|"); int UpperBound = fileList.countTokens(); String[] file_arr = new String[UpperBound]; while (fileList.hasMoreTokens()) { file_arr[x] = fileList.nextToken(); x += 1; } for (x=0; xERROR! File \"" + file_arr[x] + "\" does not exist!
\n"); error = true; } } if (days < -1) { out.println ("ERROR! The 2nd parameter must be a whole number greater than or equal to -1!
\n"); error = true; } if (mode < 0 || mode > 2) { out.println ("ERROR! The 3rd parameter can only be 0, 1, or 2!
\n"); error = true; } if (!error) { for (x=0; x"); } if (mode == 0 || mode == 2) { //#Print the "updated" date out.println (updated_date); } break; //#At least one of the files has been updated. No reason to check the rest. } } //#for-loop } //#!error } //#PrintUpdatedInfo //############################################################## %>