Source Code Cross Referenced for FileListing.java in  » Workflow-Engines » Dalma » com » sun » jbi » common » 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 » Workflow Engines » Dalma » com.sun.jbi.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (c) 2004 Sun Microsystems Inc., All Rights Reserved.
002:
003:        /*
004:         * FileListing.java
005:         *
006:         * SUN PROPRIETARY/CONFIDENTIAL.
007:         * This software is the proprietary information of Sun Microsystems, Inc.
008:         * Use is subject to license terms.
009:         *
010:         */
011:        package com.sun.jbi.common;
012:
013:        import java.io.File;
014:        import java.io.FilenameFilter;
015:
016:        import java.util.ArrayList;
017:        import java.util.Arrays;
018:        import java.util.Iterator;
019:        import java.util.List;
020:        import java.util.logging.Logger;
021:
022:        /**
023:         * Helper class for listing files / folders.
024:         *
025:         * @author Ramesh
026:         */
027:        public final class FileListing {
028:            /**
029:             * Flag to indicate recursive listing.
030:             */
031:            private static boolean sRecurse = false;
032:
033:            /**
034:             * Filter class to be used.
035:             */
036:            private static FilenameFilter sFilter = null;
037:
038:            /**
039:             * Logger object.
040:             */
041:            private static Logger sLog = Logger
042:                    .getLogger("com.sun.jbi.binding.file.util");
043:
044:            /**
045:             * Gets the list of files in a folder.
046:             *
047:             * @param aDir folder name.
048:             * @param bRecurse will recurse if true.
049:             * @param aFilter filname filter.
050:             *
051:             * @return List of file names.
052:             */
053:            public static synchronized List getFileListing(File aDir,
054:                    boolean bRecurse, FilenameFilter aFilter) {
055:                sRecurse = bRecurse;
056:                sFilter = aFilter;
057:
058:                if ((aDir == null) || (aDir.getName().trim().equals(""))) {
059:                    sLog.severe("Directory is null");
060:
061:                    return null;
062:                }
063:
064:                return getListing(aDir);
065:            }
066:
067:            public static String getXMLFile(String path) {
068:                InputFileFilter myFilter = new InputFileFilter();
069:                myFilter.setFilterexpression(".*\\.xml");
070:                sFilter = myFilter;
071:                String xmlfile = null;
072:                try {
073:                    xmlfile = ((File) getListing(new File(path)).get(0))
074:                            .getAbsolutePath();
075:                } catch (Exception e) {
076:                    ;
077:                }
078:                sFilter = null;
079:                return xmlfile;
080:
081:            }
082:
083:            public static String getWSDLFile(String path) {
084:                InputFileFilter myFilter = new InputFileFilter();
085:                myFilter.setFilterexpression(".*\\.wsdl");
086:                sFilter = myFilter;
087:                String xmlfile = null;
088:                try {
089:                    xmlfile = ((File) getListing(new File(path)).get(0))
090:                            .getAbsolutePath();
091:                } catch (Exception e) {
092:                    ;
093:                }
094:
095:                sFilter = null;
096:
097:                return xmlfile;
098:
099:            }
100:
101:            /**
102:             * Recursively walk a directory tree and return a List of all Files found;
103:             * the List is sorted using File.compareTo.
104:             *
105:             * @param aDir is a valid directory, which can be read.
106:             *
107:             * @return array of folder names
108:             */
109:            public static synchronized String[] getFolderListing(File aDir) {
110:                File[] dirs = aDir.listFiles();
111:
112:                if (dirs == null) {
113:                    return null;
114:                }
115:
116:                List filesDirs = Arrays.asList(dirs);
117:
118:                if (filesDirs == null) {
119:                    return null;
120:                }
121:
122:                Iterator filesIter = filesDirs.iterator();
123:                String[] result = new String[filesDirs.size()];
124:                File file = null;
125:                int counter = 0;
126:
127:                while (filesIter.hasNext()) {
128:                    file = (File) filesIter.next();
129:
130:                    if (!file.isFile()) {
131:                        result[counter] = file.getAbsolutePath();
132:                        counter++;
133:                    }
134:                }
135:
136:                return result;
137:            }
138:
139:            /**
140:             * Util method to get the list of folders.
141:             *
142:             * @param aDir folder name for which contents have to be listed.
143:             *
144:             * @return array of folder names.
145:             */
146:            public static synchronized String[] getFolderNameListing(File aDir) {
147:                File[] dirs = aDir.listFiles();
148:
149:                if (dirs == null) {
150:                    return null;
151:                }
152:
153:                List filesDirs = Arrays.asList(dirs);
154:
155:                if (filesDirs == null) {
156:                    return null;
157:                }
158:
159:                Iterator filesIter = filesDirs.iterator();
160:                String[] result = new String[filesDirs.size()];
161:                File file = null;
162:                int counter = 0;
163:
164:                while (filesIter.hasNext()) {
165:                    file = (File) filesIter.next();
166:
167:                    if (!file.isFile()) {
168:                        result[counter] = file.getName();
169:                        counter++;
170:                    }
171:                }
172:
173:                return result;
174:            }
175:
176:            /**
177:             * Recursively walk a directory tree and return a List of all Files found;
178:             * the List is sorted using File.compareTo.
179:             *
180:             * @param aDir is a valid directory, which can be read.
181:             *
182:             * @return list of files.
183:             */
184:            private static List getListing(File aDir) {
185:                List result = new ArrayList();
186:                File[] filesAndDirs = aDir.listFiles(sFilter);
187:
188:                if (filesAndDirs == null) {
189:                    return null;
190:                }
191:
192:                List filesDirs = Arrays.asList(filesAndDirs);
193:
194:                if (filesDirs == null) {
195:                    return null;
196:                }
197:
198:                Iterator filesIter = filesDirs.iterator();
199:                File file = null;
200:
201:                while (filesIter.hasNext()) {
202:                    file = (File) filesIter.next();
203:
204:                    if (!file.isFile()) {
205:                        //must be a directory
206:                        //recursive call!
207:                        if (sRecurse) {
208:                            List deeperList = getListing(file);
209:                            result.addAll(deeperList);
210:                        }
211:                    } else {
212:                        result.add(file);
213:                    }
214:                }
215:
216:                return result;
217:            }
218:
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.