Source Code Cross Referenced for ImportScrubber.java in  » Code-Analyzer » importscrubber » net » sourceforge » importscrubber » 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 » Code Analyzer » importscrubber » net.sourceforge.importscrubber 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.importscrubber;
002:
003:        import java.io.File;
004:        import java.io.IOException;
005:        import java.util.*;
006:
007:        /**
008:         * This class encapsulates the import scrubber controller
009:         */
010:        public class ImportScrubber {
011:            public static final String START_DIRECTORY_KEY = "importscrubber.startDir";
012:            public static final String CLASS_DIRECTORY_KEY = "importscrubber.classDir";
013:            public static final String RECURSE = "importscrubber.recurse";
014:            public static final String SORT_STD_HIGH = "importscrubber.sortStdHigh";
015:            public static final String SYNC_CLASS_TO_SOURCE = "importscrubber.syncClassToSource";
016:            public static final String THRESHOLD = "importscrubber.threshold";
017:            public static final String THRESHOLD_STD_ONLY = "importscrubber.thresholdStdOnly";
018:            public static final String BREAK_STYLE = "importscrubber.breakStyle";
019:
020:            public static final String FILE_SEPARATOR = System
021:                    .getProperty("file.separator");
022:            public static final String LINE_SEPARATOR = System
023:                    .getProperty("line.separator");
024:            public static boolean DEBUG = false;
025:            private FileChooser _fileChooser;
026:            private List _tasks = new ArrayList();
027:            private StatementFormat _format;
028:            private String _encoding;
029:
030:            public ImportScrubber(String encoding) {
031:                _encoding = encoding;
032:            }
033:
034:            public void setFileRoot(String fileName, String classRoot,
035:                    boolean recurse) throws IOException {
036:                _fileChooser = new FileChooser(fileName, classRoot, recurse);
037:            }
038:
039:            public static String getDirectory(String fileName) {
040:                File f = new File(fileName);
041:                if (f.isDirectory()) {
042:                    return fileName;
043:                } else {
044:                    return f.getParent();
045:                }
046:            }
047:
048:            public void setFormat(StatementFormat format) {
049:                _format = format;
050:            }
051:
052:            public void debugOff() {
053:                DEBUG = false;
054:            }
055:
056:            public void debug() {
057:                DEBUG = true;
058:            }
059:
060:            public int getTaskCount() {
061:                return _tasks.size();
062:            }
063:
064:            public Iterator getFilesIterator() {
065:                return _fileChooser;
066:            }
067:
068:            // Returns number of files to work on, allows getFiles to be called just once.
069:            public int buildTasks(Iterator iter) throws IOException {
070:                while (iter.hasNext()) {
071:                    FilePair pair = (FilePair) iter.next();
072:                    _tasks.add(new ScrubTask(pair, _format, _encoding));
073:                }
074:
075:                return _tasks.size();
076:            }
077:
078:            public void runTasks(IProgressMonitor monitor) throws IOException {
079:                for (ListIterator iter = _tasks.listIterator(); iter.hasNext();) {
080:                    ScrubTask task = (ScrubTask) iter.next();
081:                    monitor.taskStarted(task);
082:                    task.run();
083:                    monitor.taskComplete(task);
084:                }
085:                _tasks.clear();
086:            }
087:
088:            public static void main(String[] args) {
089:                if (argExists("g", args)) {
090:                    new ImportScrubberGUI();
091:                    return;
092:                }
093:
094:                String encoding = null;
095:                if (argExists("encoding", args)) {
096:                    encoding = findArg("encoding", args);
097:                } else {
098:                    encoding = System.getProperty("file.encoding");
099:                }
100:
101:                if (!argExists("root", args)) {
102:                    usage();
103:                    System.exit(0);
104:                }
105:                String root = findArg("root", args);
106:                if (!(new File(root).exists())) {
107:                    System.out.println("Root: " + root + " does not exist");
108:                    usage();
109:                    System.exit(0);
110:                }
111:                boolean recurse = argExists("recurse", args);
112:
113:                StatementFormat format = StatementFormat.getFormat(args);
114:
115:                try {
116:                    ImportScrubber scrubber = new ImportScrubber(encoding);
117:
118:                    if (argExists("classRoot", args)) {
119:                        String classesRootStr = findArg("classRoot", args);
120:                        scrubber.setFileRoot(root, classesRootStr, recurse);
121:                    } else {
122:                        scrubber.setFileRoot(root, getDirectory(root), recurse);
123:                    }
124:
125:                    scrubber.setFormat(format);
126:                    System.out.println("Building tasks");
127:                    scrubber.buildTasks(scrubber.getFilesIterator());
128:                    scrubber.runTasks(new ConsoleProgressMonitor());
129:                    System.out.println(LINE_SEPARATOR + "All done!");
130:                } catch (Exception e) {
131:                    e.printStackTrace();
132:                }
133:            }
134:
135:            public static boolean argExists(String argFlag, String[] args) {
136:                for (int i = 0; i < args.length; i++) {
137:                    if (args[i].equalsIgnoreCase("-" + argFlag)) {
138:                        return true;
139:                    }
140:                }
141:                return false;
142:            }
143:
144:            public static String findArg(String argFlag, String[] args) {
145:                for (int i = 0; i < args.length; i++) {
146:                    if (args[i].equalsIgnoreCase("-" + argFlag)) {
147:                        return args[i + 1];
148:                    }
149:                }
150:                throw new IllegalArgumentException("Couldn't find " + argFlag);
151:            }
152:
153:            private static void usage() {
154:                System.out
155:                        .println("Usage: java net.sourceforge.importscrubber.ImportScrubber\n"
156:                                + "-g\n"
157:                                + "| -root <dir|file> [-classroot <dir>] [-recurse] [-encoding charsetname] [formatargs]\n"
158:                                + "formatargs:\n" + StatementFormat.getUsage());
159:                System.out
160:                        .println("Ex: java net.sourceforge.importscrubber.ImportScrubber -root /home/me/myproject/src -recurse");
161:                System.out.println("\nOR, TO USE THE GUI:\n");
162:                System.out
163:                        .println("Ex: java net.sourceforge.importscrubber.ImportScrubber -g");
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.