From de7b3835a635856113dd84ddaeb64ec2d3e7a9ad Mon Sep 17 00:00:00 2001 From: Koda Date: Fri, 20 Jan 2017 20:18:00 +0900 Subject: [PATCH] #588 Set file type icon --- gulpfile.js | 8 ++++- .../knowledge/logic/UploadedFileLogic.java | 35 +++++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index d0d0bc302..913e59553 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -22,7 +22,7 @@ gulp.task('min', function() { }); gulp.task('copy', ['copy:bootswatch', 'copy:highlightjs', 'copy:font-awesome', 'copy:flag-icon-css', - 'copy:html5shiv', 'copy:respond', 'copy:MathJax', 'copy:emoji-parser']); + 'copy:html5shiv', 'copy:respond', 'copy:MathJax', 'copy:emoji-parser', 'copy:free-file-icons']); gulp.task('copy:bootswatch', function() { return gulp.src([ 'src/main/webapp/bower/bootswatch/**/*' @@ -72,6 +72,12 @@ gulp.task('copy:emoji-parser', function() { ]) .pipe(gulp.dest('target/knowledge/bower/emoji-parser')); }); +gulp.task('copy:free-file-icons', function() { + return gulp.src([ + 'src/main/webapp/bower/teambox.free-file-icons/**/*' + ]) + .pipe(gulp.dest('target/knowledge/bower/teambox.free-file-icons')); +}); gulp.task('default', ['min', 'copy']); diff --git a/src/main/java/org/support/project/knowledge/logic/UploadedFileLogic.java b/src/main/java/org/support/project/knowledge/logic/UploadedFileLogic.java index fa907dfe3..fee14e083 100644 --- a/src/main/java/org/support/project/knowledge/logic/UploadedFileLogic.java +++ b/src/main/java/org/support/project/knowledge/logic/UploadedFileLogic.java @@ -34,7 +34,17 @@ public class UploadedFileLogic { public static UploadedFileLogic get() { return Container.getComp(UploadedFileLogic.class); } - + + /** アイコン画像の種類 */ + public static final String[] ICONS = { "_blank", "_page", "aac", "ai", "aiff", "avi", "bmp", "c", "cpp", + "css", "dat", "dmg", "doc", "dotx", "dwg", "dxf", "eps", "exe", "flv", "gif", "h", + "hpp", "html", "ics", "iso", "java", "jpg", "js", "key", "less", "mid", "mp3", "mp4", + "mpg", "odf", "ods", "odt", "otp", "ots", "ott", "pdf", "php", "png", "ppt", "psd", + "py", "qt", "rar", "rb", "rtf", "sass", "scss", "sql", "tga", "tgz", "tiff", "txt", + "wav", "xls", "xlsx", "xml", "yml", "zip" }; + + + /** * ファイルを保存する * @@ -70,19 +80,24 @@ public UploadFile convUploadFile(String context, KnowledgeFilesEntity entity) { UploadFile file = new UploadFile(); file.setFileNo(entity.getFileNo()); file.setUrl(context + "/open.file/download?fileNo=" + entity.getFileNo()); - // file.setThumbnailUrl(context + "/open.file/thumbnai?fileNo=" + entity.getFileNo()); - file.setThumbnailUrl(context + "/bower/teambox.free-file-icons/32px/_blank.png"); file.setName(entity.getFileName()); - //file.setType("-"); + String thumbnai = context + "/bower/teambox.free-file-icons/16px/_blank.png"; String extention = StringUtils.getExtension(entity.getFileName()); - if (StringUtils.contains(extention, ".png", ".jpg", ".jpeg", ".gif", ".bmp")) { - file.setType("image"); - } else if (StringUtils.contains(extention, ".pdf", ".pptx")) { - file.setType("slide"); - } else { - file.setType("file"); + if (StringUtils.isNotEmpty(extention)) { + extention = extention.substring(1); // 先頭の「.」を削除 + if (StringUtils.contains(extention, "png", "jpg", "jpeg", "gif", "bmp")) { + file.setType("image"); + } else if (StringUtils.contains(extention, "pdf", "pptx")) { + file.setType("slide"); + } else { + file.setType("file"); + } + if (StringUtils.contains(extention, ICONS)) { + thumbnai = context + "/bower/teambox.free-file-icons/16px/" + extention + ".png"; + } } + file.setThumbnailUrl(thumbnai); file.setSize(entity.getFileSize()); file.setDeleteUrl(context + "/protect.file/delete?fileNo=" + entity.getFileNo());