Source Code Cross Referenced for MimeTypesHandling.java in  » Development » ivatamasks » com » ivata » mask » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » ivatamasks » com.ivata.mask.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001 - 2005 ivata limited.
003:         * All rights reserved.
004:         * -----------------------------------------------------------------------------
005:         * ivata masks may be redistributed under the GNU General Public
006:         * License as published by the Free Software Foundation;
007:         * version 2 of the License.
008:         *
009:         * These programs are free software; you can redistribute them and/or
010:         * modify them under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; version 2 of the License.
012:         *
013:         * These programs are distributed in the hope that they will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         *
017:         * See the GNU General Public License in the file LICENSE.txt for more
018:         * details.
019:         *
020:         * If you would like a copy of the GNU General Public License write to
021:         *
022:         * Free Software Foundation, Inc.
023:         * 59 Temple Place - Suite 330
024:         * Boston, MA 02111-1307, USA.
025:         *
026:         *
027:         * To arrange commercial support and licensing, contact ivata at
028:         *                  http://www.ivata.com/contact.jsp
029:         * -----------------------------------------------------------------------------
030:         * $Log: MimeTypesHandling.java,v $
031:         * Revision 1.4  2005/10/02 14:06:32  colinmacleod
032:         * Added/improved log4j logging.
033:         *
034:         * Revision 1.3  2005/04/09 18:04:17  colinmacleod
035:         * Changed copyright text to GPL v2 explicitly.
036:         *
037:         * Revision 1.2  2005/01/06 22:21:45  colinmacleod
038:         * Moved up a version number.
039:         * Changed copyright notices to 2005.
040:         * Updated the documentation:
041:         *   - started working on multiproject:site docu.
042:         *   - changed the logo.
043:         * Added checkstyle and fixed LOADS of style issues.
044:         * Added separate thirdparty subproject.
045:         * Added struts (in web), util and webgui (in webtheme) from ivata op.
046:         *
047:         * Revision 1.4  2004/03/21 21:16:36  colinmacleod
048:         * Shortened name to ivata op.
049:         *
050:         * Revision 1.3  2004/02/10 19:57:25  colinmacleod
051:         * Changed email address.
052:         *
053:         * Revision 1.2  2004/02/01 22:07:32  colinmacleod
054:         * Added full names to author tags
055:         *
056:         * Revision 1.1.1.1  2004/01/27 20:59:46  colinmacleod
057:         * Moved ivata op to SourceForge.
058:         *
059:         * Revision 1.2  2003/10/15 14:13:53  colin
060:         * fixing for XDoclet
061:         *
062:         * Revision 1.9  2003/06/12 09:06:44  peter
063:         * added logic for presentations, oo writer and more spreadsheets
064:         *
065:         * Revision 1.8  2003/06/03 10:42:30  peter
066:         * added rtf type and removed application for unknown starting with application/
067:         *
068:         * Revision 1.7  2003/02/28 17:24:58  peter
069:         * fixed MimeType2Icon, substring check implemented ...
070:         *
071:         * Revision 1.6  2003/02/27 17:25:34  peter
072:         * fixed a bug in MimeType2Image - image mime types
073:         *
074:         * Revision 1.5  2003/02/24 19:27:31  colin
075:         * restructured file paths
076:         * Revision 1.4  2003/02/04 17:43:52  colin
077:         * copyright notice
078:         * Revision 1.3  2002/08/27 15:24:32  peter
079:         * mimeType2Icon Method added
080:         * Revision 1.2  2002/08/15 08:27:04  peter
081:         * modified
082:         * Revision 1.1  2002/08/08 15:03:06  peter
083:         * created
084:         * -----------------------------------------------------------------------------
085:         */
086:        package com.ivata.mask.util;
087:
088:        import org.apache.log4j.Logger;
089:
090:        /**
091:         * <p>
092:         * MimeTypeHandling is a class of static methods for handling MimeTypes. It
093:         * contains methods for getting MimeType information from filenames etc..
094:         * </p>
095:         * <p>
096:         * Don't create an instance of this class; use the static final methods.
097:         * </p>
098:         *
099:         * @since ivata masks 0.4 (2001-12-27)
100:         * @author Peter Illes
101:         * @version $Revision: 1.4 $ /
102:         */
103:        public final class MimeTypesHandling {
104:            /**
105:             * Logger for this class.
106:             */
107:            private static final Logger logger = Logger
108:                    .getLogger(MimeTypesHandling.class);
109:
110:            /**
111:             * /**
112:             * <p>
113:             * This method returns an appropriate mime-icon-image name from a filename
114:             * (or rather from the extension of the file).
115:             * </p>
116:             *
117:             * @param filename
118:             *            a String which is the name of the file.
119:             * @return the full path to the image (in the webapp) representing this
120:             *         file-types
121:             */
122:            public static String fileName2Icon(final String filename) {
123:                if (logger.isDebugEnabled()) {
124:                    logger.debug("fileName2Icon(String filename = " + filename
125:                            + ") - start");
126:                }
127:
128:                String iconDir = "/images/mime/";
129:                String extension;
130:                try {
131:                    extension = (filename
132:                            .substring(filename.lastIndexOf(".") + 1))
133:                            .toLowerCase();
134:                } catch (java.lang.StringIndexOutOfBoundsException e) {
135:                    logger.error("fileName2Icon(String)", e);
136:
137:                    String returnString = iconDir + "file_types_unknown.gif";
138:                    if (logger.isDebugEnabled()) {
139:                        logger
140:                                .debug("fileName2Icon(String) - end - return value = "
141:                                        + returnString);
142:                    }
143:                    return returnString;
144:                }
145:                if (extension.equals("")) {
146:                    String returnString = iconDir + "file_types_unknown.gif";
147:                    if (logger.isDebugEnabled()) {
148:                        logger
149:                                .debug("fileName2Icon(String) - end - return value = "
150:                                        + returnString);
151:                    }
152:                    return returnString;
153:                } else if (extension.equals("txt")) {
154:                    String returnString = iconDir + "file_types_text.gif";
155:                    if (logger.isDebugEnabled()) {
156:                        logger
157:                                .debug("fileName2Icon(String) - end - return value = "
158:                                        + returnString);
159:                    }
160:                    return returnString;
161:                } else if (extension.equals("htm") || extension.equals("html")) {
162:                    String returnString = iconDir + "file_types_html.gif";
163:                    if (logger.isDebugEnabled()) {
164:                        logger
165:                                .debug("fileName2Icon(String) - end - return value = "
166:                                        + returnString);
167:                    }
168:                    return returnString;
169:                } else if (extension.equals("jpg") || extension.equals("jpeg")
170:                        || extension.equals("gif") || extension.equals("bmp")
171:                        || extension.equals("png") || extension.equals("tiff")) {
172:                    String returnString = iconDir + "file_types_image.gif";
173:                    if (logger.isDebugEnabled()) {
174:                        logger
175:                                .debug("fileName2Icon(String) - end - return value = "
176:                                        + returnString);
177:                    }
178:                    return returnString;
179:                } else if (extension.equals("mp3") || extension.equals("wav")
180:                        || extension.equals("m3u") || extension.equals("ogg")) {
181:                    String returnString = iconDir + "file_types_sound.gif";
182:                    if (logger.isDebugEnabled()) {
183:                        logger
184:                                .debug("fileName2Icon(String) - end - return value = "
185:                                        + returnString);
186:                    }
187:                    return returnString;
188:                } else if (extension.equals("mpg") || extension.equals("mpeg")
189:                        || extension.equals("avi") || extension.equals("mov")) {
190:                    String returnString = iconDir + "file_types_video.gif";
191:                    if (logger.isDebugEnabled()) {
192:                        logger
193:                                .debug("fileName2Icon(String) - end - return value = "
194:                                        + returnString);
195:                    }
196:                    return returnString;
197:                } else if (extension.equals("pdf")) {
198:                    String returnString = iconDir + "file_types_pdf.gif";
199:                    if (logger.isDebugEnabled()) {
200:                        logger
201:                                .debug("fileName2Icon(String) - end - return value = "
202:                                        + returnString);
203:                    }
204:                    return returnString;
205:                } else if (extension.equals("ps")) {
206:                    String returnString = iconDir + "file_types_printer.gif";
207:                    if (logger.isDebugEnabled()) {
208:                        logger
209:                                .debug("fileName2Icon(String) - end - return value = "
210:                                        + returnString);
211:                    }
212:                    return returnString;
213:                } else if (extension.equals("zip") || extension.equals("rar")
214:                        || extension.equals("gzip") || extension.equals("tar")) {
215:                    String returnString = iconDir + "file_types_zip.gif";
216:                    if (logger.isDebugEnabled()) {
217:                        logger
218:                                .debug("fileName2Icon(String) - end - return value = "
219:                                        + returnString);
220:                    }
221:                    return returnString;
222:                } else if (extension.equals("doc")) {
223:                    String returnString = iconDir + "file_types_wdoc.gif";
224:                    if (logger.isDebugEnabled()) {
225:                        logger
226:                                .debug("fileName2Icon(String) - end - return value = "
227:                                        + returnString);
228:                    }
229:                    return returnString;
230:                } else if (extension.equals("msg") || extension.equals("eml")) {
231:                    String returnString = iconDir + "file_types_mail.gif";
232:                    if (logger.isDebugEnabled()) {
233:                        logger
234:                                .debug("fileName2Icon(String) - end - return value = "
235:                                        + returnString);
236:                    }
237:                    return returnString;
238:                } else {
239:                    String returnString = iconDir + "file_types_unknown.gif";
240:                    if (logger.isDebugEnabled()) {
241:                        logger
242:                                .debug("fileName2Icon(String) - end - return value = "
243:                                        + returnString);
244:                    }
245:                    return returnString;
246:                }
247:            }
248:
249:            /**
250:             * <p>
251:             * Returns the full path to the appropriate icon for this mime-type that the
252:             * webapp will use.
253:             * </p>
254:             *
255:             * @param mimeType
256:             *            as string
257:             * @return the path to the image for use by webapp
258:             */
259:            public static String mimeType2Icon(final String mimeType) {
260:                if (logger.isDebugEnabled()) {
261:                    logger.debug("mimeType2Icon(String mimeType = " + mimeType
262:                            + ") - start");
263:                }
264:
265:                String iconDir = "/images/mime/";
266:                String iconFileName = null;
267:                String mimeTypeLower = mimeType.toLowerCase();
268:                if (mimeTypeLower.indexOf("text/plain") != -1) {
269:                    iconFileName = "file_types_text.gif";
270:                } else if (mimeTypeLower.indexOf("text/html") != -1) {
271:                    iconFileName = "file_types_html.gif";
272:                } else if (mimeTypeLower.indexOf("text/rtf") != -1
273:                        || mimeTypeLower.indexOf("application/rtf") != -1) {
274:                    iconFileName = "file_types_rtf.gif";
275:                } else if (mimeTypeLower.indexOf("message/") != -1
276:                        || mimeTypeLower.indexOf("multipart/") != -1) {
277:                    iconFileName = "file_types_mail.gif";
278:                } else if (mimeTypeLower.indexOf("image/") != -1) {
279:                    iconFileName = "file_types_image.gif";
280:                } else if (mimeTypeLower.indexOf("audio/") != -1) {
281:                    iconFileName = "file_types_sound.gif";
282:                } else if (mimeTypeLower.indexOf("video/") != -1) {
283:                    iconFileName = "file_types_video.gif";
284:                } else if (mimeTypeLower.indexOf("application/pdf") != -1) {
285:                    iconFileName = "file_types_pdf.gif";
286:                } else if (mimeTypeLower.indexOf("application/postscript") != -1) {
287:                    iconFileName = "file_types_printer.gif";
288:                } else if (mimeTypeLower.indexOf("zip") != -1) {
289:                    iconFileName = "file_types_zip.gif";
290:                } else if (mimeTypeLower.indexOf("application/msword") != -1) {
291:                    iconFileName = "file_types_wdoc.gif";
292:                } else if (mimeTypeLower.indexOf("application/vnd.ms-excel") != -1
293:                        || mimeTypeLower
294:                                .indexOf("application/vnd.stardivision.calc") != -1
295:                        || mimeTypeLower
296:                                .indexOf("application/vnd.sun.xml.calc") != -1) {
297:                    iconFileName = "file_types_spreadsheet.gif";
298:                } else if (mimeTypeLower
299:                        .indexOf("application/vnd.sun.xml.writer") != -1) {
300:                    iconFileName = "file_types_oodoc.gif";
301:                } else if (mimeTypeLower
302:                        .indexOf("application/vnd.stardivision.impress") != -1
303:                        || mimeTypeLower
304:                                .indexOf("application/vnd.sun.xml.impress") != -1
305:                        || mimeTypeLower
306:                                .indexOf("application/vnd.ms-powerpoint") != -1) {
307:                    iconFileName = "file_types_presentation.gif";
308:                }
309:                //if still not set, it's unknown...
310:                if (iconFileName == null) {
311:                    iconFileName = "file_types_unknown.gif";
312:                }
313:                String returnString = iconDir + iconFileName;
314:                if (logger.isDebugEnabled()) {
315:                    logger
316:                            .debug("mimeType2Icon(String) - end - return value = "
317:                                    + returnString);
318:                }
319:                return returnString;
320:            }
321:
322:            /**
323:             * <p>
324:             * Private default constructor ensures utility class functionality.
325:             * </p>
326:             */
327:            private MimeTypesHandling() {
328:            }
329:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.