Java 类net.sf.jasperreports.engine.util.JRExpressionUtil 实例源码

项目:jasperreports    文件:ChartConverter.java   
@Override
public JRPrintElement convert(ReportConverter reportConverter, JRElement element)
{
    JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider());
    JRChart chart = (JRChart)element;

    copyElement(reportConverter, chart, printImage);

    printImage.copyBox(chart.getLineBox());

    printImage.setAnchorName(JRExpressionUtil.getExpressionText(chart.getAnchorNameExpression()));
    printImage.setBookmarkLevel(chart.getBookmarkLevel());
    printImage.setLinkType(chart.getLinkType());
    printImage.setOnErrorType(OnErrorTypeEnum.ICON);
    printImage.setRenderer(getRenderer(reportConverter, chart));
    printImage.setScaleImage(ScaleImageEnum.CLIP);

    return printImage;
}
项目:jasperreports    文件:ReportConverter.java   
protected void loadReportTemplateStyles(JRReportTemplate template, Set<String> loadedLocations)
{
    JRExpression sourceExpression = template.getSourceExpression();
    if (sourceExpression != null)
    {
        String location = JRExpressionUtil.getSimpleExpressionText(sourceExpression);
        if (location == null)
        {
            log.warn("Template source expression " + sourceExpression.getText() 
                    + "cannot be evaluated; some styles might remain unresolved.");
        }
        else
        {
            HashSet<String> parentLocations = new HashSet<String>();
            loadTemplateStyles(location, loadedLocations, parentLocations);
        }
    }
}
项目:jasperreports    文件:TextFieldConverter.java   
@Override
public JRPrintElement convert(ReportConverter reportConverter, JRElement element)
{
    JRBasePrintText printText = new JRBasePrintText(reportConverter.getDefaultStyleProvider());
    JRTextField textField = (JRTextField)element;

    copyTextElement(reportConverter, textField, printText);

    printText.setMarkup(JRCommonText.MARKUP_NONE);//text fields are never converted to styled print text elements
    printText.setAnchorName(JRExpressionUtil.getExpressionText(textField.getAnchorNameExpression()));
    printText.setBookmarkLevel(textField.getBookmarkLevel());
    printText.setLinkType(textField.getLinkType());
    printText.setPattern(textField.getOwnPattern());

    printText.setText(JRExpressionUtil.getExpressionText(textField.getExpression()));

    JRTextMeasurerUtil.getInstance(reportConverter.getJasperReportsContext()).measureTextElement(printText);

    return printText;
}
项目:PDFReporter-Studio    文件:ChartConverter.java   
/**
 *
 */
public JRPrintElement convert(ReportConverter reportConverter, JRElement element) {
    JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider());
    JRChart chart = (JRChart) element;

    copyElement(reportConverter, chart, printImage);

    printImage.copyBox(chart.getLineBox());

    printImage.setAnchorName(JRExpressionUtil.getExpressionText(chart.getAnchorNameExpression()));
    printImage.setBookmarkLevel(chart.getBookmarkLevel());
    printImage.setLinkType(chart.getLinkType());
    printImage.setOnErrorType(OnErrorTypeEnum.ICON);
    printImage.setRenderable(getRenderer(reportConverter, chart));
    printImage.setScaleImage(ScaleImageEnum.CLIP);

    return printImage;
}
项目:PDFReporter-Studio    文件:ImageConverter.java   
/**
 *
 */
public JRPrintElement convert(final ReportConverter reportConverter, final JRElement element) {
    JRImage image = (JRImage) element;
    JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider());
    Renderable cacheRenderer = getRenderable(reportConverter, element, image, printImage);
    copyGraphicElement(reportConverter, image, printImage);

    printImage.copyBox(image.getLineBox());

    printImage.setAnchorName(JRExpressionUtil.getExpressionText(image.getAnchorNameExpression()));
    printImage.setBookmarkLevel(image.getBookmarkLevel());
    printImage.setHorizontalAlignment(image.getOwnHorizontalAlignmentValue());
    printImage.setLazy(image.isLazy());
    printImage.setLinkType(image.getLinkType());
    printImage.setOnErrorType(OnErrorTypeEnum.ICON);
    printImage.setVerticalAlignment(image.getOwnVerticalAlignmentValue());
    if (cacheRenderer == null)
        cacheRenderer = getRenderableNoImage(reportConverter.getJasperReportsContext(), image, printImage);
    printImage.setRenderable(cacheRenderer);
    printImage.setScaleImage(image.getOwnScaleImageValue());

    return printImage;
}
项目:PDFReporter-Studio    文件:LazyImageConverter.java   
/**
 * Return the content for an MImage element
 * 
 * @param reportConverter the report converter 
 * @param element a not null MImage element
 * @return An image pointed by the expression of the element if it can be found, the
 * standard not found image otherwise. it is never null
 */
public JRPrintElement convertImage(ReportConverter reportConverter, MGraphicElement element){
    JRImage image = (JRImage) element.getValue();
    JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider());
    Renderable cacheRenderer = getRenderable(reportConverter, image, element);
    copyGraphicElement(reportConverter, image, printImage);

    printImage.copyBox(image.getLineBox());

    printImage.setAnchorName(JRExpressionUtil.getExpressionText(image.getAnchorNameExpression()));
    printImage.setBookmarkLevel(image.getBookmarkLevel());
    printImage.setHorizontalAlignment(image.getOwnHorizontalAlignmentValue());
    printImage.setLazy(image.isLazy());
    printImage.setLinkType(image.getLinkType());
    printImage.setOnErrorType(OnErrorTypeEnum.ICON);
    printImage.setVerticalAlignment(image.getOwnVerticalAlignmentValue());
    //If it is null load the no image found element
    if (cacheRenderer == null)
        cacheRenderer = getRenderableNoImage(reportConverter.getJasperReportsContext(), image, printImage);
    printImage.setRenderable(cacheRenderer);
    printImage.setScaleImage(image.getOwnScaleImageValue());

    return printImage;
}
项目:jasperreports    文件:FlyingSaucerHtmlPrintElement.java   
@Override
public JRPrintImage createImageFromComponentElement(JRComponentElement componentElement) throws JRException {
    HtmlComponent html = (HtmlComponent) componentElement.getComponent();

    String htmlContent = "";

    if (html.getHtmlContentExpression() != null) {
        htmlContent = JRExpressionUtil.getExpressionText(html.getHtmlContentExpression());
    }

    JRBasePrintImage printImage = new JRBasePrintImage(componentElement.getDefaultStyleProvider());

    printImage.setStyle(componentElement.getStyle());
    printImage.setMode(componentElement.getModeValue());
    printImage.setBackcolor(componentElement.getBackcolor());
    printImage.setForecolor(componentElement.getForecolor());
    printImage.setX(componentElement.getX());
    printImage.setY(componentElement.getY());
    printImage.setWidth(componentElement.getWidth());
    printImage.setHeight(componentElement.getHeight());
    printImage.setScaleImage(html.getScaleType());
    printImage.setHorizontalImageAlign(html.getHorizontalImageAlign());
    printImage.setVerticalImageAlign(html.getVerticalImageAlign());

    FlyingSaucerXhtmlToImageRenderer renderer = new FlyingSaucerXhtmlToImageRenderer(getHtmlDocument(htmlContent), componentElement.getWidth(), componentElement.getHeight());
    printImage.setRenderer(renderer);
    return printImage;
}
项目:jasperreports    文件:DefaultHtmlPrintElement.java   
@Override
public JRPrintImage createImageFromComponentElement(JRComponentElement componentElement) throws JRException {
    HtmlComponent html = (HtmlComponent) componentElement.getComponent();

    JEditorPane editorPane = new JEditorPane();
    editorPane.setEditorKitForContentType("text/html", new SynchronousImageLoaderKit());
    editorPane.setContentType("text/html");

    String htmlContent = "";

    if (html.getHtmlContentExpression() != null) {
        htmlContent = JRExpressionUtil.getExpressionText(html.getHtmlContentExpression());
    }

    editorPane.setText(htmlContent);
    editorPane.setBorder(null);
    editorPane.setSize(editorPane.getPreferredSize());

    JRBasePrintImage printImage = new JRBasePrintImage(componentElement.getDefaultStyleProvider());
    printImage.setX(componentElement.getX());
    printImage.setY(componentElement.getY());
    printImage.setWidth(componentElement.getWidth());
    printImage.setHeight(componentElement.getHeight());
    printImage.setScaleImage(html.getScaleType());
    printImage.setHorizontalImageAlign(html.getHorizontalImageAlign());
    printImage.setVerticalImageAlign(html.getVerticalImageAlign());
    printImage.setStyle(componentElement.getStyle());
    printImage.setMode(componentElement.getModeValue());
    printImage.setBackcolor(componentElement.getBackcolor());
    printImage.setForecolor(componentElement.getForecolor());

    printImage.setRenderer(new AwtComponentRendererImpl(editorPane));

    return printImage;
}
项目:jasperreports    文件:ImageConverter.java   
@Override
public JRPrintElement convert(ReportConverter reportConverter, JRElement element)
{
    JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider());
    JRImage image = (JRImage)element;

    copyGraphicElement(reportConverter, image, printImage);

    printImage.copyBox(image.getLineBox());

    printImage.setAnchorName(JRExpressionUtil.getExpressionText(image.getAnchorNameExpression()));
    printImage.setBookmarkLevel(image.getBookmarkLevel());
    printImage.setHorizontalImageAlign(image.getOwnHorizontalImageAlign());
    printImage.setLinkType(image.getLinkType());
    printImage.setOnErrorType(OnErrorTypeEnum.ICON);
    printImage.setVerticalImageAlign(image.getOwnVerticalImageAlign());

    printImage.setRenderer(
        ResourceRenderer.getInstance(
            JRExpressionUtil.getSimpleExpressionText(image.getExpression()),
            image.isLazy()
            )
        );

    printImage.setScaleImage(image.getOwnScaleImageValue());

    return printImage;
}
项目:jasperreports    文件:BarcodeDesignEvaluator.java   
protected String evaluateStringExpression(JRExpression expression, String defaultValue)
{
    String value = JRExpressionUtil.getSimpleExpressionText(expression);
    if (value == null)
    {
        value = defaultValue;
    }
    return value;
}
项目:PDFReporter-Studio    文件:ExpressionUtil.java   
/**
 * Resolve an expression and return its value or null if it can not be resolve. First it will try to use a simple evaluation
 * since it is much faster. If this can't resolve the expression then an interpreter for the current report is created 
 * and cached (since create and interpreter is very slow) 
 * 
 * @param exp expression to resolve
 * @param project project of the report
 * @param jConfig Configuration of the report to evaluate the expression
 * @param dataset the context of the expression resolution
 * @return resolved expression or null it it can't be resolved
 */
public static String cachedExpressionEvaluation(JRExpression exp, JasperReportsConfiguration jConfig, JRDesignDataset dataset){ 
    synchronized (datasetsIntepreters) {
        String evaluatedExpression = null;
        String expString = exp != null ? exp.getText() : "";
        try{
            evaluatedExpression = JRExpressionUtil.getSimpleExpressionText(exp);
            if (evaluatedExpression == null && dataset != null){
                //Unable to interpret the expression, lets try with a more advanced (and slow, so its cached) interpreter
                JasperDesign jd = jConfig.getJasperDesign();
                ExpressionInterpreter interpreter = datasetsIntepreters.get(dataset);
                if (interpreter == null){
                    if (exp != null && jd != null){
                        interpreter = new ExpressionInterpreter(dataset, jd, jConfig);
                        datasetsIntepreters.put(dataset, interpreter);
                        //The dataset was added to the cache, check if it has the listener and add them where are needed
                        setDatasetListners(dataset);
                        setDesignListener(jd, jConfig);
                    }
                }
                if (interpreter != null){
                    Object expressionValue = interpreter.interpretExpression(expString);
                    if (expressionValue != null) evaluatedExpression = expressionValue.toString();
                }
            }
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return evaluatedExpression;
    }
}
项目:ireport-fork    文件:CreateImageAction.java   
public JRDesignElement createReportElement(JasperDesign jd)
{
        RepositoryFile file = (RepositoryFile) getPaletteItem().getData();


        JRDesignElement element = new JRDesignImage(jd);
        element.setWidth(100);
        element.setHeight(50);

        JRDesignExpression exp = new JRDesignExpression();
        exp.setValueClassName("java.lang.String");
        exp.setText("\"repo:" + file.getDescriptor().getUriString()+"\"");

        // Try to load the image...
        try {
            String fname = file.getFile();

            ImageIcon img = new ImageIcon(fname);
            element.setWidth(img.getIconWidth());
            element.setHeight(img.getIconHeight());

            RepoImageCache.getInstance().put( JRExpressionUtil.getSimpleExpressionText(exp) , new File(fname));

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        ((JRDesignImage)element).setExpression(exp);

        return element;
}
项目:jasperreports    文件:JavaScriptCompiler.java   
@Override
protected String compileUnits(JRCompilationUnit[] units, String classpath,
        File tempDirFile) throws JRException
{
    Context context = ContextFactory.getGlobal().enterContext();
    try
    {
        Errors errors = new Errors();
        for (int i = 0; i < units.length; i++)
        {
            JRCompilationUnit unit = units[i];
            JavaScriptCompileData compileData = new JavaScriptCompileData();
            for (Iterator<JRExpression> it = unit.getExpressions().iterator(); it.hasNext();)
            {
                JRExpression expr = it.next();
                int id = unit.getCompileTask().getExpressionId(expr).intValue();

                ScriptExpressionVisitor defaultVisitor = defaultExpressionCreator();
                JRExpressionUtil.visitChunks(expr, defaultVisitor);
                String defaultExpression = defaultVisitor.getScript();

                //compile the default expression to catch syntax errors
                try
                {
                    context.compileString(defaultExpression, "expression", 0, null);
                }
                catch (EvaluatorException e)
                {
                    errors.addError(e);
                }

                if (!errors.hasErrors())
                {
                    ScriptExpressionVisitor oldVisitor = oldExpressionCreator();
                    ScriptExpressionVisitor estimatedVisitor = estimatedExpressionCreator();
                    JRExpressionUtil.visitChunks(expr, new CompositeExpressionChunkVisitor(oldVisitor, estimatedVisitor));

                    compileData.addExpression(id, defaultExpression, estimatedVisitor.getScript(), oldVisitor.getScript());
                }
            }

            if (!errors.hasErrors())
            {
                unit.setCompileData(compileData);
            }
        }

        return errors.errorMessage();
    }
    finally
    {
        Context.exit();
    }
}
项目:jasperreports    文件:JavaScriptClassCompiler.java   
@Override
protected String compileUnits(JRCompilationUnit[] units, String classpath,
        File tempDirFile) throws JRException
{
    Context context = ContextFactory.getGlobal().enterContext();
    try
    {
        JRPropertiesUtil properties = JRPropertiesUtil.getInstance(jasperReportsContext);
        int expressionsPerScript = properties.getIntegerProperty(PROPERTY_EXPRESSIONS_PER_SCRIPT);
        int scriptMaxLength = properties.getIntegerProperty(PROPERTY_SCRIPT_MAX_SIZE);

        int optimizationLevel = properties.getIntegerProperty(PROPERTY_OPTIMIZATION_LEVEL);
        context.setOptimizationLevel(optimizationLevel);
        context.getWrapFactory().setJavaPrimitiveWrap(false);

        Errors errors = new Errors();

        CompilerEnvirons compilerEnv = new CompilerEnvirons();
        compilerEnv.initFromContext(context);

        // we're using the context to compile the expressions in interpreted mode to catch syntax errors 
        context.setOptimizationLevel(-1);

        for (int i = 0; i < units.length; i++)
        {
            JRCompilationUnit unit = units[i];
            CompileSources compileSources = new CompileSources(expressionsPerScript, scriptMaxLength);
            JavaScriptCompiledData compiledData = new JavaScriptCompiledData();

            for (Iterator<JRExpression> it = unit.getExpressions().iterator(); it.hasNext();)
            {
                JRExpression expr = it.next();
                int id = unit.getCompileTask().getExpressionId(expr).intValue();

                ScriptExpressionVisitor defaultVisitor = defaultExpressionCreator();
                JRExpressionUtil.visitChunks(expr, defaultVisitor);
                String defaultExpression = defaultVisitor.getScript();

                //compile the default expression to catch syntax errors
                try
                {
                    context.compileString(defaultExpression, "expression", 0, null);
                }
                catch (EvaluatorException e)
                {
                    errors.addError(e);
                }

                if (!errors.hasErrors())
                {
                    ScriptExpressionVisitor oldVisitor = oldExpressionCreator();
                    ScriptExpressionVisitor estimatedVisitor = estimatedExpressionCreator();
                    JRExpressionUtil.visitChunks(expr, new CompositeExpressionChunkVisitor(oldVisitor, estimatedVisitor));

                    int defaultExpressionIdx = compileSources.addExpression(defaultExpression);
                    int oldExpressionIdx = compileSources.addExpression(oldVisitor.getScript());
                    int estimatedExpressionIdx = compileSources.addExpression(estimatedVisitor.getScript());

                    compiledData.addExpression(id, defaultExpressionIdx, oldExpressionIdx, estimatedExpressionIdx);
                }
            }

            if (!errors.hasErrors())
            {
                compileScripts(unit, compilerEnv, compileSources, compiledData);
                unit.setCompileData(compiledData);
            }
        }

        return errors.errorMessage();
    }
    finally
    {
        Context.exit();
    }
}
项目:jasperreports    文件:SpiderChartDesignConverter.java   
@Override
    public JRPrintElement convert(ReportConverter reportConverter, JRComponentElement element)
    {
        SpiderChartComponent chartComponent = (SpiderChartComponent) element.getComponent();
        if (chartComponent == null)
        {
            return null;
        }
        JRBasePrintImage printImage = new JRBasePrintImage(reportConverter.getDefaultStyleProvider());
        ChartSettings chartSettings = chartComponent.getChartSettings();

        reportConverter.copyBaseAttributes(element, printImage);

        //TODO: spiderchart box
//      printImage.copyBox(element.getLineBox());

        printImage.setAnchorName(JRExpressionUtil.getExpressionText(chartSettings.getAnchorNameExpression()));
        printImage.setBookmarkLevel(chartSettings.getBookmarkLevel());
        printImage.setLinkType(chartSettings.getLinkType());
        printImage.setOnErrorType(OnErrorTypeEnum.ICON);
        printImage.setScaleImage(ScaleImageEnum.CLIP);
        SpiderChartSharedBean spiderchartBean = 
            new SpiderChartSharedBean(
                chartSettings.getRenderType(),
                SpiderChartRendererEvaluator.SAMPLE_MAXVALUE,
                JRExpressionUtil.getExpressionText(chartSettings.getTitleExpression()),
                JRExpressionUtil.getExpressionText(chartSettings.getSubtitleExpression()),
                null,
                null
                );

        printImage.setRenderer(
            SpiderChartRendererEvaluator.evaluateRenderable(
                reportConverter.getJasperReportsContext(),
                element,
                spiderchartBean,
                null,
                JRPropertiesUtil.getInstance(reportConverter.getJasperReportsContext()).getProperty(reportConverter.getReport(), JRChart.PROPERTY_CHART_RENDER_TYPE),
                SpiderChartRendererEvaluator.SAMPLE_DATASET)
                );

        return printImage;
    }
项目:jasperreports    文件:BarbecueDesignConverter.java   
@Override
public JRPrintElement convert(ReportConverter reportConverter,
        JRComponentElement element)
{
    BarbecueComponent component = (BarbecueComponent) element.getComponent();
    if (component == null || component.getType() == null)
    {
        return null;
    }

    try
    {
        JRBasePrintImage image = new JRBasePrintImage(
                reportConverter.getDefaultStyleProvider());
        reportConverter.copyBaseAttributes(element, image);
        image.setScaleImage(ScaleImageEnum.RETAIN_SHAPE);

        String code = null;
        if (component.getCodeExpression() != null)
        {
            code = JRExpressionUtil.getSimpleExpressionText(
                    component.getCodeExpression());
        }
        if (code == null)
        {
            //TODO custom default code
            code = DEFAULT_PREVIEW_CODE;
        }

        String applicationIdentifier = null;
        if (component.getApplicationIdentifierExpression() != null)
        {
            applicationIdentifier = JRExpressionUtil.getSimpleExpressionText(
                    component.getApplicationIdentifierExpression());
        }
        //TODO custom default app id

        BarcodeInfo barcodeInfo = new BarcodeInfo();
        barcodeInfo.setType(component.getType());
        barcodeInfo.setCode(code);
        barcodeInfo.setApplicationIdentifier(applicationIdentifier);
        barcodeInfo.setDrawText(component.isDrawText());
        barcodeInfo.setRequiresChecksum(component.isChecksumRequired());
        barcodeInfo.setBarWidth(component.getBarWidth());
        barcodeInfo.setBarHeight(component.getBarHeight());

        Barcode barcode = BarcodeProviders.createBarcode(barcodeInfo);
        BarbecueRendererImpl renderer = new BarbecueRendererImpl(barcode);
        renderer.setRotation(BarbecueStyleResolver.getRotationValue(element));
        image.setRenderer(renderer);
        return image;
    }
    catch (Exception e)
    {
        if (log.isDebugEnabled())
        {
            log.debug("Error while previewing barcode", e);
        }

        return null;
    }

}