| | */ |
| | private Path exportImage( final String src ) throws Exception { |
| | - Path imageFile = null; |
| | + return getProtocol( src ).isRemote() |
| | + ? downloadImage( src ) |
| | + : resolveImage( src ); |
| | + } |
| | |
| | - final var protocol = getProtocol( src ); |
| | + private Path downloadImage( final String src ) throws Exception { |
| | + final Path imageFile; |
| | |
| | - // Download remote resources into temporary files. |
| | - if( protocol.isRemote() ) { |
| | - try( final var response = httpGet( src ) ) { |
| | - final var mediaType = response.getMediaType(); |
| | + clue( "Main.status.image.xhtml.image.download", src ); |
| | |
| | - imageFile = mediaType.createTempFile( APP_TITLE_LOWERCASE, true ); |
| | + try( final var response = httpGet( src ) ) { |
| | + final var mediaType = response.getMediaType(); |
| | |
| | - try( final var image = response.getInputStream() ) { |
| | - copy( image, imageFile, REPLACE_EXISTING ); |
| | - } |
| | + // Preserve image files if autoclean is turned off. |
| | + imageFile = mediaType.createTempFile( APP_TITLE_LOWERCASE, autoclean() ); |
| | |
| | - // Strip comments, superfluous whitespace, DOCTYPE, and XML |
| | - // declarations. |
| | - if( mediaType.isSvg() ) { |
| | - DocumentParser.sanitize( imageFile ); |
| | - } |
| | + try( final var image = response.getInputStream() ) { |
| | + copy( image, imageFile, REPLACE_EXISTING ); |
| | + } |
| | + |
| | + // Strip comments, superfluous whitespace, DOCTYPE, and XML |
| | + // declarations. |
| | + if( mediaType.isSvg() ) { |
| | + DocumentParser.sanitize( imageFile ); |
| | } |
| | } |
| | - else { |
| | - final var extensions = getImageOrder(); |
| | - var imagePath = getImagePath(); |
| | - var found = false; |
| | |
| | - for( final var extension : extensions ) { |
| | - final var filename = format( |
| | - "%s%s%s", src, extension.isBlank() ? "" : ".", extension ); |
| | - imageFile = Path.of( imagePath, filename ); |
| | + return imageFile; |
| | + } |
| | |
| | - if( imageFile.toFile().exists() ) { |
| | - found = true; |
| | - break; |
| | - } |
| | + private Path resolveImage( final String src ) throws Exception { |
| | + var imagePath = getImagePath(); |
| | + var found = false; |
| | + |
| | + Path imageFile = null; |
| | + |
| | + clue( "Main.status.image.xhtml.image.resolve", src ); |
| | + |
| | + for( final var extension : getImageOrder() ) { |
| | + final var filename = format( |
| | + "%s%s%s", src, extension.isBlank() ? "" : ".", extension ); |
| | + imageFile = Path.of( imagePath, filename ); |
| | + |
| | + if( imageFile.toFile().exists() ) { |
| | + found = true; |
| | + break; |
| | } |
| | + } |
| | |
| | - if( !found ) { |
| | - imagePath = getDocumentDir().toString(); |
| | - imageFile = Path.of( imagePath, src ); |
| | + if( !found ) { |
| | + imagePath = getDocumentDir().toString(); |
| | + imageFile = Path.of( imagePath, src ); |
| | |
| | - if( !imageFile.toFile().exists() ) { |
| | - throw new FileNotFoundException( imageFile.toString() ); |
| | - } |
| | + if( !imageFile.toFile().exists() ) { |
| | + final var filename = imageFile.toString(); |
| | + clue( "Main.status.image.xhtml.image.missing", filename ); |
| | + |
| | + throw new FileNotFoundException( filename ); |
| | } |
| | } |
| | + |
| | + clue( "Main.status.image.xhtml.image.found", imageFile.toString() ); |
| | |
| | return imageFile; |
 |
| | private Locale getLocale() { |
| | return mContext.getLocale(); |
| | + } |
| | + |
| | + private boolean autoclean() { |
| | + return mContext.getAutoClean(); |
| | } |
| | |