@Test public void testDeserializer() throws Exception { final FileObjectResourceLoader fileObjectResourceLoader = new FileObjectResourceLoader(); final FileObject fileObject = VFS.getManager().resolveFile( Paths.get( "src/test/resources/org/pentaho/reporting/libraries/resourceloader/SVG.svg" ).toAbsolutePath().toString() ); try { fileObjectResourceLoader.deserialize( null, null ); fail( "deserialize of a null string should throw an exception" ); } catch ( IllegalArgumentException iae ) { } try { fileObjectResourceLoader.deserialize( null, "" ); fail( "deserialize of an empty string should throw an exception" ); } catch ( ResourceKeyCreationException rkce ) { } try { fileObjectResourceLoader.deserialize( null, STRING_SERIALIZATION_PREFIX + this.getClass().getName() + ';' + fileObject.getName().getURI() ); fail( "deserialize with an invalid resource class name should throw an exception" ); } catch ( ResourceKeyCreationException rkce ) { } try { fileObjectResourceLoader.deserialize( null, DESERIALIZE_PREFIX + ":/tmp" ); fail( "deserialize with an invalid file should thrown an exception" ); } catch ( ResourceKeyCreationException rkce ) { } final ResourceKey key1 = fileObjectResourceLoader.deserialize( null, DESERIALIZE_PREFIX + ';' + fileObject.getName().getURI() + ";\"\"\"f:this=that\"\":\"\"f:invalid\"\":\"\"f:null=\"\"\"" ); assertNotNull( key1 ); assertTrue( key1.getIdentifier() instanceof FileObject ); assertEquals( FileObjectResourceLoader.class.getName(), key1.getSchema() ); assertEquals( fileObject.getName().getURI(), ( (FileObject) key1.getIdentifier() ).getName().getURI() ); assertEquals( 2, key1.getFactoryParameters().size() ); assertTrue( !key1.getFactoryParameters().containsKey( new FactoryParameterKey( "invalid" ) ) ); assertTrue( key1.getFactoryParameters().containsKey( new FactoryParameterKey( "null" ) ) ); assertNull( key1.getFactoryParameters().get( new FactoryParameterKey( "null" ) ) ); assertEquals( "that", key1.getFactoryParameters().get( new FactoryParameterKey( "this" ) ) ); }
public ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ) throws ResourceKeyCreationException { final ResourceKeyData keyData = ResourceKeyUtils.parse( stringKey ); if ( SCHEMA_NAME.equals( keyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of fileObject key does not contain correct schema" ); } try { final FileObject fileObject = VFS.getManager().resolveFile( keyData.getIdentifier() ); return new ResourceKey( SCHEMA_NAME, fileObject, keyData.getFactoryParameters() ); } catch ( FileSystemException fse ) { throw new ResourceKeyCreationException( "Serialized version of fileObject key does not result into a valid FileObject" ); } }
FileObjectResourceLoader implements ResourceLoader { public ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ) throws ResourceKeyCreationException { final ResourceKeyData keyData = ResourceKeyUtils.parse( stringKey ); if ( SCHEMA_NAME.equals( keyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of fileObject key does not contain correct schema" ); } try { final FileObject fileObject = VFS.getManager().resolveFile( keyData.getIdentifier() ); return new ResourceKey( SCHEMA_NAME, fileObject, keyData.getFactoryParameters() ); } catch ( FileSystemException fse ) { throw new ResourceKeyCreationException( "Serialized version of fileObject key does not result into a valid FileObject" ); } } }
FileObjectResourceLoader implements ResourceLoader { public ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ) throws ResourceKeyCreationException { final ResourceKeyData keyData = ResourceKeyUtils.parse( stringKey ); if ( SCHEMA_NAME.equals( keyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of fileObject key does not contain correct schema" ); } try { final FileObject fileObject = VFS.getManager().resolveFile( keyData.getIdentifier() ); return new ResourceKey( SCHEMA_NAME, fileObject, keyData.getFactoryParameters() ); } catch ( FileSystemException fse ) { throw new ResourceKeyCreationException( "Serialized version of fileObject key does not result into a valid FileObject" ); } } FileObjectResourceLoader(); }
FileObjectResourceLoader implements ResourceLoader { public ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ) throws ResourceKeyCreationException { final ResourceKeyData keyData = ResourceKeyUtils.parse( stringKey ); if ( SCHEMA_NAME.equals( keyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of fileObject key does not contain correct schema" ); } try { final FileObject fileObject = VFS.getManager().resolveFile( keyData.getIdentifier() ); return new ResourceKey( SCHEMA_NAME, fileObject, keyData.getFactoryParameters() ); } catch ( FileSystemException fse ) { throw new ResourceKeyCreationException( "Serialized version of fileObject key does not result into a valid FileObject" ); } } FileObjectResourceLoader(); boolean isSupportedKey( final ResourceKey key ); ResourceKey createKey( final Object value, final Map factoryKeys ); ResourceKey deriveKey( final ResourceKey parent, final String path, final Map factoryKeys ); URL toURL( final ResourceKey key ); ResourceData load( final ResourceKey key ); String serialize( final ResourceKey bundleKey, final ResourceKey key ); ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ); boolean isSupportedDeserializer( final String data ); }
FileObjectResourceLoader implements ResourceLoader { public ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ) throws ResourceKeyCreationException { final ResourceKeyData keyData = ResourceKeyUtils.parse( stringKey ); if ( SCHEMA_NAME.equals( keyData.getSchema() ) == false ) { throw new ResourceKeyCreationException( "Serialized version of fileObject key does not contain correct schema" ); } try { final FileObject fileObject = VFS.getManager().resolveFile( keyData.getIdentifier() ); return new ResourceKey( SCHEMA_NAME, fileObject, keyData.getFactoryParameters() ); } catch ( FileSystemException fse ) { throw new ResourceKeyCreationException( "Serialized version of fileObject key does not result into a valid FileObject" ); } } FileObjectResourceLoader(); boolean isSupportedKey( final ResourceKey key ); ResourceKey createKey( final Object value, final Map factoryKeys ); ResourceKey deriveKey( final ResourceKey parent, final String path, final Map factoryKeys ); URL toURL( final ResourceKey key ); ResourceData load( final ResourceKey key ); String serialize( final ResourceKey bundleKey, final ResourceKey key ); ResourceKey deserialize( final ResourceKey bundleKey, final String stringKey ); boolean isSupportedDeserializer( final String data ); static final String SCHEMA_NAME; }