public static MasterReport createReport(final Serializable fileId) throws ResourceException, IOException { final ResourceManager resourceManager = new ResourceManager(); resourceManager.registerDefaults(); final HashMap helperObjects = new HashMap(); // add the runtime context so that PentahoResourceData class can get access // to the solution repo ResourceKey key = null; IUnifiedRepository unifiedRepository = PentahoSystem.get(IUnifiedRepository.class, PentahoSessionHolder.getSession()); RepositoryFile repositoryFile = unifiedRepository.getFileById(fileId); if (repositoryFile != null) { key = resourceManager.createKey( RepositoryResourceLoader.SOLUTION_SCHEMA_NAME + RepositoryResourceLoader.SCHEMA_SEPARATOR + repositoryFile.getPath(), helperObjects); } else { key = resourceManager.createKey( RepositoryResourceLoader.SOLUTION_SCHEMA_NAME + RepositoryResourceLoader.SCHEMA_SEPARATOR + fileId, helperObjects); } final Resource resource = resourceManager.create(key, null, MasterReport.class); return (MasterReport) resource.getResource(); }
/** * Parses an external file using LibLoader and returns the parsed result as an object of type * <code>targetClass</code>. The file is given as relative pathname (relative to the current * source file). The current helper-methods are used as parse-parameters for the external parsing. * * @param file the file to be parsed. * @param targetClass the target type of the parse operation. * @param map the map of parse parameters. * @return the result, never null. * @throws ParseException if parsing the result failed for some reason. * @throws ResourceLoadingException if there was an IO error loading the resource. * @see #deriveParseParameters() */ protected Object performExternalParsing(final String file, final Class targetClass, final Map map) throws ParseException, ResourceLoadingException { try { final ResourceManager resourceManager = rootHandler.getResourceManager(); final ResourceKey source = rootHandler.getSource(); final ResourceKey target = resourceManager.deriveKey(source, file, map); final DependencyCollector dc = rootHandler.getDependencyCollector(); final Resource resource = resourceManager.create(target, rootHandler.getContext(), targetClass); dc.add(resource); return resource.getResource(); } catch (ResourceLoadingException rle) { throw rle; } catch (ResourceException e) { throw new ParseException("Failure while loading data: " + file, e, getLocator()); } }
/** * Helperfunction to extract an image from an imagereference. If the image is contained as * java.awt.Image object only, the image is recoded into an PNG-Image. * * @param reference the image reference. * @return an image. * @throws com.lowagie.text.DocumentException if no PDFImageElement could be created using the * given ImageReference. * @throws java.io.IOException if the image could not be read. */ public Image getImage(final ImageContainer reference) throws DocumentException, IOException { if (reference == null) { throw new NullPointerException(); } Object identity = null; java.awt.Image image = null; if (reference instanceof URLImageContainer) { final URLImageContainer urlImageContainer = (URLImageContainer) reference; final ResourceKey url = urlImageContainer.getResourceKey(); if (url != null && urlImageContainer.isLoadable()) { identity = url; final Image cached = (Image) cachedImages.get(identity); if (cached != null) { return cached; } try { final ResourceData resourceData = resourceManager.load(url); final byte[] data = resourceData.getResource(resourceManager); final Image itextimage = Image.getInstance(data); cachedImages.put(identity, itextimage); return itextimage; } catch (ResourceException re) { RTFImageCache.logger.info("Caught illegal Image, will recode to PNG instead", re); } catch (BadElementException be) { RTFImageCache.logger.info("Caught illegal Image, will recode to PNG instead", be); } catch (IOException ioe) { RTFImageCache.logger.info( "Unable to read the raw-data, will try to recode image-data.", ioe); } try { final Resource resource = resourceManager.create(url, null, Image.class); image = (java.awt.Image) resource.getResource(); } catch (ResourceException re) { RTFImageCache.logger.info("Caught illegal Image, will try to find local instance", re); } } } if (reference instanceof LocalImageContainer && image == null) { final LocalImageContainer localImageContainer = (LocalImageContainer) reference; image = localImageContainer.getImage(); if (image != null) { // check, if the content was cached ... identity = localImageContainer.getIdentity(); if (identity != null) { final Image cachedImage = (Image) cachedImages.get(identity); if (cachedImage != null) { return cachedImage; } } } } if (image == null) { return null; } final WaitingImageObserver obs = new WaitingImageObserver(image); obs.waitImageLoaded(); try { final byte[] data = RenderUtility.encodeImage(image); final Image itextimage = Image.getInstance(data); if (identity != null) { cachedImages.put(identity, itextimage); } return itextimage; } catch (UnsupportedEncoderException uee) { logger.warn("Assertation-Failure: PNG encoding failed.", uee); return null; } }
protected void drawReplacedContent(final RenderableReplacedContentBox content) { final Graphics2D g2 = getGraphics(); final Object o = content.getContent().getRawObject(); if (o instanceof DrawableWrapper) { final DrawableWrapper drawableWrapper = (DrawableWrapper) o; if (drawDrawable(content, g2, drawableWrapper)) { drawImageMap(content); } return; } if (o instanceof Image) { if (drawImage(content, (Image) o)) { drawImageMap(content); } return; } if (o instanceof URLImageContainer) { final URLImageContainer imageContainer = (URLImageContainer) o; if (imageContainer.isLoadable() == false) { PdfLogicalPageDrawable.logger.info( "URL-image cannot be rendered, as it was declared to be not loadable: " + imageContainer.getSourceURLString()); } else { final ResourceKey resource = imageContainer.getResourceKey(); if (resource == null) { PdfLogicalPageDrawable.logger.info( "URL-image cannot be rendered, as it did not return a valid URL."); } else { try { final ResourceManager resourceManager = getResourceManager(); final com.lowagie.text.Image instance; final com.lowagie.text.Image maybeImage = imageCache.get(resource); if (maybeImage != null) { instance = maybeImage; } else { final ResourceData data = resourceManager.load(resource); instance = com.lowagie.text.Image.getInstance(data.getResource(resourceManager)); imageCache.put(resource, instance); } final Resource imageWrapped = resourceManager.create(resource, null, Image.class); final Image image = (Image) imageWrapped.getResource(); if (drawImage(content, image, instance)) { drawImageMap(content); } return; } catch (InvalidReportStateException re) { throw re; } catch (Exception e) { PdfLogicalPageDrawable.logger.info( "URL-image cannot be rendered, as the image was not loadable.", e); } } } } if (o instanceof LocalImageContainer) { final LocalImageContainer imageContainer = (LocalImageContainer) o; final Image image = imageContainer.getImage(); if (drawImage(content, image)) { drawImageMap(content); } } else { PdfLogicalPageDrawable.logger.debug("Unable to handle " + o); } }