/** * 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()); }
protected void updatePagePermissions(PageInstance page) throws Exception { Permissions pagePermissions = page.getPage().getPermissions(); pagePermissions.getGroups().clear(); Map<String, Group> groups = new HashMap<String, Group>(); for(Map.Entry<String, String> entry : accessLevels.entrySet()) { Group group = new Group(); group.setName(entry.getKey()); group.setAccessLevel(entry.getValue()); groups.put(group.getName(), group); } for(Map.Entry<String, List<String>> custPerm : permissions.entrySet()) { String groupId = custPerm.getKey(); Group group = groups.get(groupId); if(group == null) { group = new Group(); group.setName(groupId); groups.put(groupId, group); } group.getPermissions().addAll(custPerm.getValue()); } for(Group group : groups.values()) { pagePermissions.getGroups().add(group); } DispatcherLogic.savePage(page); }
/** * Recursively applies a template to a subtree of pages. * @param directory the starting page directory (root of the subtree). * @param filter the filter for selecting pages. * @param edit the object holding template configuration. */ protected void updateTemplate(File directory, FileFilter filter, EditPage edit) { File[] children = directory.listFiles(filter); for(File child : children) { if(!child.getName().equals(PageInstance.DETAIL)) { try { Page page = DispatcherLogic.getPage(child); page.getLayout().setTemplate(edit.template); page.getDetailLayout().setTemplate(edit.detailTemplate); DispatcherLogic.savePage(child, page); } catch (Exception e) { logger.warn("Could not set template of " + child.getAbsolutePath(), e); } } updateTemplate(child, filter, edit); } }
public Resolution updateLayout() { if (!checkPermissionsOnTargetPage(getPageInstance())) { return new ForbiddenAccessResolution("You are not authorized to edit the layout of this page."); } HttpServletRequest request = context.getRequest(); Enumeration parameters = request.getParameterNames(); while(parameters.hasMoreElements()) { String parameter = (String) parameters.nextElement(); if(parameter.startsWith("embeddedPageAction_")) { String layoutContainer = parameter.substring("embeddedPageAction_".length()); String[] embeddedPageActionIds = request.getParameterValues(parameter); updateLayout(layoutContainer, embeddedPageActionIds); } } try { DispatcherLogic.savePage(getPageInstance()); } catch (Exception e) { logger.error("Error updating layout", e); SessionMessages.addErrorMessage(ElementsThreadLocals.getText("layout.update.failed")); } return new RedirectResolution(originalPath); }
page.setDescription(calendarTitle); DispatcherLogic.savePage(dir, page); File actionFile = new File(dir, "action.groovy"); try {
DispatcherLogic.savePage(dir, page); File actionFile = new File(dir, "action.groovy"); FileWriter fileWriter = new FileWriter(actionFile);
permissions.getGroups().add(group); page.setPermissions(permissions); DispatcherLogic.savePage(dir, page);
layout.getChildPages().addAll(sortedChildren); try { DispatcherLogic.savePage(getPageInstance()); } catch (Exception e) { logger.error("Couldn't save page", e);
if(pageName.equals(it.next().getName())) { it.remove(); DispatcherLogic.savePage(parentPageInstance.getDirectory(), parentPageInstance.getPage()); break;
page.getDetailLayout().setTemplate(edit.detailTemplate); try { File pageFile = DispatcherLogic.savePage(pageInstance.getDirectory(), page); logger.info("Page saved to " + pageFile.getAbsolutePath()); } catch (Exception e) {
DispatcherLogic.savePage(oldParent.getDirectory(), oldParent.getPage()); logger.debug("Moving directory"); FileUtils.moveDirectory(pageInstance.getDirectory(), newDirectory); String pageId = RandomUtil.createRandomId(); newPage.setId(pageId); DispatcherLogic.savePage(newDirectory, newPage); DispatcherLogic.savePage(newParent.getDirectory(), newParent.getPage()); } catch (Exception e) { logger.error("Couldn't copy/move page", e);
@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(); }
DispatcherLogic.savePage(pagesDir, rootPage); } catch (Exception e) { logger.error("Error while creating pages", e);
page.getDetailLayout().setTemplate(parentPage.getDetailLayout().getTemplate()); logger.debug("Creating the new child page in directory: {}", directory); DispatcherLogic.savePage(directory, page); if(configuration != null) { DispatcherLogic.saveConfiguration(directory, configuration); DispatcherLogic.savePage(parentDirectory, parentPage); } catch (Exception e) { logger.error("Exception saving page configuration");