Java 类net.sf.jasperreports.engine.xml.JRXmlTemplateLoader 实例源码

项目: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;
}
项目:PDFReporter-Studio    文件:ImpStyleTemplate.java   
public File publish(JasperDesign jd, JRReportTemplate img, MReportUnit mrunit, IProgressMonitor monitor, Set<String> fileset, IFile file) throws Exception {
    AFileResource fres = findFile(mrunit, monitor, jd, fileset, getExpression(img), file);
    if (fres != null) {
        JRSimpleTemplate jrt = (JRSimpleTemplate) JRXmlTemplateLoader.load(fres.getFile());
        for (JRTemplateReference r : jrt.getIncludedTemplatesList()) {
            IFile[] fs = root.findFilesForLocationURI(fres.getFile().toURI());
            if (fs != null && fs.length > 0) {
                File ftr = findFile(file, r.getLocation());
                if (ftr != null && ftr.exists()) {
                    fileset.add(ftr.getAbsolutePath());
                    addResource(monitor, mrunit, fileset, ftr, new PublishOptions());
                }
            }
        }
        return fres.getFile();
    }
    return null;
}
项目:PDFReporter-Studio    文件:StyleTemplateFactory.java   
public static void getStylesReference(IFile file, String location, List<JRStyle> list, Set<File> files) {
    if (location == null)
        return;
    File fileToBeOpened = getFile(location, file);
    if (files.contains(fileToBeOpened))
        return;
    if (fileToBeOpened != null && fileToBeOpened.exists() && fileToBeOpened.isFile()) {
        files.add(fileToBeOpened);
        JRSimpleTemplate jrst = (JRSimpleTemplate) JRXmlTemplateLoader.load(fileToBeOpened);
        list.addAll(jrst.getStylesList());
        List<JRTemplateReference> tlist = jrst.getIncludedTemplatesList();
        if (tlist != null && !tlist.isEmpty()) {
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IFile[] fs = root.findFilesForLocationURI(fileToBeOpened.toURI());
            if (fs != null && fs[0] != null)
                for (JRTemplateReference tr : tlist)
                    getStylesReference(fs[0], tr.getLocation(), list, files);
        }
    }
}
项目:PDFReporter-Studio    文件:StyleTemplateFactory.java   
public static void getStylesReference(String absoulteLocation, List<JRStyle> list, Set<File> files) {
    if (absoulteLocation == null)
        return;
    File fileToBeOpened = new File(absoulteLocation);
    if (files.contains(fileToBeOpened))
        return;
    if (fileToBeOpened != null && fileToBeOpened.exists() && fileToBeOpened.isFile()) {
        files.add(fileToBeOpened);
        JRSimpleTemplate jrst = (JRSimpleTemplate) JRXmlTemplateLoader.load(fileToBeOpened);
        list.addAll(jrst.getStylesList());
        List<JRTemplateReference> tlist = jrst.getIncludedTemplatesList();
        if (tlist != null && !tlist.isEmpty()) {
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IFile[] fs = root.findFilesForLocationURI(fileToBeOpened.toURI());
            if (fs != null && fs[0] != null)
                for (JRTemplateReference tr : tlist)
                    getStylesReference(fs[0], tr.getLocation(), list, files);
        }
    }
}
项目: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;
}
项目:PDFReporter-Studio    文件:StyleTemplateFactory.java   
public static void createTemplateReference(ANode parent, String location, int newIndex, Set<String> set,
        boolean editable, IFile file) {
    if (file == null)
        return;
    File fileToBeOpened = getFile(location, file);
    if (fileToBeOpened != null && fileToBeOpened.exists() && fileToBeOpened.isFile()) {
        JRSimpleTemplate jrst = (JRSimpleTemplate) JRXmlTemplateLoader.load(fileToBeOpened);
        createTemplate(parent, set, editable, file, fileToBeOpened, jrst);
    }
}
项目:PDFReporter-Studio    文件:CreateStyleTemplateCommand.java   
private void createObject() {
    if (jrTemplate == null) {
        FilteredResourcesSelectionDialog fd = new FilteredHelpDialog(Display.getCurrent().getActiveShell(),false, ResourcesPlugin.getWorkspace().getRoot(), IResource.FILE);
        fd.setInitialPattern("*.jrtx");//$NON-NLS-1$
        if (fd.open() == Dialog.OK) {
            IFile file = (IFile) fd.getFirstResult();
            File  fileToBeOpened = file.getRawLocation().makeAbsolute().toFile();
            boolean showErrorMessage = false;
            //Check if the file is a valid template before add it to the model
            if (fileToBeOpened != null && fileToBeOpened.exists() && fileToBeOpened.isFile()) {
                try{
                    //Try to load the file to see if it is a valid template
                    JRXmlTemplateLoader.load(fileToBeOpened);
                    this.jrTemplate = MStyleTemplate.createJRTemplate();
                    JRDesignExpression jre = new JRDesignExpression();
                    jre.setText("\"" + getStylePath(file) + "\"");//$NON-NLS-1$ //$NON-NLS-2$
                    ((JRDesignReportTemplate) jrTemplate).setSourceExpression(jre);
                } catch(Exception ex){
                    showErrorMessage = true;
                }
            } else {
                showErrorMessage = true;
            }
            if (showErrorMessage){
                MessageDialog.open(MessageDialog.ERROR, Display.getCurrent().getActiveShell(), Messages.UIUtils_ExceptionTitle, Messages.CreateStyleTemplateCommand_loadStyleError, SWT.NONE);
            }
        }
    }
}
项目: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);
}
项目:ireport-fork    文件:AbstractStyleProperty.java   
List getStyleInTemplate(JRReportTemplate template)
{
    List styleNames = new ArrayList();
    if (template != null)
    {
        String fileNameExp = Misc.getExpressionText(template.getSourceExpression());
        if (fileNameExp != null && fileNameExp.length() > 0)
        {
            ExpressionFileResolver resolver = new ExpressionFileResolver(
                    (JRDesignExpression)template.getSourceExpression(),jasperDesign.getMainDesignDataset(), jasperDesign);

            File f = resolver.resolveFile(null);
            if (f!=null && f.exists())
            {
                try {
                    // try to load this jrtx template...
                    JRSimpleTemplate template2 = (JRSimpleTemplate) JRXmlTemplateLoader.load(new FileInputStream(f));

                    JRStyle[] styles = template2.getStyles();
                    for (int i=0; i<styles.length; ++i)
                    {
                        styleNames.add(new Tag(styles[i].getName(),I18n.getString("property.styleNameReference",  styles[i].getName())));
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
    return styleNames;
}
项目:dynamicreports-jasper    文件:JasperTemplateStyleLoader.java   
public static DRStyle[] loadStyles(String fileName) throws DRException {
    Validate.notNull(fileName, "fileName must not be null");
    try {
        return loadStyles(JRXmlTemplateLoader.load(fileName));
    } catch (JRException e) {
        throw new DRException(e);
    }
}
项目: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    文件: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;
}
项目:dynamicreports-jasper    文件:JasperTemplateStyleLoader.java   
public static DRStyle[] loadStyles(File file) {
    Validate.notNull(file, "file must not be null");
    return loadStyles(JRXmlTemplateLoader.load(file));
}
项目:dynamicreports-jasper    文件:JasperTemplateStyleLoader.java   
public static DRStyle[] loadStyles(InputStream inputStream) {
    Validate.notNull(inputStream, "inputStream must not be null");
    return loadStyles(JRXmlTemplateLoader.load(inputStream));
}
项目:dynamicreports-jasper    文件:JasperTemplateStyleLoader.java   
public static DRStyle[] loadStyles(URL url) {
    Validate.notNull(url, "url must not be null");
    return loadStyles(JRXmlTemplateLoader.load(url));
}