Source Code Cross Referenced for FileListing.java in  » ESB » open-esb » com » sun » jbi » binding » file » 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 » ESB » open esb » com.sun.jbi.binding.file.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)FileListing.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.binding.file.util;
030:
031:        import java.io.File;
032:        import java.io.FilenameFilter;
033:
034:        import java.util.ArrayList;
035:        import java.util.Arrays;
036:        import java.util.Iterator;
037:        import java.util.List;
038:        import java.util.logging.Logger;
039:
040:        /**
041:         * Helper class for listing files / folders.
042:         *
043:         * @author Sun Microsystems, Inc.
044:         */
045:        public final class FileListing {
046:            /**
047:             * Flag to indicate recursive listing.
048:             */
049:            private static boolean sRecurse = false;
050:
051:            /**
052:             * Filter class to be used.
053:             */
054:            private static FilenameFilter sFilter = null;
055:
056:            /**
057:             * Logger object.
058:             */
059:            private static Logger sLog = Logger
060:                    .getLogger("com.sun.jbi.binding.file.util");
061:
062:            /**
063:             * Gets the list of files in a folder.
064:             *
065:             * @param aDir folder name.
066:             * @param bRecurse will recurse if true.
067:             * @param aFilter filname filter.
068:             *
069:             * @return List of file names.
070:             */
071:            public static synchronized List getFileListing(File aDir,
072:                    boolean bRecurse, FilenameFilter aFilter) {
073:                sRecurse = bRecurse;
074:                sFilter = aFilter;
075:
076:                if ((aDir == null) || (aDir.getName().trim().equals(""))) {
077:                    sLog.severe("Directory is null");
078:
079:                    return null;
080:                }
081:
082:                return getListing(aDir);
083:            }
084:
085:            /**
086:             * Recursively walk a directory tree and return a List of all Files found;
087:             * the List is sorted using File.compareTo.
088:             *
089:             * @param aDir is a valid directory, which can be read.
090:             *
091:             * @return array of folder names
092:             */
093:            public static synchronized String[] getFolderListing(File aDir) {
094:                File[] dirs = aDir.listFiles();
095:
096:                if (dirs == null) {
097:                    return null;
098:                }
099:
100:                List filesDirs = Arrays.asList(dirs);
101:
102:                if (filesDirs == null) {
103:                    return null;
104:                }
105:
106:                Iterator filesIter = filesDirs.iterator();
107:                String[] result = new String[filesDirs.size()];
108:                File file = null;
109:                int counter = 0;
110:
111:                while (filesIter.hasNext()) {
112:                    file = (File) filesIter.next();
113:
114:                    if (!file.isFile()) {
115:                        result[counter] = file.getAbsolutePath();
116:                        counter++;
117:                    }
118:                }
119:
120:                return result;
121:            }
122:
123:            /**
124:             * Util method to get the list of folders.
125:             *
126:             * @param aDir folder name for which contents have to be listed.
127:             *
128:             * @return array of folder names.
129:             */
130:            public static synchronized String[] getFolderNameListing(File aDir) {
131:                File[] dirs = aDir.listFiles();
132:
133:                if (dirs == null) {
134:                    return null;
135:                }
136:
137:                List filesDirs = Arrays.asList(dirs);
138:
139:                if (filesDirs == null) {
140:                    return null;
141:                }
142:
143:                Iterator filesIter = filesDirs.iterator();
144:                String[] result = new String[filesDirs.size()];
145:                File file = null;
146:                int counter = 0;
147:
148:                while (filesIter.hasNext()) {
149:                    file = (File) filesIter.next();
150:
151:                    if (!file.isFile()) {
152:                        result[counter] = file.getName();
153:                        counter++;
154:                    }
155:                }
156:
157:                return result;
158:            }
159:
160:            /**
161:             * Returns a WSDL file from the deployment artifact.
162:             *
163:             * @param path Path of the ASA
164:             *
165:             * @return WSDL file path
166:             */
167:            public static String getWSDLFile(String path) {
168:                InputFileFilter myFilter = new InputFileFilter();
169:                myFilter.setFilterexpression(".*\\.wsdl");
170:
171:                String wsdlfile = null;
172:
173:                try {
174:                    File dir = new File(path);
175:                    File[] filesAndDirs = dir.listFiles(myFilter);
176:
177:                    if (filesAndDirs == null) {
178:                        wsdlfile = null;
179:                    } else {
180:                        if (filesAndDirs.length > 0) {
181:                            wsdlfile = filesAndDirs[0].getAbsolutePath();
182:                        }
183:                    }
184:                } catch (Exception e) {
185:                    ;
186:                }
187:
188:                return wsdlfile;
189:            }
190:
191:            /**
192:             * Returns an XML file path from the deployment artifact.
193:             *
194:             * @param path path of the deployment artifact.
195:             *
196:             * @return XML file path.
197:             */
198:            public static String getXMLFile(String path) {
199:                InputFileFilter myFilter = new InputFileFilter();
200:                myFilter.setFilterexpression(".*\\.xml");
201:
202:                String xmlfile = null;
203:
204:                try {
205:                    File dir = new File(path);
206:                    File[] filesAndDirs = dir.listFiles(myFilter);
207:
208:                    if (filesAndDirs == null) {
209:                        xmlfile = null;
210:                    } else {
211:                        if (filesAndDirs.length > 0) {
212:                            xmlfile = filesAndDirs[0].getAbsolutePath();
213:                        }
214:                    }
215:                } catch (Exception e) {
216:                    ;
217:                }
218:
219:                return xmlfile;
220:            }
221:
222:            /**
223:             * Recursively walk a directory tree and return a List of all Files found;
224:             * the List is sorted using File.compareTo.
225:             *
226:             * @param aDir is a valid directory, which can be read.
227:             *
228:             * @return list of files.
229:             */
230:            private static List getListing(File aDir) {
231:                List result = new ArrayList();
232:                File[] filesAndDirs = aDir.listFiles(sFilter);
233:
234:                if (filesAndDirs == null) {
235:                    return null;
236:                }
237:
238:                List filesDirs = Arrays.asList(filesAndDirs);
239:
240:                if (filesDirs == null) {
241:                    return null;
242:                }
243:
244:                Iterator filesIter = filesDirs.iterator();
245:                File file = null;
246:
247:                while (filesIter.hasNext()) {
248:                    file = (File) filesIter.next();
249:
250:                    if (!file.isFile()) {
251:                        if (sRecurse) {
252:                            List deeperList = getListing(file);
253:                            result.addAll(deeperList);
254:                        }
255:                    } else {
256:                        if (FileBindingUtil.canAdd(file)) {
257:                            result.add(file);
258:                        }
259:
260:                        if (result.size() >= ConfigData.BATCH_SIZE) {
261:                            return result;
262:                        }
263:                    }
264:                }
265:
266:                return result;
267:            }
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.