Skip to content

Commit

Permalink
when adding harvesting logo, make copies of several formats so that i…
Browse files Browse the repository at this point in the history
…t is easier to get harvest logo in any format
  • Loading branch information
Jesse Eichar committed Dec 4, 2012
1 parent 78af036 commit 022bdd8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class ResourceFilter implements Filter {
private static final int CONTEXT_PATH_PREFIX = "/".length();
private static final int FIVE_DAYS = 60*60*24*5;
private static final int SIX_HOURS = 60*60*6;
private String resourcesDir;
private byte[] defaultImage;
private FilterConfig config;
Expand Down Expand Up @@ -64,7 +64,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
HttpServletResponse httpServletResponse = (HttpServletResponse)response;
// TODO : other type of resources html
httpServletResponse.setContentType("image/"+ext);
httpServletResponse.addHeader("Cache-Control", "max-age="+FIVE_DAYS+", public");
httpServletResponse.addHeader("Cache-Control", "max-age="+SIX_HOURS+", public");
if(filename.equals("logos/favicon.gif")) {
httpServletResponse.setContentLength(favicon.length);

Expand Down
24 changes: 23 additions & 1 deletion web/src/main/java/org/fao/geonet/resources/Resources.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.fao.geonet.resources;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileFilter;
Expand All @@ -11,6 +12,7 @@
import java.util.HashSet;
import java.util.Set;

import javax.imageio.ImageIO;
import javax.servlet.ServletContext;

import jeeves.server.context.ServiceContext;
Expand Down Expand Up @@ -291,14 +293,15 @@ public static void copyLogo(ServiceContext context, String icon,
appDir, icon);

int extIdx = src.getName().lastIndexOf('.');
String extension = src.getName().substring(extIdx);
String extension = src.getName().substring(extIdx).toLowerCase();
des = new File(Resources.locateLogosDir(context), destName
+ extension);

FileInputStream is = new FileInputStream(src);
FileOutputStream os = new FileOutputStream(des);

BinaryFile.copy(is, os, true, true);
copyOtherFormats(context, src, destName);
} catch (IOException e) {
// --- we ignore exceptions here, just log them

Expand All @@ -308,6 +311,25 @@ public static void copyLogo(ServiceContext context, String icon,
}
}

private static void copyOtherFormats(ServiceContext context, File src, String destName) throws IOException {
BufferedImage srcImage = ImageIO.read(src);
String srcSuffix = src.getName().substring(src.getName().lastIndexOf('.')).toLowerCase();
String[] suffixes = ImageIO.getWriterFileSuffixes();
for (int i = 0; i < suffixes.length; i++) {
String suffix = suffixes[i];

if(!srcSuffix.equalsIgnoreCase(suffix) && suffix.length()>0) {
File dest = new File(Resources.locateLogosDir(context), destName + "." + suffix.toLowerCase());
try {
ImageIO.write(srcImage, suffix, dest);
} catch (IOException e) {
// --- we ignore exceptions here, just log them
context.warning("Cannot copy icon to format: "+suffix+" -> " + e.getMessage());
}
}
}
}

// ---------------------------------------------------------------------------
/**
* copy the "unknown" logo to the logos directory for the name
Expand Down

0 comments on commit 022bdd8

Please sign in to comment.