- String path = url.getPath();
- if (path.length() == 0) {
- path = "/";
- }
- String[] pathComponents = path.split("/");
- if (pathComponents.length < 2) {
- throw new IllegalArgumentException("URL “" + url + "” is not a valid freenet page.");
- }
- String siteName = pathComponents[1];
- String[] siteComponents = siteName.split("@");
- if (siteComponents.length != 2) {
- throw new IllegalArgumentException("siteName “" + siteName + "” is not a valid freenet page.");
- }
- if (!"USK".equals(siteComponents[0]) && !"SSK".equals(siteComponents[0]) && !"CHK".equals(siteComponents[0])) {
- throw new IllegalArgumentException("siteName “" + siteName + "” is not a valid freenet page.");
- }
- if ("USK".equals(siteComponents[0])) {
- Site site = new Site(siteComponents[1], pathComponents[2]);
- Edition edition = new Edition(site, Integer.parseInt(pathComponents[3]));
- Page page = new Page(edition, createPath(pathComponents, 4));
- addPage(page);
- }
- if ("SSK".equals(siteComponents[0])) {
- int lastDash = pathComponents[2].lastIndexOf('-');
- String basename = pathComponents[2].substring(0, lastDash);
- int editionNumber = Integer.parseInt(pathComponents[2].substring(lastDash + 1));
- Site site = new Site(siteComponents[1], basename);
- Edition edition = new Edition(site, editionNumber);
- Page page = new Page(edition, createPath(pathComponents, 3));
- addPage(page);
- }
- /* TODO: handle CHK */