dk.netarkivet.archive.webinterface
Class BitpreserveFileState

java.lang.Object
  extended by dk.netarkivet.archive.webinterface.BitpreserveFileState

public class BitpreserveFileState
extends java.lang.Object

Class encapsulating methods for handling web requests for ActiveBitPreservation.


Constructor Summary
BitpreserveFileState()
           
 
Method Summary
static java.lang.String makeCheckbox(java.lang.String command, java.lang.String... args)
          Create a generic checkbox as used by processMissingRequest.
static java.lang.String presentChecksum(java.util.List<java.lang.String> csum, java.util.Locale locale)
          Present a list of checksums in a human-readable form.
static void printChecksumErrorStateForLocation(javax.servlet.jsp.JspWriter out, Location location, java.util.Locale locale)
          Print HTML formatted state for checksum errors on a given location in a given locale.
static void printFileName(javax.servlet.jsp.JspWriter out, java.lang.String filename, int rowCount, java.util.Locale locale)
          Print a table row with a file name and a checkbox to request more info.
static void printFileState(javax.servlet.jsp.JspWriter out, FilePreservationState fs, java.util.Locale locale)
          Print a file state table for a file.
static void printMissingFileStateForLocation(javax.servlet.jsp.JspWriter out, Location location, java.util.Locale locale)
          Print HTML formatted state for missing files on a given location in a given locale.
static void printToggleCheckboxes(javax.servlet.jsp.JspWriter out, java.util.Locale locale, int numberOfMissingCheckboxes, int numberOfUploadableCheckboxes)
          Print checkboxes for changing state for files.
static FilePreservationState processChecksumRequest(java.lang.StringBuilder res, javax.servlet.jsp.PageContext context)
          Processes a checksum request.
static java.util.Map<java.lang.String,FilePreservationState> processMissingRequest(javax.servlet.jsp.PageContext context, java.lang.StringBuilder res)
          Processes a missingFiles request.
static void processUpdateRequest(javax.servlet.jsp.PageContext context)
          Extract the name of the bitarchive (parameter Constants.BITARCHIVE_NAME_PARAM) and whether to update missing files (parameter Constants.FIND_MISSING_FILES_PARAM) or checksums (parameter Constants.CHECKSUM_PARAM).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BitpreserveFileState

public BitpreserveFileState()
Method Detail

processUpdateRequest

public static void processUpdateRequest(javax.servlet.jsp.PageContext context)
Extract the name of the bitarchive (parameter Constants.BITARCHIVE_NAME_PARAM) and whether to update missing files (parameter Constants.FIND_MISSING_FILES_PARAM) or checksums (parameter Constants.CHECKSUM_PARAM). Does nothing if parameter 'bitarchive' is not set.

Parameters:
context - the current JSP context
Throws:
ForwardedToErrorPage - if an unknown bitarchive is posted.

processMissingRequest

public static java.util.Map<java.lang.String,FilePreservationState> processMissingRequest(javax.servlet.jsp.PageContext context,
                                                                                          java.lang.StringBuilder res)
Processes a missingFiles request. Parameters of the form Constants.ADD_COMMAND=## causes the file to be added to that bitarchive, if it is missing. Parameters of the form Constants.GET_INFO_COMMAND= causes checksums to be computed for the file in all bitarchives and the information to be shown in the next update (notice that this information disappears when the page is next reloaded).

Parameters:
context - the current JSP context.
res - the result object. This is updated with result information, and expected to be printed to the resulting page.
Returns:
A map of info gathered for files as requested.
Throws:
ForwardedToErrorPage - if the commands have the wrong number of arguments.

processChecksumRequest

public static FilePreservationState processChecksumRequest(java.lang.StringBuilder res,
                                                           javax.servlet.jsp.PageContext context)
Processes a checksum request. The name of a bitarchive must always be given in parameter Constants.BITARCHIVE_NAME_PARAM. If parameter Constants.FILENAME_PARAM is given, file info for that file will be returned, and all actions will work on that file. If parameter Constants.FIX_ADMIN_CHECKSUM_PARAM is given, the admin data checksum will be fixed for the file. If parameter Constants.CREDENTIALS and Constants.CHECKSUM_PARAM is given, removes and reuploads a file with that checksum in the given bitarchive, using the credentials for authorisation.

Parameters:
res - the result object. This is updated with result information, and expected to be printed to the resulting page.
context - the current JSP pagecontext.
Returns:
The file preservation state for a file, if a filename is given in the request. Null otherwise.

makeCheckbox

public static java.lang.String makeCheckbox(java.lang.String command,
                                            java.lang.String... args)
Create a generic checkbox as used by processMissingRequest.

Parameters:
command - The name of the command
args - Arguments to the command
Returns:
A checkbox with the command and arguments in correct format and with HTML stuff escaped.

printMissingFileStateForLocation

public static void printMissingFileStateForLocation(javax.servlet.jsp.JspWriter out,
                                                    Location location,
                                                    java.util.Locale locale)
                                             throws java.io.IOException
Print HTML formatted state for missing files on a given location in a given locale.

Parameters:
out - The writer to write state to.
location - The location to write state for.
locale - The locale to write state in.
Throws:
java.io.IOException - On IO trouble writing state to the writer.

printChecksumErrorStateForLocation

public static void printChecksumErrorStateForLocation(javax.servlet.jsp.JspWriter out,
                                                      Location location,
                                                      java.util.Locale locale)
                                               throws java.io.IOException
Print HTML formatted state for checksum errors on a given location in a given locale.

Parameters:
out - The writer to write state to.
location - The location to write state for.
locale - The locale to write state in.
Throws:
java.io.IOException - On IO trouble writing state to the writer.

printFileName

public static void printFileName(javax.servlet.jsp.JspWriter out,
                                 java.lang.String filename,
                                 int rowCount,
                                 java.util.Locale locale)
                          throws java.io.IOException
Print a table row with a file name and a checkbox to request more info.

Parameters:
out - The stream to print to.
filename - The name of the file.
rowCount - The rowcount, used for styling rows.
locale - The current locale for labels.
Throws:
java.io.IOException - On trouble writing to stream.

printFileState

public static void printFileState(javax.servlet.jsp.JspWriter out,
                                  FilePreservationState fs,
                                  java.util.Locale locale)
                           throws java.io.IOException
Print a file state table for a file. This will present the state of the file in admin data and all bitarchives.

Parameters:
out - The stream to print to.
fs - The file state for the file.
locale - The locale to print labels in.
Throws:
java.io.IOException - On trouble printing to a stream.

printToggleCheckboxes

public static void printToggleCheckboxes(javax.servlet.jsp.JspWriter out,
                                         java.util.Locale locale,
                                         int numberOfMissingCheckboxes,
                                         int numberOfUploadableCheckboxes)
                                  throws java.io.IOException
Print checkboxes for changing state for files. This will print two checkboxes for changing a number of checkboxes, one for getting more info, one for reestablishing missing files. This method assumes the file toggleCheckboxes.js to be available in the directory with the page this method is called from.

Parameters:
out - The stream to print the checkboxes to.
locale - The locale of the labels.
numberOfMissingCheckboxes - The total possible number of missing checkboxes.
numberOfUploadableCheckboxes - The total possible number of reestablish checkboxes.
Throws:
java.io.IOException - On trouble printing the checkboxes.

presentChecksum

public static java.lang.String presentChecksum(java.util.List<java.lang.String> csum,
                                               java.util.Locale locale)
Present a list of checksums in a human-readable form. If size of list is 0, it returns "No checksum". If size of list is 1, it returns the one available checksum. Otherwise, it returns toString of the list.

Parameters:
csum - List of checksum strings
locale - The given locale.
Returns:
String presenting the checksums.