From: Oleg A. <oan...@ea...> - 2009-06-16 18:49:08
|
Author: oandreyev Date: 2009-06-16 11:48:15 -0700 (Tue, 16 Jun 2009) New Revision: 12359 Modified: versions/1.0/trunk/hot-deploy/financials/webapp/financials/reports/GlActivityAnalysisSetup.ftl versions/1.0/trunk/hot-deploy/opentaps-common/src/common/org/opentaps/common/reporting/jasper/JasperReportsViewHandler.java Log: Remove exporter parameters handling from JR view handler as they may be included into report design. Remove parameters from GL account activity report as they were in step with default values. Modified: versions/1.0/trunk/hot-deploy/financials/webapp/financials/reports/GlActivityAnalysisSetup.ftl =================================================================== --- versions/1.0/trunk/hot-deploy/financials/webapp/financials/reports/GlActivityAnalysisSetup.ftl 2009-06-16 17:06:51 UTC (rev 12358) +++ versions/1.0/trunk/hot-deploy/financials/webapp/financials/reports/GlActivityAnalysisSetup.ftl 2009-06-16 18:48:15 UTC (rev 12359) @@ -28,13 +28,6 @@ <@inputHidden name="organizationPartyId" value="${parameters.organizationPartyId}"/> <@inputHidden name="reportPath" value="${reportPath}"/> - <#-- XLS exporter properties --> - <@inputHidden name="jrXlsIsFontSizeFixEnabled" value="true"/> - <@inputHidden name="jrXlsIsIgnoreCellBorder" value="true"/> - <@inputHidden name="jrXlsIsIgnoreGraphics" value="true"/> - <@inputHidden name="jrXlsIsRemoveEmptySpaceBetweenRows" value="true"/> - <@inputHidden name="jrXlsIsWhitePageBackground" value="false"/> - <@inputDateRow name="fromDate" form="GlActivityAnalysisSetupForm" title="${uiLabelMap.CommonFromDate}" default=fromDate?if_exists/> <@inputDateRow name="thruDate" form="GlActivityAnalysisSetupForm" title="${uiLabelMap.CommonThruDate}" default=thruDate?if_exists/> <@inputAutoCompleteGlAccountRow name="glAccountId" title="${uiLabelMap.AccountingGlAcc}" /> Modified: versions/1.0/trunk/hot-deploy/opentaps-common/src/common/org/opentaps/common/reporting/jasper/JasperReportsViewHandler.java =================================================================== --- versions/1.0/trunk/hot-deploy/opentaps-common/src/common/org/opentaps/common/reporting/jasper/JasperReportsViewHandler.java 2009-06-16 17:06:51 UTC (rev 12358) +++ versions/1.0/trunk/hot-deploy/opentaps-common/src/common/org/opentaps/common/reporting/jasper/JasperReportsViewHandler.java 2009-06-16 18:48:15 UTC (rev 12359) @@ -52,6 +52,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import javolution.util.FastMap; import net.sf.jasperreports.engine.JRDataSource; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRExporter; @@ -61,7 +62,6 @@ import net.sf.jasperreports.engine.JasperReport; import net.sf.jasperreports.engine.export.FontKey; import net.sf.jasperreports.engine.export.JExcelApiExporter; -import net.sf.jasperreports.engine.export.JExcelApiExporterParameter; import net.sf.jasperreports.engine.export.JRCsvExporter; import net.sf.jasperreports.engine.export.JRHtmlExporter; import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; @@ -70,7 +70,6 @@ import net.sf.jasperreports.engine.export.JRRtfExporter; import net.sf.jasperreports.engine.export.JRTextExporter; import net.sf.jasperreports.engine.export.JRTextExporterParameter; -import net.sf.jasperreports.engine.export.JRXlsAbstractExporterParameter; import net.sf.jasperreports.engine.export.JRXmlExporter; import net.sf.jasperreports.engine.export.PdfFont; import net.sf.jasperreports.engine.export.oasis.JROdtExporter; @@ -86,6 +85,7 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.jdbc.ConnectionFactory; import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.party.party.PartyHelper; import org.ofbiz.webapp.control.ContextFilter; import org.ofbiz.webapp.view.ViewHandler; import org.ofbiz.webapp.view.ViewHandlerException; @@ -222,7 +222,7 @@ // Generates and exports report ContentType content = UtilReports.getContentType(myContentType); - generate(request.getParameter("reportName"), jp, content, response, extractExporterParameters(request, parameters, content)); + generate(request.getParameter("reportName"), jp, content, request, response); } catch (java.sql.SQLException e) { Debug.logError(e.getMessage(), MODULE); @@ -256,17 +256,18 @@ /** * Method will stream out the requested report in various report types (pdf, word, excel, text, xml). - * @param name Friendly name of report - * @param jasperPrint JasperPrint - * @param contentType String - * @param response HttpServletResponse + * + * @param name report friendly name + * @param jasperPrint compiled report object + * @param contentType MIME type, a <code>ContentType</code> value + * @param request HttpServletResponce object + * @param response HttpServletResponse object * @throws IOException * @throws JRException - * - * @throws Exception */ - private void generate(String name, JasperPrint jasperPrint, ContentType contentType, HttpServletResponse response, Map<Object, Object> exporterParameters) throws IOException, JRException { + private void generate(String name, JasperPrint jasperPrint, ContentType contentType, HttpServletRequest request, HttpServletResponse response) throws IOException, JRException { ServletOutputStream os = response.getOutputStream(); + Map<JRExporterParameter, Object> exporterParameters = FastMap.newInstance(); JRExporter exporter = null; String reportName = UtilValidate.isEmpty(name) ? jasperPrint.getName() : name; if (UtilValidate.isEmpty(reportName)) { @@ -279,6 +280,16 @@ exporterParameters.put(JRExporterParameter.JASPER_PRINT, jasperPrint); exporterParameters.put(JRExporterParameter.OUTPUT_STREAM, os); exporterParameters.put(JRPdfExporterParameter.FONT_MAP, getPdfFontMap()); + // add logged user as author + HttpSession session = request.getSession(); + GenericValue person = (GenericValue) session.getAttribute("person"); + if (UtilValidate.isNotEmpty(person)) { + exporterParameters.put(JRPdfExporterParameter.METADATA_AUTHOR, PartyHelper.getPartyName((GenericDelegator) request.getAttribute("delegator"), person.getString("partyId"), false)); + } + // add product name as creator + String opentaps = UtilProperties.getPropertyValue("OpentapsUiLabels.properties", "OpentapsProductName"); + if (UtilValidate.isNotEmpty(opentaps)) exporterParameters.put(JRPdfExporterParameter.METADATA_CREATOR, opentaps); + } else if (contentType.equals(ContentType.HTML)) { response.setHeader(HEADER_CONTENT_DISPOSITION, String.format("attachment; filename=\"%1$s.html\"", reportName)); exporter = new JRHtmlExporter(); @@ -442,134 +453,4 @@ return fontMap; } - - /** - * @param parameters - * @param mimeType - * @return - */ - Map<Object, Object> extractExporterParameters(HttpServletRequest request, Map<String, Object> parameters, ContentType contentType) { - Map<Object, Object> exporterParameters = new HashMap<Object, Object>(); - Object currentParameter = null; - if (contentType.equals(ContentType.PDF)) { - - if ((currentParameter = parameters.get("jrPdfForceLinebreakPolicy")) != null) - exporterParameters.put(JRPdfExporterParameter.FORCE_LINEBREAK_POLICY, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrPdfForceSvgShapes")) != null) - exporterParameters.put(JRPdfExporterParameter.FORCE_SVG_SHAPES, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrPdfIs128BitKey")) != null) - exporterParameters.put(JRPdfExporterParameter.IS_128_BIT_KEY, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrPdfIsCompressed")) != null) - exporterParameters.put(JRPdfExporterParameter.IS_COMPRESSED, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrPdfIsCreatingBatchModeBookmarks")) != null) - exporterParameters.put(JRPdfExporterParameter.IS_CREATING_BATCH_MODE_BOOKMARKS, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrPdfIsEncrypted")) != null) - exporterParameters.put(JRPdfExporterParameter.IS_ENCRYPTED, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrPdfMetadataAuthor")) != null) { - exporterParameters.put(JRPdfExporterParameter.METADATA_AUTHOR, currentParameter); - } else { - // user's name as PDF author by default - HttpSession session = request.getSession(); - GenericValue person = (GenericValue) session.getAttribute("person"); - if (UtilValidate.isNotEmpty(person)) - exporterParameters.put(JRPdfExporterParameter.METADATA_AUTHOR, String.format("%1$s %2$s", person.getString("firstName"), person.getString("lastName"))); - } - if ((currentParameter = parameters.get("jrPdfMetadataCreator")) != null) { - exporterParameters.put(JRPdfExporterParameter.METADATA_CREATOR, currentParameter); - } else { - // application name as creator by default - String opentaps = UtilProperties.getPropertyValue("OpentapsUiLabels.properties", "OpentapsProductName"); - if (UtilValidate.isNotEmpty(opentaps)) exporterParameters.put(JRPdfExporterParameter.METADATA_CREATOR, opentaps); - } - if ((currentParameter = parameters.get("jrPdfMetadataKeywords")) != null) - exporterParameters.put(JRPdfExporterParameter.METADATA_KEYWORDS, currentParameter); - if ((currentParameter = parameters.get("jrPdfMetadataSubject")) != null) - exporterParameters.put(JRPdfExporterParameter.METADATA_SUBJECT, currentParameter); - if ((currentParameter = parameters.get("jrPdfMetadataTitle")) != null) - exporterParameters.put(JRPdfExporterParameter.METADATA_TITLE, currentParameter); - if ((currentParameter = parameters.get("jrPdfOwnerPassword")) != null) - exporterParameters.put(JRPdfExporterParameter.OWNER_PASSWORD, currentParameter); - if ((currentParameter = parameters.get("jrPdfUserPassword")) != null) - exporterParameters.put(JRPdfExporterParameter.USER_PASSWORD, currentParameter); - if ((currentParameter = parameters.get("jrPdfJavascript")) != null) - exporterParameters.put(JRPdfExporterParameter.PDF_JAVASCRIPT, currentParameter); - if ((currentParameter = parameters.get("jrPdfVersion")) != null) - exporterParameters.put(JRPdfExporterParameter.PDF_VERSION, currentParameter instanceof Character ? currentParameter : new Character(((String)currentParameter).charAt(0))); - if ((currentParameter = parameters.get("jrPdfPermission")) != null) - exporterParameters.put(JRPdfExporterParameter.PERMISSIONS, currentParameter instanceof Integer ? currentParameter : new Integer((String)currentParameter)); - - } if (contentType.equals(ContentType.XLS)) { - - if ((currentParameter = parameters.get("jrXlsIsCollapseRowSpan")) != null) - exporterParameters.put(JRXlsAbstractExporterParameter.IS_COLLAPSE_ROW_SPAN, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrXlsIsDetectCellType")) != null) - exporterParameters.put(JRXlsAbstractExporterParameter.IS_DETECT_CELL_TYPE, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrXlsIsFontSizeFixEnabled")) != null) - exporterParameters.put(JRXlsAbstractExporterParameter.IS_FONT_SIZE_FIX_ENABLED, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrXlsIsIgnoreCellBorder")) != null) - exporterParameters.put(JRXlsAbstractExporterParameter.IS_IGNORE_CELL_BORDER, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrXlsIsIgnoreGraphics")) != null) - exporterParameters.put(JRXlsAbstractExporterParameter.IS_IGNORE_GRAPHICS, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrXlsIsOnePagePerSheet")) != null) - exporterParameters.put(JRXlsAbstractExporterParameter.IS_ONE_PAGE_PER_SHEET, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrXlsIsRemoveEmptySpaceBetweenRows")) != null) - exporterParameters.put(JRXlsAbstractExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrXlsIsWhitePageBackground")) != null) - exporterParameters.put(JRXlsAbstractExporterParameter.IS_WHITE_PAGE_BACKGROUND, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrXlsMaximumRowsPerSheet")) != null) - exporterParameters.put(JRXlsAbstractExporterParameter.MAXIMUM_ROWS_PER_SHEET, currentParameter instanceof Integer ? currentParameter : new Integer((String)currentParameter)); - //TODO: arrays of string. JSON? - if ((currentParameter = parameters.get("jrXlsSheetNames")) != null) - exporterParameters.put(JRXlsAbstractExporterParameter.SHEET_NAMES, currentParameter); - if ((currentParameter = parameters.get("jrXlsCreateCustomPalette")) != null) - exporterParameters.put(JExcelApiExporterParameter.CREATE_CUSTOM_PALETTE, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - - } if (contentType.equals(ContentType.CSV)) { - - } if (contentType.equals(ContentType.HTML)) { - - if ((currentParameter = parameters.get("jrHtmlBetweenPages")) != null) - exporterParameters.put(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, currentParameter); - if ((currentParameter = parameters.get("jrHtmlFooter")) != null) - exporterParameters.put(JRHtmlExporterParameter.HTML_FOOTER, currentParameter); - if ((currentParameter = parameters.get("jrHtmlIsRemoveEmptySpaceBetweenRows")) != null) - exporterParameters.put(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrHtmlFramesAsNestedTables")) != null) - exporterParameters.put(JRHtmlExporterParameter.FRAMES_AS_NESTED_TABLES, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrHtmlHeader")) != null) - exporterParameters.put(JRHtmlExporterParameter.HTML_HEADER, currentParameter); - if ((currentParameter = parameters.get("jrHtmlImagesDir")) != null) - exporterParameters.put(JRHtmlExporterParameter.IMAGES_DIR, currentParameter); - if ((currentParameter = parameters.get("jrHtmlImagesDirName")) != null) - exporterParameters.put(JRHtmlExporterParameter.IMAGES_DIR_NAME, currentParameter); - if ((currentParameter = parameters.get("jrHtmlImagesUri")) != null) - exporterParameters.put(JRHtmlExporterParameter.IMAGES_URI, currentParameter); - if ((currentParameter = parameters.get("jrHtmlIsOutputImagesToDir")) != null) - exporterParameters.put(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrHtmlIsUsingImagesToAlign")) != null) - exporterParameters.put(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrHtmlIsWhitePageBackground")) != null) - exporterParameters.put(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, currentParameter instanceof Boolean ? currentParameter : new Boolean((String)currentParameter)); - if ((currentParameter = parameters.get("jrHtmlIsWrapBreakWord")) != null) - exporterParameters.put(JRHtmlExporterParameter.IS_WRAP_BREAK_WORD, currentParameter); - - } if (contentType.equals(ContentType.TXT)) { - - if ((currentParameter = parameters.get("jrTextBetweenPages")) != null) - exporterParameters.put(JRTextExporterParameter.BETWEEN_PAGES_TEXT, currentParameter); - if ((currentParameter = parameters.get("jrTextCharacterHeight")) != null) - exporterParameters.put(JRTextExporterParameter.CHARACTER_HEIGHT, currentParameter instanceof Integer ? currentParameter : new Integer((String)currentParameter)); - if ((currentParameter = parameters.get("jrTextCharacterWidth")) != null) - exporterParameters.put(JRTextExporterParameter.CHARACTER_WIDTH, currentParameter instanceof Integer ? currentParameter : new Integer((String)currentParameter)); - if ((currentParameter = parameters.get("jrTextLineSeparator")) != null) - exporterParameters.put(JRTextExporterParameter.LINE_SEPARATOR, currentParameter); - if ((currentParameter = parameters.get("jrTextPageHeight")) != null) - exporterParameters.put(JRTextExporterParameter.PAGE_HEIGHT, currentParameter instanceof Integer ? currentParameter : new Integer((String)currentParameter)); - if ((currentParameter = parameters.get("jrTextPageWidth")) != null) - exporterParameters.put(JRTextExporterParameter.PAGE_WIDTH, currentParameter instanceof Integer ? currentParameter : new Integer((String)currentParameter)); - - } - - return exporterParameters; - } } \ No newline at end of file |