Search in sources :

Example 1 with PersistenceUtil

use of net.sf.jasperreports.repo.PersistenceUtil in project mapfish-print by mapfish.

the class MapfishPrintRepositoryService method getResource.

@Override
public <K extends Resource> K getResource(final String uri, final Class<K> resourceType) {
    try {
        if (resourceType.isAssignableFrom(InputStreamResource.class)) {
            final InputStream inputStream = getInputStream(uri);
            if (inputStream != null) {
                final InputStreamResource resource = new InputStreamResource();
                resource.setInputStream(inputStream);
                return resourceType.cast(resource);
            }
        }
        final PersistenceUtil persistenceUtil = PersistenceUtil.getInstance(this.jasperReportsContext);
        PersistenceService persistenceService = persistenceUtil.getService(FileRepositoryService.class, resourceType);
        if (persistenceService != null) {
            return resourceType.cast(persistenceService.load(uri, this));
        }
    } catch (IllegalStateException e) {
        LOGGER.info("Resource not found {} ({}).", uri, e.toString());
    } catch (Exception e) {
        LOGGER.trace("Error on getting resource {}", uri, e);
    }
    return null;
}
Also used : PersistenceService(net.sf.jasperreports.repo.PersistenceService) PersistenceUtil(net.sf.jasperreports.repo.PersistenceUtil) InputStream(java.io.InputStream) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) InputStreamResource(net.sf.jasperreports.repo.InputStreamResource)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 InputStreamResource (net.sf.jasperreports.repo.InputStreamResource)1 PersistenceService (net.sf.jasperreports.repo.PersistenceService)1 PersistenceUtil (net.sf.jasperreports.repo.PersistenceUtil)1