content = BookLoader.GSON.fromJson(data, ctype); } catch(Exception e) { content = new ContentError(ctype == null ? "Failed to create a page of type \"" + type + "\", perhaps the type is not registered?" : "Failed to create a page of type \"" + type + "\", perhaps the page file \"" + this.data + "\" is missing or invalid?", e); content = BookLoader.getPageType(type).newInstance(); } catch(InstantiationException | IllegalAccessException | NullPointerException e) { content = new ContentError("Failed to create a page of type \"" + type + "\", perhaps the type is not registered?"); content.load(); } catch(Exception e) { content = new ContentError("Failed to load page " + parent.name + "." + name + ".", e); e.printStackTrace();
@Override public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) { addTitle(list, "Error"); TextData[] text = new TextData[1 + (exception != null ? 2 : 0)]; text[0] = new TextData(errorStage); text[0].color = "dark_red"; text[0].underlined = true; if(exception != null) { text[1] = new TextData("The following error has occured: "); text[1].color = "dark_red"; text[1].paragraph = true; text[2] = new TextData(exception.getMessage() != null ? exception.getMessage() : exception.getClass() .getSimpleName()); text[2].color = "dark_red"; text[2].paragraph = true; } list.add(new ElementText(0, TITLE_HEIGHT, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - TITLE_HEIGHT, text)); } }
@Override public void load() { if(name == null) { name = "section" + parent.unnamedSectionCounter++; } name = name.toLowerCase(); if(!data.equals("no-load")) { IResource pagesInfo = source.getResource(source.getResourceLocation(data)); if(pagesInfo != null) { String data = source.resourceToString(pagesInfo); if(!data.isEmpty()) { try { pages = new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(data, PageData[].class))); } catch(Exception e) { pages = new ArrayList<>(); PageData pdError = new PageData(true); pdError.name = "errorrenous"; pdError.content = new ContentError("Failed to load section " + name + ".", e); pages.add(pdError); } } } } for(PageData page : pages) { page.parent = this; page.source = source; page.load(); } icon.location = source.getResourceLocation(icon.file, true); }
PageData page = new PageData(true); page.name = "errorenous"; page.content = new ContentError("Failed to load repository " + repo.toString() + ".", e); error.pages.add(page); sections.add(error); PageData page = new PageData(true); page.name = "errorenous"; page.content = new ContentError("Failed to load the book due to an unexpected error.", e); section.pages.add(page); this.sections.add(section);