public static synchronized File getProcessedFile( String resourceName, InputStream resourceInputStream) throws IOException { resourceName = resourceName.replace(".css", "_processed.css"); resourceName = resourceName.substring(resourceName.lastIndexOf("/") + 1); File file = new File( CommonWorkingDirectory.PROCESSED_RESOURCES_DIR.getDirectoryPath(true) + resourceName); if (!file.exists() || ApplicationUtil.getAplosContextListener().isDebugMode()) { String lineSep = System.getProperty("line.separator"); BufferedReader br = null; br = new BufferedReader(new InputStreamReader(resourceInputStream)); String nextLine = ""; StringBuffer sb = new StringBuffer(); try { while ((nextLine = br.readLine()) != null) { sb.append(nextLine); sb.append(lineSep); } } catch (IOException e1) { e1.printStackTrace(); } String cssContent = sb.toString(); String newCssContent = CommonUtil.includeContextRootInPathsForCss(cssContent, JSFUtil.getContextPath()); FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write(newCssContent.getBytes()); fileOutputStream.close(); } return file; }
@Override public InputStream getInputStream() throws IOException { if (minifyTask != null && minifyTask.isDone()) { try { File file = minifyTask.get(); if (file != null && file.exists()) { return new FileInputStream(file); } } catch (ExecutionException eex) { ApplicationUtil.handleError(eex, false); } catch (InterruptedException iex) { ApplicationUtil.handleError(iex, false); } } return new FileInputStream(getProcessedFile(getResourceName(), super.getInputStream())); }
@Override public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String obj) { AutoComplete autoComplete = (AutoComplete) uiComponent; Map<String, Object> viewMap = facesContext.getViewRoot().getViewMap(); @SuppressWarnings("unchecked") List<? extends AplosAbstractBean> aplosAbstractBeanList = (List<? extends AplosAbstractBean>) viewMap.get(autoComplete.getClientId() + "_suggestions"); viewMap.put(autoComplete.getClientId() + "_suggestions", null); Map<String, AjaxBehaviorEvent> customEvents = autoComplete.getCustomEvents(); boolean itemSelected = false; /* * Only process if the object has been selected, otherwise the obj property won't be an index * but the string of the autocomplete. */ for (Iterator<String> customEventIter = customEvents.keySet().iterator(); customEventIter.hasNext(); ) { String customEventKey = customEventIter.next(); if (customEventKey == "itemSelect") { itemSelected = true; } } if (itemSelected) { if (aplosAbstractBeanList != null) { try { if (obj == null) { return null; } else { return aplosAbstractBeanList.get(Integer.parseInt(obj)); } } catch (Exception ex) { // There's an error been sent back saying that the obj is out of bounds of the // array, this should give more information if this happens again 8 Nov 2010 StringBuffer strBuf = new StringBuffer(); if (obj != null) { strBuf.append(obj.toString() + " "); } for (int i = 0, n = aplosAbstractBeanList.size(); i < n; i++) { strBuf.append(aplosAbstractBeanList.get(i).getId() + " "); } ErrorEmailSender.sendErrorEmail( JSFUtil.getRequest(), ApplicationUtil.getAplosContextListener(), ex, strBuf.toString()); if (aplosAbstractBeanList.size() > 0) { return aplosAbstractBeanList.get(0); } } } return null; } else { return null; } }
public void generateSiteMap(File file) { List<CmsPage> cmsPages = new BeanDao(CmsPage.class).getAll(); StringBuffer sitemapStrBuf = new StringBuffer(); sitemapStrBuf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); sitemapStrBuf.append("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"); CmsPageRevision tempCmsPageRevision; removeUnusedPages(cmsPages, getUnusedMenu().getChildren()); removeUnusedPages(cmsPages, getErrorMenu().getChildren()); for (int i = 0, n = cmsPages.size(); i < n; i++) { tempCmsPageRevision = cmsPages.get(i).getLatestRevision(); if (tempCmsPageRevision != null && cmsPages.get(i).getClass().equals(CmsPage.class)) { sitemapStrBuf.append("<url>"); sitemapStrBuf.append("<loc>"); CmsPageUrl cmsPageUrl = new CmsPageUrl(cmsPages.get(i)); cmsPageUrl.setHost(this); sitemapStrBuf.append(cmsPageUrl.toString()); sitemapStrBuf.append("</loc>"); sitemapStrBuf.append("<lastmod>"); sitemapStrBuf.append(FormatUtil.formatDateForDB(tempCmsPageRevision.getDateLastModified())); sitemapStrBuf.append("</lastmod>"); sitemapStrBuf.append("<priority>"); sitemapStrBuf.append(cmsPages.get(i).getSiteMapPriority()); sitemapStrBuf.append("</priority>"); sitemapStrBuf.append("</url>"); for (CmsAtom tempCmsAtom : tempCmsPageRevision.getCmsAtomList()) { if (tempCmsAtom instanceof BasicCmsContentAtom) { addBasicCmsContentUrls( sitemapStrBuf, (BasicCmsContentFeDmb) ((BasicCmsContentAtom) tempCmsAtom).getFrontendModuleBacking(), tempCmsPageRevision); } } } } List<BlogEntry> blogEntryList = new BeanDao(BlogEntry.class).getAll(); for (int i = 0, n = blogEntryList.size(); i < n; i++) { sitemapStrBuf.append("<url>"); sitemapStrBuf.append("<loc>"); sitemapStrBuf.append( StringEscapeUtils.escapeXml( BlogFeDmb.getBlogEntryUrl( blogEntryList.get(i), CmsConfiguration.getCmsConfiguration().getBlogCpr()))); sitemapStrBuf.append("</loc>"); sitemapStrBuf.append("<lastmod>"); sitemapStrBuf.append(FormatUtil.formatDateForDB(blogEntryList.get(i).getDateLastModified())); sitemapStrBuf.append("</lastmod>"); sitemapStrBuf.append("</url>"); } sitemapStrBuf.append("</urlset>"); try { file.createNewFile(); FileWriter writer = new FileWriter(file); writer.write(sitemapStrBuf.toString()); writer.flush(); writer.close(); } catch (IOException ioex) { ApplicationUtil.handleError(ioex); } }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String templateClass = request.getParameter(AplosAppConstants.TEMPLATE_CLASS); if (templateClass == null || templateClass.equals("")) { return; } ServletContext servletContext = request.getSession().getServletContext(); AplosContextListener aplosContextListener = (AplosContextListener) servletContext.getAttribute(AplosScopedBindings.CONTEXT_LISTENER); String processedTemplateClass; if (PageBindingPhaseListener.getPrintTemplateOverrideMap().containsKey(templateClass)) { processedTemplateClass = PageBindingPhaseListener.getPrintTemplateOverrideMap().get(templateClass); } else { processedTemplateClass = templateClass; } PrintTemplate printTemplate = (PrintTemplate) Class.forName(processedTemplateClass).newInstance(); boolean createPdf = false; boolean createSizedPdf = false; if (request.getParameter(AplosAppConstants.CREATE_PDF) != null && request.getParameter(AplosAppConstants.CREATE_PDF).equals("true")) { createPdf = true; } if (request.getParameter(AplosAppConstants.CREATE_SIZED_PDF) != null && request.getParameter(AplosAppConstants.CREATE_SIZED_PDF).equals("true")) { createSizedPdf = true; } response.setHeader("Content-Disposition", "inline;"); StringInputStream input = null; BufferedOutputStream output = null; try { printTemplate.initialise(response, request); String templateOutput = printTemplate.getTemplateContent(); if (!createSizedPdf) { output = new BufferedOutputStream(response.getOutputStream()); if (createPdf) { ITextRenderer renderer = new ITextRenderer(); ApplicationUtil.getAplosContextListener().addFonts(renderer); renderer.setDocumentFromString(templateOutput); renderer.layout(); renderer.createPDF(output, true); response.setContentType("application/pdf"); } else { input = new StringInputStream(templateOutput); byte[] buffer = new byte[8192]; int length; while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } } } } catch (Exception e) { AplosContextListener.getAplosContextListener().handleError(e); input = new StringInputStream( "There was an error trying to create this report, please contact system support"); byte[] buffer = new byte[8192]; int length; while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } } finally { if (output != null) { try { output.close(); } catch (IOException logOrIgnore) { } } if (input != null) { try { input.close(); } catch (IOException logOrIgnore) { } } } } catch (ClassNotFoundException cnfex) { AplosContextListener.getAplosContextListener().handleError(cnfex); } catch (IllegalAccessException iaex) { AplosContextListener.getAplosContextListener().handleError(iaex); } catch (InstantiationException iex) { AplosContextListener.getAplosContextListener().handleError(iex); } }