/** * 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()); }
/** * Returns the path inside the web application of a resource relative to this action's directory. * E.g. getResourcePath("my.jsp") might return /WEB-INF/pages/this/that/my.jsp. * @param resource the path of the resource, relative to this action's directory. * @return the path of the resource, relative to the web application root. */ public String getResourcePath(String resource) { File resourceFile = new File(pageInstance.getDirectory(), resource); File appRoot = new File(serverInfo.getRealPath()); return ElementsFileUtils.getRelativePath(appRoot, resourceFile); }
protected void prepareScript() { String pageId = pageInstance.getPage().getId(); File file = ScriptingUtil.getGroovyScriptFile(pageInstance.getDirectory(), "action"); FileReader fr = null; try { fr = new FileReader(file); script = IOUtils.toString(fr); } catch (Exception e) { logger.warn("Couldn't load script for page " + pageId, e); } finally { IOUtils.closeQuietly(fr); } }
/** * Utility method to save the configuration object to a file in this page's directory. * @param configuration the object to save. It must be in a state that will produce a valid XML document. * @return true if the object was correctly saved, false otherwise. */ protected boolean saveConfiguration(Object configuration) { try { File confFile = DispatcherLogic.saveConfiguration(pageInstance.getDirectory(), configuration); logger.info("Configuration saved to " + confFile.getAbsolutePath()); return true; } catch (Exception e) { logger.error("Couldn't save configuration", e); SessionMessages.addErrorMessage("error saving conf"); return false; } }
/** * 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()); }
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); }
protected void updateScript() { File directory = pageInstance.getDirectory(); File groovyScriptFile = ScriptingUtil.getGroovyScriptFile(directory, "action"); FileWriter fw = null;
protected void setupChildPages() { File directory = getPageInstance().getDirectory(); childPagesForm = setupChildPagesForm(childPages, directory, getPage().getLayout(), ""); if(PageActionLogic.supportsDetail(getPageInstance().getActionClass())) { File detailDirectory = new File(directory, PageInstance.DETAIL); if(!detailDirectory.isDirectory() && !ElementsFileUtils.safeMkdir(detailDirectory)) { logger.error("Could not create detail directory{}", detailDirectory.getAbsolutePath()); SessionMessages.addErrorMessage("Could not create detail directory"); return; } detailChildPagesForm = setupChildPagesForm(detailChildPages, detailDirectory, getPage().getDetailLayout(), "detail"); } }
protected void commonUploadAttachment() throws IOException { logger.debug("Uploading attachment"); viewAttachmentUrl = null; InputStream attachmentStream = upload.getInputStream(); String attachmentId = RandomUtil.createRandomId(); File dataFile = RandomUtil.getCodeFile( pageInstance.getDirectory(), ATTACHMENT_FILE_NAME_PATTERN, attachmentId); // copy the data FileOutputStream fileOutputStream = new FileOutputStream(dataFile); IOUtils.copyLarge(attachmentStream, fileOutputStream); if(textConfiguration == null) { textConfiguration = new TextConfiguration(); } Attachment attachment = TextLogic.createAttachment( textConfiguration, attachmentId, upload.getFileName(), upload.getContentType(), upload.getSize()); attachment.setDownloadable(uploadDownloadable); viewAttachmentUrl = generateViewAttachmentUrl(attachmentId); saveConfiguration(textConfiguration); logger.info("Attachment uploaded: " + upload.getFileName() + " (" + attachmentId + ")"); IOUtils.closeQuietly(attachmentStream); IOUtils.closeQuietly(fileOutputStream); upload.delete(); logger.debug("Upload resources cleaned"); }
protected void buildCopyPageForm() { PageInstance pageInstance = dispatch.getLastPageInstance(); SelectionProvider pagesSelectionProvider = DispatcherLogic.createPagesSelectionProvider (pagesDir, true, true, pageInstance.getDirectory()); copyForm = new FormBuilder(CopyPage.class) .configReflectiveFields() .configSelectionProvider(pagesSelectionProvider, "destinationPagePath") .build(); }
protected void buildMovePageForm() { PageInstance pageInstance = dispatch.getLastPageInstance(); SelectionProvider pagesSelectionProvider = DispatcherLogic.createPagesSelectionProvider (pagesDir, true, true, pageInstance.getDirectory()); moveForm = new FormBuilder(MovePage.class) .configReflectiveFields() .configSelectionProvider(pagesSelectionProvider, "destinationPagePath") .build(); }
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); 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) { updateTemplate(pageInstance.getDirectory(), filter, edit);
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); 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); DispatcherLogic.savePage(oldParent.getDirectory(), oldParent.getPage()); logger.debug("Moving directory"); FileUtils.moveDirectory(pageInstance.getDirectory(), newDirectory); } else { logger.debug("Copying directory"); FileUtils.copyDirectory(pageInstance.getDirectory(), newDirectory); logger.debug("Generating a new Id for the new page"); Page newPage = DispatcherLogic.getPage(newDirectory); DispatcherLogic.savePage(newParent.getDirectory(), newParent.getPage()); } catch (Exception e) { logger.error("Couldn't copy/move page", e);
String attachmentId = attachment.getId(); final File file = RandomUtil.getCodeFile( pageInstance.getDirectory(), ATTACHMENT_FILE_NAME_PATTERN, attachmentId);
pageInstance.getDirectory(), ATTACHMENT_FILE_NAME_PATTERN, attachment.getId()); if(!FileUtils.deleteQuietly(file)) { logger.warn("File wasn't deleted: {}", file.getAbsolutePath());
@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(); }
parentPage = parentPageInstance.getPage(); parentLayout = parentPageInstance.getLayout(); parentDirectory = parentPageInstance.getDirectory(); directory = parentPageInstance.getChildPageDirectory(fragment); configurePath = originalPath; parentPage = parentPageInstance.getPage(); parentLayout = parentPageInstance.getLayout(); parentDirectory = parentPageInstance.getDirectory(); directory = parentPageInstance.getChildPageDirectory(fragment); configurePath = parentPageInstance.getPath();