public void performPaging(PageFetcher fetcher, PageControl control)
throws PageFetchException
{
PrintStream out;
PageList data;
boolean lineNumberMode;
// Don't know how to handle this case
if (control.getPagesize() == 0) {
return;
}
lineNumberMode = false;
out = getOutStream();
if (isRedirected()) {
control.setPagesize(PageControl.SIZE_UNLIMITED);
}
data = fetcher.getPage((PageControl)control.clone());
printPage(out, data, control.getPageEntityIndex() + 1,
lineNumberMode);
if (control.getPagesize() == PageControl.SIZE_UNLIMITED ||
data.size() < control.getPagesize())
{
return;
}
while (true) {
boolean printPage = false;
String cmd;
int totalPages;
totalPages = getNumPages(control, data);
try {
cmd = getInput("--More-- (Page " +
(control.getPagenum() + 1) + " of " +
totalPages + ")", false);
} catch(IOException exc) {
out.println();
break;
}
if (cmd == null || (cmd = cmd.trim()).length() == 0) {
printPage = true;
control.setPagenum(control.getPagenum() + 1);
}
else if (cmd.equals("q")) {
break;
}
else if (cmd.equals("b")) {
printPage = true;
if (control.getPagenum() > 0) {
control.setPagenum(control.getPagenum() - 1);
}
}
else if (cmd.equals("l")) {
lineNumberMode = !lineNumberMode;
printPage = true;
}
else if (cmd.equals("?")) {
out.println(" 'b' - Scroll back one page");
out.println(" 'l' - Toggle line number mode");
out.println(" 'q' - Quit paging");
out.println(" '<number>' - Jump to the specified page #");
out.println(" '<enter>' - Scroll forward one page");
}
else {
int newPageNo;
try {
newPageNo = Integer.parseInt(cmd);
} catch(NumberFormatException exc) {
out.println("Unknown command '" + cmd + "' " +
" type '?' for paging help");
continue;
}
if (newPageNo < 1 || newPageNo > totalPages) {
out.println(newPageNo + " out of range (must be " +
"1 to " + totalPages + ")");
}
else {
control.setPagenum(newPageNo - 1);
printPage = true;
}
}
if (printPage) {
data = fetcher.getPage((PageControl)control.clone());
printPage(out, data, control.getPageEntityIndex() + 1,
lineNumberMode);
// Check to see if we printed the last of the data
if (data.size() < control.getPagesize()) {
break;
}
}
}
}