forked from I2P_Developers/i2p.i2p
Custom error pages
Some checks failed
Java CI / build (push) Has been cancelled
Java CI / javadoc-latest (push) Has been cancelled
Java CI / build-java7 (push) Has been cancelled
Java with IzPack Snapshot Setup / setup (push) Has been cancelled
Sync Primary Repository to GitHub Mirror / sync (push) Has been cancelled
Some checks failed
Java CI / build (push) Has been cancelled
Java CI / javadoc-latest (push) Has been cancelled
Java CI / build-java7 (push) Has been cancelled
Java with IzPack Snapshot Setup / setup (push) Has been cancelled
Sync Primary Repository to GitHub Mirror / sync (push) Has been cancelled
This commit is contained in:
@ -5,6 +5,7 @@ import java.io.File;
|
||||
import org.eclipse.jetty.ee8.servlet.ErrorPageErrorHandler;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.FileSuffixFilter;
|
||||
|
||||
/**
|
||||
* Customize the error page.
|
||||
@ -14,6 +15,7 @@ import net.i2p.I2PAppContext;
|
||||
public class I2PErrorHandler extends ErrorPageErrorHandler
|
||||
{
|
||||
private final File _docroot;
|
||||
private static final String RESOURCES = ".resources";
|
||||
|
||||
public I2PErrorHandler() {
|
||||
this(new File(I2PAppContext.getGlobalContext().getConfigDir(), "eepsite/docroot"));
|
||||
@ -28,6 +30,38 @@ public class I2PErrorHandler extends ErrorPageErrorHandler
|
||||
_docroot = docroot;
|
||||
setShowServlet(false);
|
||||
setShowStacks(false);
|
||||
setErrorPages();
|
||||
}
|
||||
|
||||
/*
|
||||
* Add error pages for any nnn.html files found.
|
||||
* Also for the special files 000.html (default), 4xx.html, and 5xx.html.
|
||||
*/
|
||||
private void setErrorPages() {
|
||||
File dir = new File(_docroot, RESOURCES);
|
||||
if (!dir.isDirectory())
|
||||
return;
|
||||
File[] files = dir.listFiles(new FileSuffixFilter(".html"));
|
||||
if (files == null)
|
||||
return;
|
||||
for (File file : files) {
|
||||
String name = file.getName();
|
||||
if (name.equals("000.html")) {
|
||||
addErrorPage(GLOBAL_ERROR_PAGE, '/' + RESOURCES + "/000.html");
|
||||
} else if (name.equals("4xx.html")) {
|
||||
addErrorPage(400, 499, '/' + RESOURCES + "/4xx.html");
|
||||
} else if (name.equals("5xx.html")) {
|
||||
addErrorPage(500, 599, '/' + RESOURCES + "/5xx.html");
|
||||
} else if (name.length() == 8 && (name.startsWith("4") || name.startsWith("5"))) {
|
||||
int code;
|
||||
try {
|
||||
code = Integer.parseInt(name.substring(0, 3));
|
||||
} catch (NumberFormatException nfe) {
|
||||
continue;
|
||||
}
|
||||
addErrorPage(code, '/' + RESOURCES + '/' + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Overrides
|
||||
|
Reference in New Issue
Block a user