KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > datatypes > processors > FileNameProcessor


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.datatypes.processors;
11
12 import org.mmbase.bridge.*;
13 import org.mmbase.util.Casting;
14 import org.apache.commons.fileupload.FileItem;
15
16 /**
17  * Some browers provide directory information (IE on Windows), and {@link
18  * org.apache.commons.fileupload.FileItem#getName()} still includes that. This processors removes
19  * it.
20  *
21  * @author Michiel Meeuwissen
22  * @version $Id: FileNameProcessor.java,v 1.1 2005/12/21 08:23:39 michiel Exp $
23  * @since MMBase-1.8
24  */

25
26 public class FileNameProcessor implements Processor {
27
28     private static final long serialVersionUID = 1L;
29
30     public final Object JavaDoc process(Node node, Field field, Object JavaDoc value) {
31         if (value == null) {
32             return null;
33         } else if (value instanceof FileItem) {
34             value = ((FileItem) value).getName();
35         }
36         String JavaDoc fileName = Casting.toString(value);
37         int pos = fileName.lastIndexOf("\\");
38         if (pos > 0) {
39             fileName = fileName.substring(pos + 1);
40         }
41         pos = fileName.lastIndexOf("/");
42         if (pos > 0) {
43             fileName = fileName.substring(pos + 1);
44         }
45         return fileName;
46     }
47
48     public String JavaDoc toString() {
49         return "FILENAME";
50     }
51 }
52
53
54
Popular Tags