@Override public String call() { return RandomUtil.createRandomId(size); } };
public static File getGroovyScriptFile(File storageDir, String pageId) { return RandomUtil.getCodeFile(storageDir, GROOVY_FILE_NAME_PATTERN, pageId); }
/** * Computes the name of the file used to store this page's content. The default implementation * returns "text.html". * @see com.manydesigns.portofino.pageactions.text.TextAction#locateTextFile() * @return the name of the file. */ protected String computeTextFileName() { return RandomUtil.getCodeFileName(TEXT_FILE_NAME_PATTERN, "text"); }
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"); }
@DefaultHandler public Resolution execute() { if(chartConfiguration == null) { return forwardToPageActionNotConfigured(); } try { // Run/generate the chart try { Thread.currentThread().setContextClassLoader(Class.class.getClassLoader()); generateChart(); } finally { Thread.currentThread().setContextClassLoader(JFreeChartAction.class.getClassLoader()); } chartId = RandomUtil.createRandomId(); String actionurl = context.getActionPath(); UrlBuilder chartResolution = new UrlBuilder(context.getLocale(), actionurl, false) .addParameter("chartId", chartId) .addParameter("chart", ""); String url = context.getRequest().getContextPath() + chartResolution.toString(); file = RandomUtil.getTempCodeFile(CHART_FILENAME_FORMAT, chartId); jfreeChartInstance = new JFreeChartInstance(chart, file, chartId, "Chart: " + chartConfiguration.getName(), width, height, url); } catch (Exception e) { logger.error("Chart exception", e); return forwardToPageActionError(e); } return new ForwardResolution("/m/chart/jfreechart/display.jsp"); }
public Resolution chart() throws FileNotFoundException { final File file = RandomUtil.getTempCodeFile(CHART_FILENAME_FORMAT, chartId); if(!file.exists()) { return new ErrorResolution(404); } final InputStream inputStream = new FileInputStream(file); //Cache the file, expire after 12h int expiresAfter = 12 * 60 * 60 * 1000; long now = System.currentTimeMillis(); HttpServletResponse response = context.getResponse(); response.setHeader("Cache-Control", "max-age=" + expiresAfter); response.setDateHeader("Last-Modified", now); response.setDateHeader("Expires", now + expiresAfter); response.setHeader("Pragma", ""); return new StreamingResolution("image/png", inputStream) { @Override protected void stream(HttpServletResponse response) throws Exception { super.stream(response); if(!file.delete()) { logger.warn("Could not delete temporary file for chart: " + file.getAbsolutePath()); } } }; }
@Override public String generateNewCode() { return RandomUtil.createRandomId(25); }
protected File getMetaFile(String code) { return RandomUtil.getCodeFile(blobsDir, metaFileNamePattern, code); }
public static File getCodeFile(File dir, String fileNameFormat, String code) { return new File(dir, getCodeFileName(fileNameFormat, code)); }
@Override public String call() { return RandomUtil.createRandomId(size); } };
public static File getTempCodeFile(String fileNameFormat, String randomCode) { return getCodeFile(tempDir, fileNameFormat, randomCode); }
public static File getCodeFile(File dir, String fileNameFormat, String code) { return new File(dir, getCodeFileName(fileNameFormat, code)); }
@Override public String generateNewCode() { return RandomUtil.createRandomId(25); }
protected File getEmailAttachmentsDirectory(String emailId) { return RandomUtil.getCodeFile(queuedDirectory, "email-{0}-attachments", emailId); }
public static String createRandomId() { return createRandomId(RANDOM_CODE_LENGTH); }
public static File getTempCodeFile(String fileNameFormat, String randomCode) { return getCodeFile(tempDir, fileNameFormat, randomCode); }
public static String createRandomId() { return createRandomId(RANDOM_CODE_LENGTH); }
protected File getDataFile(String code) { return RandomUtil.getCodeFile(blobsDir, dataFileNamePattern, code); }
protected List<Object[]> loadChartData() { try { chartId = RandomUtil.createRandomId(); String query = chartConfiguration.getQuery(); Session session = persistence.getSession(chartConfiguration.getDatabase()); return QueryUtils.runSql(session, query); } catch(Exception e) { logger.error("Error executing query", e); return null; } }
protected File getDataFile(String code) { return RandomUtil.getCodeFile(blobsDir, dataFileNamePattern, code); }