public Resolution preparePage() { if(!pageInstance.getParameters().isEmpty()) { return new ErrorResolution(404); } chartConfiguration = (JFreeChartConfiguration) pageInstance.getConfiguration(); return null; }
/** * Reconstructs the URL path to this PageInstance from the root of the application (not including the * webapp's context path). */ public String getPath() { if(getParent() == null) { return ""; } else { return getParent().getPath() + "/" + getUrlFragment(); } }
public static void configurePageAction(PageAction pageAction, PageInstance pageInstance) throws JAXBException, IOException { if(pageInstance.getConfiguration() != null) { logger.debug("Page instance {} is already configured"); return; } File configurationFile = new File(pageInstance.getDirectory(), "configuration.xml"); Class<?> configurationClass = PageActionLogic.getConfigurationClass(pageAction.getClass()); try { Object configuration = getConfiguration(configurationFile, configurationClass); pageInstance.setConfiguration(configuration); } catch (Throwable t) { logger.error("Couldn't load configuration from " + configurationFile.getAbsolutePath(), t); } pageAction.setPageInstance(pageInstance); }
@Deprecated public static PageAction ensureActionBean(PageInstance page) throws IllegalAccessException, InstantiationException { PageAction action = page.getActionBean(); assert action != null; if(action == null) { action = page.getActionClass().newInstance(); page.setActionBean(action); } return action; }
public Resolution preparePage() { if(pageInstance.getConfiguration() == null) { pageInstance.setConfiguration(new CalendarConfiguration()); } return null; }
String prefix = ""; if(rootPageIndex > 0) { prefix += rootPageInstance.getParent().getPath() + "/" + rootPageInstance.getName(); Page rootPage = rootPageInstance.getPage(); boolean rootGhost = rootPage.getActualNavigationRoot() == NavigationRoot.GHOST_ROOT; rootNavigationItem = new NavigationItem( rootPageInstance.getTitle(), rootPageInstance.getDescription(), prefix, null, true, rootSelected, rootGhost); LinkedList<Page> pages = new LinkedList<Page>(); PageInstance[] allInstances = dispatch.getPageInstancePath(); for(int i = 0; i <= rootPageIndex; i++) { pages.add(allInstances[i].getPage()); Layout layout = current.getLayout(); if (layout != null) { childPages = layout.getChildPages(); currentNavigationItem.getChildNavigationItems(); prefix = currentNavigationItem.getPath() + "/"; for(String param : current.getParameters()) { prefix += param + "/"; File pageDir = current.getChildPageDirectory(childPage.getName()); Page page; try { List<String> parameters = null; if (next != null) {
PageInstance oldParent = pageInstance.getParent(); if(oldParent == null) { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("you.cant.copy.or.move.the.root.page")); Dispatch landingPageDispatch = dispatcher.getDispatch(landingPagePath); if(landingPageDispatch != null && landingPageDispatch.getLastPageInstance().getDirectory().equals(pageInstance.getDirectory())) { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("you.cant.move.the.landing.page")); return new RedirectResolution(originalPath); File dir = pagesDir; try { newParent = new PageInstance(null, dir, DispatcherLogic.getPage(dir), null); } catch (Exception e) { throw new Error("Couldn't load root page", e); if(newParent.getDirectory().equals(oldParent.getDirectory())) { List<String> params = newParent.getParameters(); newParent = new PageInstance(newParent.getParent(), newParent.getDirectory(), oldParent.getPage(), null); newParent.getParameters().addAll(params); newName = StringUtils.isEmpty(newName) ? pageInstance.getName() : newName; File newDirectory = newParent.getChildPageDirectory(newName); File newParentDirectory = newDirectory.getParentFile(); logger.debug("Ensuring that new parent directory {} exists", newParentDirectory); if(!newDirectory.exists()) { try { Iterator<ChildPage> it = oldParent.getLayout().getChildPages().iterator();
int start = dispatch.getClosestSubtreeRootIndex(); PageInstance pageInstance = dispatch.getPageInstance(start); PageInstance parentPageInstance = pageInstance.getParent(); if(parentPageInstance == null) { start++; } else { sb.append(parentPageInstance.getPath()); Page page = current.getPage(); sb.append(current.getName()); BreadcrumbItem item = new BreadcrumbItem( sb.toString(), current.getPage().getTitle(), current.getPage().getDescription()); if(page.getActualNavigationRoot() != NavigationRoot.GHOST_ROOT) { items.add(item); if(!current.getParameters().isEmpty()) { for(String param : current.getParameters()) { sb.append("/").append(param); String title = current.getTitle(); String description = current.getDescription(); BreadcrumbItem item2 = new BreadcrumbItem(sb.toString(), title, description); items.add(item2);
public Resolution deletePage() { PageInstance pageInstance = getPageInstance(); PageInstance parentPageInstance = pageInstance.getParent(); if(parentPageInstance == null) { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("you.cant.delete.the.root.page")); Dispatch landingPageDispatch = dispatcher.getDispatch(landingPagePath); if(landingPageDispatch != null && landingPageDispatch.getLastPageInstance().getDirectory().equals(pageInstance.getDirectory())) { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("you.cant.delete.the.landing.page")); return new RedirectResolution(originalPath); String pageName = pageInstance.getName(); File childPageDirectory = parentPageInstance.getChildPageDirectory(pageName); Layout parentLayout = parentPageInstance.getLayout(); Iterator<ChildPage> it = parentLayout.getChildPages().iterator(); while(it.hasNext()) { if(pageName.equals(it.next().getName())) { it.remove(); DispatcherLogic.savePage(parentPageInstance.getDirectory(), parentPageInstance.getPage()); break; logger.error("Error deleting page", e); return new RedirectResolution(StringUtils.defaultIfEmpty(parentPageInstance.getPath(), "/"));
parentLayout = parentPage.getLayout(); configurePath = ""; parentPageInstance = new PageInstance(null, parentDirectory, parentPage, null); break; case CHILD: parentPageInstance = getPageInstance(); parentPage = parentPageInstance.getPage(); parentLayout = parentPageInstance.getLayout(); parentDirectory = parentPageInstance.getDirectory(); directory = parentPageInstance.getChildPageDirectory(fragment); configurePath = originalPath; break; case SIBLING: parentPageInstance = dispatch.getPageInstance(-2); parentPage = parentPageInstance.getPage(); parentLayout = parentPageInstance.getLayout(); parentDirectory = parentPageInstance.getDirectory(); directory = parentPageInstance.getChildPageDirectory(fragment); configurePath = parentPageInstance.getPath(); break; default:
public CalendarConfiguration getConfiguration() { return (CalendarConfiguration) pageInstance.getConfiguration(); } }
@Override protected boolean acceptsPathParameter() { return (classAccessor != null && pageInstance.getParameters().size() < classAccessor.getKeyProperties().length); }
@Override public void setPageInstance(PageInstance pageInstance) { super.setPageInstance(pageInstance); this.crudConfiguration = (CrudConfiguration) pageInstance.getConfiguration(); if (crudConfiguration == null) { logger.warn("Crud is not configured: " + pageInstance.getPath()); return; } ClassAccessor innerAccessor = prepare(pageInstance); if (innerAccessor == null) { return; } classAccessor = new CrudAccessor(crudConfiguration, innerAccessor); pkHelper = new PkHelper(classAccessor); }
/** * Sets the layout that drives the display of the embedded children of this page. * If this page instance has parameters, the detail layout is set; else, the regular layout is set. * @param layout the new layout. */ public void setLayout(Layout layout) { if(getParameters().isEmpty()) { getPage().setLayout(layout); } else { getPage().setDetailLayout(layout); } }
/** * Persists a page to the file system. * @param pageInstance the live PageInstance containing the Page to save. * @return the file where the page was saved. * @throws Exception in case the save fails. */ public static File savePage(PageInstance pageInstance) throws Exception { return savePage(pageInstance.getDirectory(), pageInstance.getPage()); }
@Button(list = "edit-content", key = "update", order = 1, type = Button.TYPE_PRIMARY) @RequiresPermissions(level = AccessLevel.VIEW, permissions = { PERMISSION_EDIT }) public Resolution updateContent() { title = context.getRequest().getParameter("title"); title = StringUtils.trimToNull(title); if (title == null) { SessionMessages.addErrorMessage(ElementsThreadLocals.getText("title.cannot.be.empty")); return new ForwardResolution("/m/pageactions/text/edit-content.jsp"); } description = context.getRequest().getParameter("description"); description = StringUtils.trimToNull(description); Page page = pageInstance.getPage(); page.setTitle(title); page.setDescription(description); try { DispatcherLogic.savePage(pageInstance.getDirectory(), page); saveContent(); SessionMessages.addInfoMessage(ElementsThreadLocals.getText("object.updated.successfully")); } catch (Exception e) { logger.error("Could not save content for page " + pageInstance.getPath(), e); SessionMessages.addInfoMessage(ElementsThreadLocals.getText("update.failed")); } return cancel(); }
public static PageAction getSubpage( Configuration configuration, PageInstance parentPageInstance, String pathFragment) throws PageNotActiveException { File currentDirectory = parentPageInstance.getChildrenDirectory(); File childDirectory = new File(currentDirectory, pathFragment); if(childDirectory.isDirectory() && !PageInstance.DETAIL.equals(childDirectory.getName())) { ChildPage childPage = null; for(ChildPage candidate : parentPageInstance.getLayout().getChildPages()) { if(candidate.getName().equals(childDirectory.getName())) { childPage = candidate; PageAction pageAction = actionClass.newInstance(); PageInstance pageInstance = new PageInstance(parentPageInstance, childDirectory, page, actionClass); pageInstance.setActionBean(pageAction); configurePageAction(pageAction, pageInstance); return pageAction;
List<String> parameters = pageInstance.getParameters(); if(!parameters.isEmpty()) { String encoding = getUrlEncoding(); ognlContext.put(crudConfiguration.getActualVariable(), object); String title = getReadTitle(); pageInstance.setTitle(title); pageInstance.setDescription(title); } else { return notInUseCase(context, parameters); pageInstance.setTitle(title); pageInstance.setDescription(title);
/** * Computes the File object used to store this page's content. The default implementation * looks for a file with a fixed name in this page's directory, computed by calling * {@link TextAction#computeTextFileName()}. * @see TextAction#computeTextFileName() * @return the document File. */ protected File locateTextFile() { return new File(pageInstance.getDirectory(), computeTextFileName()); }
protected String getClosestSafePath(PageInstance newParent, String newName) { String path = newParent.getPath(); int indexOfDetail = path.indexOf(PageInstance.DETAIL); if(indexOfDetail > 0) { return path.substring(0, indexOfDetail); } else { return path + (path.endsWith("/") ? "" : "/") + newName; } }