Java Code Examples for org.pentaho.reporting.libraries.resourceloader.ResourceManager#load()

The following examples show how to use org.pentaho.reporting.libraries.resourceloader.ResourceManager#load() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractElementReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ResourceKey localizeKey( final ResourceManager resourceManager, final ResourceKey valueKey ) {
  final Object object = valueKey.getFactoryParameters().get( ClassicEngineFactoryParameters.EMBED );
  if ( "false".equals( object ) ) {
    return valueKey;
  }
  if ( "org.pentaho.reporting.libraries.docbundle.bundleloader.RepositoryResourceBundleLoader".equals( valueKey
      .getSchema() ) == false
      && object == null ) {
    return valueKey;
  }

  try {
    final ResourceData resourceData = resourceManager.load( valueKey );
    final byte[] resource = resourceData.getResource( resourceManager );
    return resourceManager.createKey( resource, valueKey.getFactoryParameters() );
  } catch ( ResourceException e ) {
    if ( logger.isDebugEnabled() ) {
      logger.info( "Unable to normalize embedded resource-key, using ordinary key-object instead.", e );
    } else {
      logger.info( "Unable to normalize embedded resource-key, using ordinary key-object instead." );
    }
  }
  return valueKey;
}
 
Example 2
Source File: ZipEntryKey.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ZipEntryKey( final ResourceManager manager,
                    final String zipFile,
                    final String entryName )
  throws ResourceKeyCreationException, ResourceLoadingException {
  if ( zipFile == null ) {
    throw new NullPointerException();
  }
  if ( entryName == null ) {
    throw new NullPointerException();
  }
  this.zipFile = manager.load( manager.createKey( zipFile ) );
  this.entryName = entryName;
}
 
Example 3
Source File: ZipEntryKey.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ZipEntryKey( final ResourceManager manager,
                    final URL zipFile,
                    final String entryName )
  throws ResourceKeyCreationException, ResourceLoadingException {
  if ( zipFile == null ) {
    throw new NullPointerException();
  }
  if ( entryName == null ) {
    throw new NullPointerException();
  }
  this.zipFile = manager.load( manager.createKey( zipFile ) );
  this.entryName = entryName;
}
 
Example 4
Source File: ZipEntryKey.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public ZipEntryKey( final ResourceManager manager,
                    final File zipFile,
                    final String entryName )
  throws ResourceKeyCreationException, ResourceLoadingException {
  if ( zipFile == null ) {
    throw new NullPointerException();
  }
  if ( entryName == null ) {
    throw new NullPointerException();
  }
  this.zipFile = manager.load( manager.createKey( zipFile ) );
  this.entryName = entryName;
}
 
Example 5
Source File: ZipResourceData.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public InputStream getResourceAsStream( final ResourceManager caller ) throws ResourceLoadingException {
  // again, this is going to hurt the performance.
  final ResourceKey parentKey = key.getParent();
  final ResourceData data = caller.load( parentKey );

  final ZipInputStream zin = new ZipInputStream( data.getResourceAsStream( caller ) );
  try {
    try {
      ZipEntry zipEntry = zin.getNextEntry();
      while ( zipEntry != null ) {
        if ( zipEntry.getName().equals( key.getIdentifier() ) == false ) {
          zipEntry = zin.getNextEntry();
          continue;
        }
        // read from here ..
        return zin;
      }
    } finally {
      zin.close();
    }
  } catch ( IOException e ) {
    throw new ResourceLoadingException
      ( "Reading the zip-file failed.", e );
  }
  throw new ResourceLoadingException
    ( "The zip-file did not contain the specified entry" );
}
 
Example 6
Source File: BundleUtilities.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void copyInto( final WriteableDocumentBundle bundle,
                             final String targetPath,
                             final ResourceKey dataKey,
                             final ResourceManager resourceManager )
  throws IOException, ResourceLoadingException {
  if ( bundle == null ) {
    throw new NullPointerException();
  }
  if ( targetPath == null ) {
    throw new NullPointerException();
  }
  if ( resourceManager == null ) {
    throw new NullPointerException();
  }
  if ( dataKey == null ) {
    throw new NullPointerException();
  }

  final ResourceData resourceData = resourceManager.load( dataKey );
  String contentType = (String) resourceData.getAttribute( ResourceData.CONTENT_TYPE );
  if ( contentType == null ) {
    contentType = "application/octet-stream";
  }

  final InputStream stream = resourceData.getResourceAsStream( resourceManager );
  try {
    final OutputStream outStream = bundle.createEntry( targetPath, contentType );
    try {
      IOUtils.getInstance().copyStreams( stream, outStream );
    } finally {
      outStream.close();
    }
  } finally {
    stream.close();
  }
}
 
Example 7
Source File: KettleEmbeddedTransReadHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
private byte[] loadDataFromBundle( final String href ) throws ResourceKeyCreationException, ResourceLoadingException {
  final ResourceKey key = getRootHandler().getSource();
  final ResourceManager manager = getRootHandler().getResourceManager();
  final ResourceKey derivedKey = manager.deriveKey( key, href );
  final ResourceData data = manager.load( derivedKey );
  return data.getResource( manager );
}
 
Example 8
Source File: PdfImageHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Image createImage( URLImageContainer imageContainer ) {
  if ( !imageContainer.isLoadable() ) {
    logger.info( "URL-image cannot be rendered, as it was declared to be not loadable: "
        + imageContainer.getSourceURLString() );
    return null;
  }

  final ResourceKey resource = imageContainer.getResourceKey();
  if ( resource == null ) {
    logger.info( "URL-image cannot be rendered, as it did not return a valid URL." );
    return null;
  }

  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 );
    }
    return instance;
  } catch ( InvalidReportStateException re ) {
    throw re;
  } catch ( Exception e ) {
    logger.info( "URL-image cannot be rendered, as the image was not loadable.", e );
  }

  return null;
}
 
Example 9
Source File: ZipResourceData.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
public long getVersion( final ResourceManager caller )
  throws ResourceLoadingException {
  final ResourceKey parentKey = key.getParent();
  final ResourceData data = caller.load( parentKey );
  return data.getVersion( caller );
}
 
Example 10
Source File: AbstractFontFileRegistry.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void loadFromCache( final String encoding, final String filename ) {
  final ResourceManager resourceManager = new ResourceManager();
  final File location = createStorageLocation();
  if ( location == null ) {
    return;
  }
  final File ttfCache = new File( location, filename );
  try {
    final ResourceKey resourceKey = resourceManager.createKey( ttfCache );
    final ResourceData data = resourceManager.load( resourceKey );
    final InputStream stream = data.getResourceAsStream( resourceManager );

    final HashMap<String, FontFileRecord> cachedSeenFiles;
    final HashMap<String, DefaultFontFamily> cachedFontFamilies;
    final HashMap<String, DefaultFontFamily> cachedFullFontNames;
    final HashMap<String, DefaultFontFamily> cachedAlternateNames;

    try {
      final ObjectInputStream oin = new ObjectInputStream( stream );
      final Object[] cache = (Object[]) oin.readObject();
      if ( cache.length != 5 ) {
        return;
      }
      if ( ObjectUtilities.equal( encoding, cache[ 0 ] ) == false ) {
        return;
      }
      cachedSeenFiles = (HashMap<String, FontFileRecord>) cache[ 1 ];
      cachedFontFamilies = (HashMap<String, DefaultFontFamily>) cache[ 2 ];
      cachedFullFontNames = (HashMap<String, DefaultFontFamily>) cache[ 3 ];
      cachedAlternateNames = (HashMap<String, DefaultFontFamily>) cache[ 4 ];
    } finally {
      stream.close();
    }

    // next; check the font-cache for validity. We cannot cleanly remove
    // entries from the cache once they become invalid, so we have to rebuild
    // the cache from scratch, if it is invalid.
    //
    // This should not matter that much, as font installations do not happen
    // every day.
    if ( isCacheValid( cachedSeenFiles ) ) {
      this.getSeenFiles().putAll( cachedSeenFiles );
      populateFromCache( cachedFontFamilies, cachedFullFontNames, cachedAlternateNames );
    }
  } catch ( final ClassNotFoundException cnfe ) {
    // ignore the exception.
    logger.debug( "Failed to restore the cache: Cache was created by a different version of LibFonts" );
  } catch ( Exception e ) {
    logger.debug( "Non-Fatal: Failed to restore the cache. The cache will be rebuilt.", e );
  }
}