Java 类net.sf.jasperreports.engine.JRTemplate 实例源码

项目:jasperreports    文件:JRBaseFiller.java   
protected void collectTemplates() throws JRException
{
    templates = new ArrayList<JRTemplate>();

    if (reportTemplates != null)
    {
        for (JRFillReportTemplate reportTemplate : reportTemplates)
        {
            JRTemplate template = reportTemplate.evaluate();
            if (template != null)
            {
                templates.add(template);
            }
        }
    }

    Collection<JRTemplate> paramTemplates = (Collection<JRTemplate>) mainDataset.getParameterValue(
            JRParameter.REPORT_TEMPLATES, true);
    if (paramTemplates != null)
    {
        templates.addAll(paramTemplates);
    }
}
项目:jasperreports    文件:JRBaseFiller.java   
protected void collectStyles(JRTemplate template, List<JRStyle> externalStyles, 
        Set<String> loadedLocations, Set<String> templateParentLocations) throws JRException
{
    collectIncludedTemplates(template, externalStyles, 
            loadedLocations, templateParentLocations);

    JRStyle[] templateStyles = template.getStyles();
    if (templateStyles != null)
    {
        for (int i = 0; i < templateStyles.length; i++)
        {
            JRStyle style = templateStyles[i];
            String styleName = style.getName();
            if (styleName == null)
            {
                throw 
                    new JRRuntimeException(
                        EXCEPTION_MESSAGE_KEY_EXTERNAL_STYLE_NAME_NOT_SET,  
                        (Object[])null 
                        );
            }

            externalStyles.add(style);
        }
    }
}
项目:jasperreports    文件:JRFillContext.java   
/**
 * Constructs a fill context.
 */
public JRFillContext(BaseReportFiller masterFiller)
{
    this.masterFiller = masterFiller;
    this.jasperReportsContext = masterFiller.getJasperReportsContext();
    this.styledTextUtil = JRStyledTextUtil.getInstance(jasperReportsContext);

    loadedImageRenderers = new HashMap<Object,Renderable>();
    renderersCache = new RenderersCache(jasperReportsContext);
    loadedSubreports = new HashMap<Object,JasperReport>();
    loadedTemplates = new HashMap<Object,JRTemplate>();
    deduplicableRegistry = new DeduplicableRegistry();

    FontUtil.getInstance(jasperReportsContext).resetThreadMissingFontsCache();

    legacyElementStretchEnabled = 
        JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(
            StretchTypeEnum.PROPERTY_LEGACY_ELEMENT_STRETCH_ENABLED
            );

    legacyBandEvaluationEnabled = 
        JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(
            JRCalculator.PROPERTY_LEGACY_BAND_EVALUATION_ENABLED
            );
}
项目:engerek    文件:ReportCreateTaskHandler.java   
private Map<String, Object> prepareReportParameters(ReportType reportType, OperationResult parentResult) {
    Map<String, Object> params = new HashMap<String, Object>();
    if (reportType.getTemplateStyle() != null) {
        byte[] reportTemplateStyleBase64 = reportType.getTemplateStyle();
        byte[] reportTemplateStyle = Base64.decodeBase64(reportTemplateStyleBase64);
        try {
            LOGGER.trace("Style template string {}", new String(reportTemplateStyle));
            InputStream inputStreamJRTX = new ByteArrayInputStream(reportTemplateStyle);
            JRTemplate templateStyle = JRXmlTemplateLoader.load(inputStreamJRTX);
            params.put(PARAMETER_TEMPLATE_STYLES, templateStyle);
            LOGGER.trace("Style template parameter {}", templateStyle);

        } catch (Exception ex) {
            LOGGER.error("Error create style template parameter {}", ex.getMessage());
            throw new SystemException(ex);
        }

    }

    // for our special datasource
    params.put(PARAMETER_REPORT_OID, reportType.getOid());
    params.put(PARAMETER_OPERATION_RESULT, parentResult);
    params.put(ReportService.PARAMETER_REPORT_SERVICE, reportService);

    return params;
}
项目:ireport-fork    文件:JRTXSourceEditor.java   
@Override
public void componentShowing() {
    super.componentShowing();
    JRTemplate template = ((JRTXEditorSupport)cloneableEditorSupport()).getCurrentModel();
    if (template != null && ((JRTXEditorSupport)cloneableEditorSupport()).isModified())
    {
        // Update the content...
        try {
                String content = JRXmlTemplateWriter.writeTemplate(template,"UTF-8");
                getEditorPane().setText(content);
                getEditorPane().setCaretPosition(0);
                ((JRTXVisualView)((JRTXEditorSupport)cloneableEditorSupport()).descriptions[0]).setNeedModelRefresh(false);
        } catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    ((JRTXEditorSupport)cloneableEditorSupport()).setCurrentModel(null);

}
项目:midpoint    文件:ReportCreateTaskHandler.java   
private Map<String, Object> prepareReportParameters(ReportType reportType, OperationResult parentResult) {
    Map<String, Object> params = new HashMap<String, Object>();
    if (reportType.getTemplateStyle() != null) {
        byte[] reportTemplateStyleBase64 = reportType.getTemplateStyle();
        byte[] reportTemplateStyle = Base64.decodeBase64(reportTemplateStyleBase64);
        try {
            LOGGER.trace("Style template string {}", new String(reportTemplateStyle));
            InputStream inputStreamJRTX = new ByteArrayInputStream(reportTemplateStyle);
            JRTemplate templateStyle = JRXmlTemplateLoader.load(inputStreamJRTX);
            params.put(PARAMETER_TEMPLATE_STYLES, templateStyle);
            LOGGER.trace("Style template parameter {}", templateStyle);

        } catch (Exception ex) {
            LOGGER.error("Error create style template parameter {}", ex.getMessage());
            throw new SystemException(ex);
        }

    }

    // for our special datasource
    params.put(PARAMETER_REPORT_OID, reportType.getOid());
    params.put(PARAMETER_OPERATION_RESULT, parentResult);
    params.put(ReportService.PARAMETER_REPORT_SERVICE, reportService);

    return params;
}
项目:midpoint    文件:ReportCreateTaskHandler.java   
private Map<String, Object> prepareReportParameters(ReportType reportType, OperationResult parentResult) {
    Map<String, Object> params = new HashMap<String, Object>();
    if (reportType.getTemplateStyle() != null) {
        byte[] reportTemplateStyleBase64 = reportType.getTemplateStyle();
        byte[] reportTemplateStyle = Base64.decodeBase64(reportTemplateStyleBase64);
        try {
            LOGGER.trace("Style template string {}", new String(reportTemplateStyle));
            InputStream inputStreamJRTX = new ByteArrayInputStream(reportTemplateStyle);
            JRTemplate templateStyle = JRXmlTemplateLoader.load(inputStreamJRTX);
            params.put(PARAMETER_TEMPLATE_STYLES, templateStyle);
            LOGGER.trace("Style template parameter {}", templateStyle);

        } catch (Exception ex) {
            LOGGER.error("Error create style template parameter {}", ex.getMessage());
            throw new SystemException(ex);
        }

    }

    // for our special datasource
    params.put(PARAMETER_REPORT_OID, reportType.getOid());
    params.put(PARAMETER_OPERATION_RESULT, parentResult);
    params.put(ReportService.PARAMETER_REPORT_SERVICE, reportService);

    return params;
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Returns the XML representation of a template.
 * 
 * @param jasperReportsContext
 * @param template the template
 * @param encoding the XML encoding to use
 * @return the XML representation of the template
 */
public static String writeTemplate(JasperReportsContext jasperReportsContext,
        JRTemplate template, String encoding)
{
    StringWriter stringOut = new StringWriter();
    try
    {
        writeTemplate(jasperReportsContext, template, stringOut, encoding);
    }
    catch (IOException e)
    {
        throw new JRRuntimeException(e);
    }
    return stringOut.toString();
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
protected static void writeTemplate(JasperReportsContext jasperReportsContext, 
        JRTemplate template, Writer out, String encoding) throws IOException
{
    JRXmlTemplateWriter writer = new JRXmlTemplateWriter(jasperReportsContext, template, out, encoding);
    writer.write();
    out.flush();
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Creates an XML template writer.
 * 
 * @param jasperReportsContext
 * @param template the template to write
 * @param out the output writer
 * @param encoding the XML encoding to use
 */
public JRXmlTemplateWriter(JasperReportsContext jasperReportsContext, 
        JRTemplate template, Writer out, String encoding)
{
    this.template = template;
    this.encoding = encoding;

    String version = JRPropertiesUtil.getInstance(jasperReportsContext).getProperty(JRXmlBaseWriter.PROPERTY_REPORT_VERSION);
    useWriter(new JRXmlWriteHelper(out), version);
}
项目:jasperreports    文件:JRBaseFiller.java   
protected List<JRStyle> collectTemplateStyles() throws JRException
{
    collectTemplates();

    List<JRStyle> externalStyles = new ArrayList<JRStyle>();
    HashSet<String> loadedLocations = new HashSet<String>();
    for (JRTemplate template : templates)
    {
        collectStyles(template, externalStyles, loadedLocations);
    }
    return externalStyles;
}
项目:jasperreports    文件:JRBaseFiller.java   
protected void collectIncludedTemplates(JRTemplate template, List<JRStyle> externalStyles, 
        Set<String> loadedLocations, Set<String> templateParentLocations) throws JRException
{
    JRTemplateReference[] includedTemplates = template.getIncludedTemplates();
    if (includedTemplates != null)
    {
        for (int i = 0; i < includedTemplates.length; i++)
        {
            JRTemplateReference reference = includedTemplates[i];
            String location = reference.getLocation();

            if (!templateParentLocations.add(location))
            {
                throw 
                    new JRRuntimeException(
                        EXCEPTION_MESSAGE_KEY_CIRCULAR_DEPENDENCY_FOUND,  
                        new Object[]{location} 
                        );
            }

            if (loadedLocations.add(location))
            {
                //template not yet loaded
                JRTemplate includedTemplate = JRFillReportTemplate.loadTemplate(
                        location, this);
                collectStyles(includedTemplate, externalStyles, 
                        loadedLocations, templateParentLocations);

            }
        }
    }
}
项目:PDFReporter-Studio    文件:JRtxEditor.java   
protected void xml2model(InputStream in) {
    JRTemplate jd = JRXmlTemplateLoader.load(in);
    ANode m = new MRoot(null, new JasperDesign());
    IFile file = ((IFileEditorInput) getEditorInput()).getFile();
    MStylesTemplate ms = new MStylesTemplate(m, file);
    ms.setValue(jd);
    ms.setJasperConfiguration(jrContext);
    StyleTemplateFactory.createTemplate(ms, new HashSet<String>(), true, file, file.getLocation().toFile(),
            (JRSimpleTemplate) jd);
    setModel(m);
}
项目:dynamicreports-jasper    文件:JasperTemplateStyleLoader.java   
private static DRStyle[] loadStyles(JRTemplate template) {
    Validate.notNull(template, "template must not be null");
    JRStyle[] jrStyles = template.getStyles();
    DRStyle[] styles = new DRStyle[jrStyles.length];
    for (int i = 0; i < jrStyles.length; i++) {
        JRStyle jrStyle = jrStyles[i];
        styles[i] = convertStyle(jrStyle);
    }
    return styles;
}
项目:jasperreports    文件:ReportConverter.java   
protected void loadTemplateStyles(String location, Set<String> loadedLocations, Set<String> parentLocations)
{
    if (!parentLocations.add(location))
    {
        throw 
            new JRRuntimeException(
                EXCEPTION_MESSAGE_KEY_CIRCULAR_DEPENDENCY_FOUND,  
                new Object[]{location} 
                );
    }

    if (!loadedLocations.add(location))
    {
        //already loaded
        return;
    }

    JRTemplate template;
    try
    {
        template = JRXmlTemplateLoader.getInstance(getJasperReportsContext()).loadTemplate(location);
    }
    catch (Exception e)
    {
        log.warn("Could not load template from location " + location 
                + "; some styles might remain unresolved.");
        return;
    }

    JRTemplateReference[] includedTemplates = template.getIncludedTemplates();
    if (includedTemplates != null)
    {
        for (int i = 0; i < includedTemplates.length; i++)
        {
            JRTemplateReference reference = includedTemplates[i];
            loadTemplateStyles(reference.getLocation(), loadedLocations, parentLocations);
        }
    }

    collectStyles(template.getStyles());
}
项目:jasperreports    文件:JRXmlTemplateLoader.java   
/**
 * @see #loadTemplate(String)
 */
public static JRTemplate load(String location) throws JRException
{
    return getDefaultInstance().loadTemplate(location);
}
项目:jasperreports    文件:JRXmlTemplateLoader.java   
/**
 * @see #loadTemplate(File)
 */
public static JRTemplate load(File file)
{
    return getDefaultInstance().loadTemplate(file);
}
项目:jasperreports    文件:JRXmlTemplateLoader.java   
/**
 * @see #loadTemplate(URL)
 */
public static JRTemplate load(URL url)
{
    return getDefaultInstance().loadTemplate(url);
}
项目:jasperreports    文件:JRXmlTemplateLoader.java   
/**
 * @see #loadTemplate(InputStream)
 */
public static JRTemplate load(InputStream data)
{
    return getDefaultInstance().loadTemplate(data);
}
项目:jasperreports    文件:JRFillReportTemplate.java   
protected static JRTemplate loadTemplate(Object source, JRBaseFiller filler) throws JRException
{
    JRTemplate template;
    if (filler.fillContext.hasLoadedTemplate(source))
    {
        template = filler.fillContext.getLoadedTemplate(source);
    }
    else
    {
        if (log.isDebugEnabled())
        {
            log.debug("Loading styles template from " + source);
        }

        if (source instanceof String)
        {
            template = JRXmlTemplateLoader.getInstance(filler.getJasperReportsContext()).loadTemplate((String) source);
        }
        else if (source instanceof File)
        {
            template = JRXmlTemplateLoader.getInstance(filler.getJasperReportsContext()).loadTemplate((File) source);
        }
        else if (source instanceof URL)
        {
            template = JRXmlTemplateLoader.getInstance(filler.getJasperReportsContext()).loadTemplate((URL) source);
        }
        else if (source instanceof InputStream)
        {
            template = JRXmlTemplateLoader.getInstance(filler.getJasperReportsContext()).loadTemplate((InputStream) source);
        }
        else
        {
            throw 
                new JRRuntimeException(
                    EXCEPTION_MESSAGE_KEY_UNKNOWN_TEMPLATE_SOURCE,  
                    new Object[]{source.getClass().getName()} 
                    );
        }

        filler.fillContext.registerLoadedTemplate(source, template);
    }
    return template;
}
项目:jasperreports    文件:JRBaseFiller.java   
public List<JRTemplate> getTemplates()
{
    return templates;
}
项目:jasperreports    文件:JRBaseFiller.java   
protected void collectStyles(JRTemplate template, List<JRStyle> externalStyles, Set<String> loadedLocations) throws JRException
{
    HashSet<String> parentLocations = new HashSet<String>();
    collectStyles(template, externalStyles, loadedLocations, parentLocations);
}
项目:jasperreports    文件:FillTableSubreport.java   
protected void copyTemplatesParameter(Map<String, Object> parameterValues)
{
    // copy the main report's templates
    List<JRTemplate> templates = filler.getTemplates();
    parameterValues.put(JRParameter.REPORT_TEMPLATES, templates);
}
项目:ireport-fork    文件:JRTXPreviewPanel.java   
public void setPreviewStyle(JRStyle style, JRTemplate template)
{
    // Remove the styles...
     STYLE_REPORT.setDefaultStyle(null);
     STYLE_REPORT.getStylesList().clear();
     STYLE_REPORT.getStylesMap().clear();

    if (style == null)
    {
        jLabelStyleName.setText("No style selected");
        jPanelGraphicElements.repaint();
        jPanelTextElements.repaint();
        setElementsStyle(null);
    }
    else
    {
        jLabelStyleName.setText(style.getName());
        try {
            JRStyle[] styles = template.getStyles();
            for (int i=0; i<styles.length; ++i)
            {
                STYLE_REPORT.addStyle(styles[i]);
                if (styles[i].isDefault()) {
                    STYLE_REPORT.setDefaultStyle(style);
                }
            }

            // The current style has the precedence...
            if (style.isDefault()) {
                STYLE_REPORT.setDefaultStyle(style);
            }
            setElementsStyle(style);
            jPanelGraphicElements.repaint();
            jPanelTextElements.repaint();
        } catch (JRException ex)
        {

        }

    }
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Returns the XML representation of a template.
 * <p/>
 * Uses {@link #DEFAULT_ENCODING the default encoding}.
 * 
 * @param template the template
 * @return the XML representation of the template
 */
public static String writeTemplate(JRTemplate template)
{
    return writeTemplate(template, DEFAULT_ENCODING);
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Returns the XML representation of a template.
 * <p/>
 * Uses {@link #DEFAULT_ENCODING the default encoding}.
 * 
 * @param jasperReportsContext
 * @param template the template
 * @return the XML representation of the template
 */
public static String writeTemplate(JasperReportsContext jasperReportsContext, JRTemplate template)
{
    return writeTemplate(jasperReportsContext, template, DEFAULT_ENCODING);
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Returns the XML representation of a template.
 * 
 * @param template the template
 * @param encoding the XML encoding to use
 * @return the XML representation of the template
 */
public static String writeTemplate(JRTemplate template, String encoding)
{
    return writeTemplate(DefaultJasperReportsContext.getInstance(), template, encoding);
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Writes the XML representation of a template to an output stream.
 * <p/>
 * Uses {@link #DEFAULT_ENCODING the default encoding}.
 * 
 * @param template the template
 * @param out the output stream
 */
public static void writeTemplate(JRTemplate template, OutputStream out)
{
    writeTemplate(template, out, DEFAULT_ENCODING);
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Writes the XML representation of a template to an output stream.
 * <p/>
 * Uses {@link #DEFAULT_ENCODING the default encoding}.
 * 
 * @param jasperReportsContext
 * @param template the template
 * @param out the output stream
 */
public static void writeTemplate(JasperReportsContext jasperReportsContext,
        JRTemplate template, OutputStream out)
{
    writeTemplate(jasperReportsContext, template, out, DEFAULT_ENCODING);
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Writes the XML representation of a template to an output stream.
 * 
 * @param template the template
 * @param out the output stream
 * @param encoding the XML encoding to use
 */
public static void writeTemplate(JRTemplate template, OutputStream out, String encoding)
{
    writeTemplate(DefaultJasperReportsContext.getInstance(), template, out, encoding);
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Writes the XML representation of a template to a file.
 * <p/>
 * Uses {@link #DEFAULT_ENCODING the default encoding}.
 * 
 * @param template the template
 * @param outputFile the output file name
 */
public static void writeTemplateToFile(JRTemplate template, String outputFile)
{
    writeTemplateToFile(template, outputFile, DEFAULT_ENCODING);
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Writes the XML representation of a template to a file.
 * <p/>
 * Uses {@link #DEFAULT_ENCODING the default encoding}.
 * 
 * @param jasperReportsContext
 * @param template the template
 * @param outputFile the output file name
 */
public static void writeTemplateToFile(JasperReportsContext jasperReportsContext, 
        JRTemplate template, String outputFile)
{
    writeTemplateToFile(jasperReportsContext, template, outputFile, DEFAULT_ENCODING);
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Writes the XML representation of a template to a file.
 * 
 * @param template the template
 * @param outputFile the output file name
 * @param encoding the XML encoding to use
 */
public static void writeTemplateToFile(JRTemplate template, String outputFile, String encoding)
{
    writeTemplateToFile(DefaultJasperReportsContext.getInstance(), 
            template, outputFile, encoding);
}
项目:jasperreports    文件:JRXmlTemplateWriter.java   
/**
 * Creates an XML template writer.
 * 
 * @param template the template to write
 * @param out the output writer
 * @param encoding the XML encoding to use
 */
public JRXmlTemplateWriter(JRTemplate template, Writer out, String encoding)
{
    this(DefaultJasperReportsContext.getInstance(), template, out, encoding);
}
项目:jasperreports    文件:JRXmlTemplateLoader.java   
/**
 * Parses a template XML found at a specified location into a {@link JRTemplate template object}.
 * 
 * @param location the template XML location.
 *  Can be a URL, a file path or a classloader resource name.
 * @return the template object
 * @throws JRException when the location cannot be resolved or read
 * @see RepositoryUtil#getBytesFromLocation(String)
 */
public JRTemplate loadTemplate(String location) throws JRException
{
    byte[] data = RepositoryUtil.getInstance(jasperReportsContext).getBytesFromLocation(location);
    return load(new ByteArrayInputStream(data));
}
项目:jasperreports    文件:JRFillContext.java   
/**
 * Gets a cached template.
 * 
 * @param source the source of the templage
 * @return the cached templage
 * @see #registerLoadedTemplate(Object, JRTemplate)
 */
public JRTemplate getLoadedTemplate(Object source)
{
    return loadedTemplates.get(source); 
}
项目:jasperreports    文件:JRFillContext.java   
/**
 * Registers a template loaded from a source.
 * <p>
 * The template is cached for further use.
 * 
 * @param source the source that was used to load the template
 * @param template the loaded templage
 * @see #getLoadedTemplate(Object)
 */
public void registerLoadedTemplate(Object source, JRTemplate template)
{
    loadedTemplates.put(source, template);
}