/** * Set an attribute via a name/value pair. * * @param name * the name of the {@link Attribute} * @param value * the value of the {@link Attribute} */ public void setAttribute( String name, Serializable value ) { setAttribute( new AttributeImpl( name, value ) ); }
@Override public Attribute getAttribute( String name ) { if ( Metacard.THUMBNAIL.equals( name ) ) { return new AttributeImpl( name, this.getThumbnail() ); } else if ( Metacard.METADATA.equals( name ) ) { return new AttributeImpl( name, this.getMetadata() ); } else { return (wrappedMetacard != null) ? wrappedMetacard.getAttribute( name ) : map.get( name ); } }
metadata = sb.toString(); setAttribute( new AttributeImpl( Metacard.METADATA, metadata ) ); } catch ( MalformedURLException e ) { LOGGER.warn( "Cannot read metadata due to Invalid metadata URL[" + metadataURI + "]: " + e.getMessage(), e );
@Override public byte[] getThumbnail() { byte[] thumbnail = null; // We can't call getData here because it will get in an endless loop because of the explicit checks in // getAttribute (for THUMBNAIL), so instead we check the values ourselves then try to pull from the link (on // demand) Attribute thumbnailAttribute = (wrappedMetacard != null) ? wrappedMetacard.getAttribute( THUMBNAIL ) : map.get( THUMBNAIL ); if ( thumbnailAttribute == null || getAttributeValue( thumbnailAttribute, byte[].class ) == null ) { URI thumbnailURI = getThumbnailURL(); if ( thumbnailURI != null ) { try ( InputStream in = thumbnailURI.toURL().openStream() ) { thumbnail = IOUtils.toByteArray( in ); setAttribute( new AttributeImpl( Metacard.THUMBNAIL, thumbnail ) ); } catch ( MalformedURLException e ) { LOGGER.warn( "Cannot read thumbnail due to invalid thumbnail URL[" + thumbnailURI + "]: " + e.getMessage(), e ); } catch ( IOException e ) { LOGGER.warn( "Could not read thumbnail from remote URL[" + thumbnailURI + "] due to: " + e.getMessage(), e ); } } } else { thumbnail = getAttributeValue( thumbnailAttribute, byte[].class ); } return thumbnail; }