/** * When the DataSet editor runs, modifications to the queryText as done in the BindParameter * function will get written to the queryText. To avoid this, we test if the query is being run by * the DataSet editor. * * <p>BIRT 2.5 has added a new Task type that identifies the DataSet editor so that this code is * no longer required. * * @param reportContext * @return */ public static boolean isDataSetEditor(IReportContext reportContext) { try { // get the protect field 'context' from reportContext @SuppressWarnings({"rawtypes"}) Class rciClass = reportContext.getClass(); Field fieldFromScript = rciClass.getDeclaredField("context"); if (fieldFromScript == null) { throw new NoSuchFieldException("Reporting Access to context from IReportContext"); } // instantiate the ExecutionContext object that // populates the context field fieldFromScript.setAccessible(true); Object execContext = fieldFromScript.get(reportContext); ExecutionContext ectx = (ExecutionContext) execContext; IEngineTask et = ectx.getEngineTask(); if ("DummyEngineTask".equalsIgnoreCase(et.getClass().getSimpleName())) { logger.info("Is Data Set Editor"); return true; } } catch (SecurityException e) { logger.warning("BIRT Functions, check for DataSet Editor: " + e.getMessage()); } catch (NoSuchFieldException e) { logger.warning("BIRT Functions, check for DataSet Editor: " + e.getMessage()); } catch (IllegalArgumentException e) { logger.warning("BIRT Functions, check for DataSet Editor: " + e.getMessage()); } catch (IllegalAccessException e) { logger.warning("BIRT Functions, check for DataSet Editor: " + e.getMessage()); } logger.finest("Is Not a Data Set Editor"); return false; }
public static void handleOnPrepare(AutoTextHandle autoTextHandle, ExecutionContext context) { try { IAutoText cell = new AutoText(autoTextHandle); IAutoTextEventHandler eh = getEventHandler(autoTextHandle, context); if (eh != null) eh.onPrepare(cell, context.getReportContext()); } catch (Exception e) { addException(context, e); } }
public static void handleInitialize(ModuleHandle design, ExecutionContext context) { try { String scriptText = design.getInitialize(); Expression.Script scriptExpr = null; if (null != scriptText) { String id = ModuleUtil.getScriptUID(design.getPropertyHandle(IModuleModel.INITIALIZE_METHOD)); scriptExpr = Expression.newScript(scriptText); scriptExpr.setFileName(id); } if (handleScript(null, scriptExpr, context).didRun()) return; IReportEventHandler eh = (IReportEventHandler) getInstance(design, context); if (eh != null) eh.initialize(context.getReportContext()); } catch (Exception e) { addException(context, e, design); } }
public static void handleOnPrepare(ReportDesignHandle report, ExecutionContext context) { try { String scriptText = report.getOnPrepare(); Expression.Script scriptExpr = null; if (null != scriptText) { String id = ModuleUtil.getScriptUID(report.getPropertyHandle(IReportDesignModel.ON_PREPARE_METHOD)); scriptExpr = Expression.newScript(scriptText); scriptExpr.setFileName(id); } if (handleScript(null, scriptExpr, context).didRun()) return; IReportEventHandler eh = (IReportEventHandler) getInstance(report, context); if (eh != null) eh.onPrepare(context.getReportContext()); } catch (Exception e) { addException(context, e, report); } }
public static void handleOnPageBreak(IAutoTextContent content, ExecutionContext context) { Object generateBy = content.getGenerateBy(); if (generateBy == null) { return; } ReportItemDesign autoTextDesign = (ReportItemDesign) generateBy; try { if (!needOnPageBreak(autoTextDesign)) { return; } // fromGrid doesn't matter here since row data is null IAutoTextInstance autoText = new AutoTextInstance(content, context, RunningState.PAGEBREAK); if (handleScript(autoText, autoTextDesign.getOnPageBreak(), context).didRun()) return; IAutoTextEventHandler eh = getEventHandler(autoTextDesign, context); if (eh != null) eh.onPageBreak(autoText, context.getReportContext()); } catch (Exception e) { addException(context, e, autoTextDesign.getHandle()); } }
public static void handleOnCreate(IAutoTextContent content, ExecutionContext context) { Object generateBy = content.getGenerateBy(); if (generateBy == null) { return; } ReportItemDesign autoTextItemDesign = (ReportItemDesign) generateBy; try { if (!needOnCreate(autoTextItemDesign)) { return; } IAutoTextInstance autoText = new AutoTextInstance(content, context, RunningState.CREATE); if (handleScript(autoText, autoTextItemDesign.getOnCreate(), context).didRun()) return; IAutoTextEventHandler eh = getEventHandler(autoTextItemDesign, context); if (eh != null) eh.onCreate(autoText, context.getReportContext()); } catch (Exception e) { addException(context, e, autoTextItemDesign.getHandle()); } }
public static void handleBeforeFactory(ReportDesignHandle report, ExecutionContext context) { try { IDesignElement element = SimpleElementFactory.getInstance().getElement(report); IReportDesign reportDesign = new ReportDesign(report); String scriptText = report.getBeforeFactory(); Expression.Script scriptExpr = null; if (null != scriptText) { String id = ModuleUtil.getScriptUID( report.getPropertyHandle(IReportDesignModel.BEFORE_FACTORY_METHOD)); scriptExpr = Expression.newScript(scriptText); scriptExpr.setFileName(id); } if (handleScript(element, scriptExpr, context).didRun()) return; IReportEventHandler eh = (IReportEventHandler) getInstance(report, context); if (eh != null) eh.beforeFactory(reportDesign, context.getReportContext()); } catch (Exception e) { addException(context, e, report); } }
protected BackgroundImageInfo createBackgroundImage(String url) { ResourceLocatorWrapper rl = null; ExecutionContext exeContext = ((ReportContent) content.getReportContent()).getExecutionContext(); if (exeContext != null) { rl = exeContext.getResourceLocator(); } IStyle cs = pageContent.getComputedStyle(); BackgroundImageInfo backgroundImage = new BackgroundImageInfo( url, cs.getProperty(IStyle.STYLE_BACKGROUND_REPEAT), 0, 0, 0, 0, rl); Image img = backgroundImage.getImageInstance(); IStyle style = pageContent.getStyle(); String widthStr = style.getBackgroundWidth(); String heightStr = style.getBackgroundHeight(); if (img != null) { int resolutionX = img.getDpiX(); int resolutionY = img.getDpiY(); if (0 == resolutionX || 0 == resolutionY) { resolutionX = 96; resolutionY = 96; } float imageWidth = img.getPlainWidth() / resolutionX * 72 * PDFConstants.LAYOUT_TO_PDF_RATIO; float imageHeight = img.getPlainHeight() / resolutionY * 72 * PDFConstants.LAYOUT_TO_PDF_RATIO; int actualWidth = (int) imageWidth; int actualHeight = (int) imageHeight; if (widthStr != null && widthStr.length() > 0 || heightStr != null && heightStr.length() > 0) { if ("contain".equals(widthStr) || "contain".equals(heightStr)) { float rh = imageHeight / height; float rw = imageWidth / width; if (rh > rw) { actualHeight = height; actualWidth = (int) (imageWidth * height / imageHeight); } else { actualWidth = width; actualHeight = (int) (imageHeight * width / imageWidth); } } else if ("cover".equals(widthStr) || "cover".equals(heightStr)) { float rh = imageHeight / height; float rw = imageWidth / width; if (rh > rw) { actualWidth = width; actualHeight = (int) (imageHeight * width / imageWidth); } else { actualHeight = height; actualWidth = (int) (imageWidth * height / imageHeight); } } else { DimensionType widthDim = DimensionType.parserUnit(widthStr); DimensionType heightDim = DimensionType.parserUnit(heightStr); if (widthDim != null) { actualWidth = PropertyUtil.getDimensionValue(content, widthDim); if (heightDim == null) { actualHeight = (int) (imageHeight * actualWidth / imageWidth); } else { actualHeight = PropertyUtil.getDimensionValue(content, heightDim); } } else if (heightDim != null) { actualHeight = PropertyUtil.getDimensionValue(content, heightDim); if (widthDim == null) { actualWidth = (int) (imageWidth * actualHeight / imageHeight); } else { actualWidth = PropertyUtil.getDimensionValue(content, widthDim); } } else { actualHeight = (int) imageHeight; actualWidth = (int) imageWidth; } } } backgroundImage.setXOffset( getDimensionValue( cs.getProperty(IStyle.STYLE_BACKGROUND_POSITION_X), width - actualWidth)); backgroundImage.setYOffset( getDimensionValue( cs.getProperty(IStyle.STYLE_BACKGROUND_POSITION_Y), height - actualHeight)); backgroundImage.setHeight(actualHeight); backgroundImage.setWidth(actualWidth); return backgroundImage; } return null; }