Source Code Cross Referenced for FindConflict.java in  » Groupware » LibreSource » org » libresource » so6 » core » exec » 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 » Groupware » LibreSource » org.libresource.so6.core.exec 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * LibreSource
003:         * Copyright (C) 2004-2008 Artenum SARL / INRIA
004:         * http://www.libresource.org - contact@artenum.com
005:         *
006:         * This file is part of the LibreSource software, 
007:         * which can be used and distributed under license conditions.
008:         * The license conditions are provided in the LICENSE.TXT file 
009:         * at the root path of the packaging that enclose this file. 
010:         * More information can be found at 
011:         * - http://dev.libresource.org/home/license
012:         *
013:         * Initial authors :
014:         *
015:         * Guillaume Bort / INRIA
016:         * Francois Charoy / Universite Nancy 2
017:         * Julien Forest / Artenum
018:         * Claude Godart / Universite Henry Poincare
019:         * Florent Jouille / INRIA
020:         * Sebastien Jourdain / INRIA / Artenum
021:         * Yves Lerumeur / Artenum
022:         * Pascal Molli / Universite Henry Poincare
023:         * Gerald Oster / INRIA
024:         * Mariarosa Penzi / Artenum
025:         * Gerard Sookahet / Artenum
026:         * Raphael Tani / INRIA
027:         *
028:         * Contributors :
029:         *
030:         * Stephane Bagnier / Artenum
031:         * Amadou Dia / Artenum-IUP Blois
032:         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033:         */package org.libresource.so6.core.exec;
034:
035:        import org.libresource.so6.core.WsConnection;
036:        import org.libresource.so6.core.engine.DBType;
037:        import org.libresource.so6.core.tf.TextFileFunctions;
038:
039:        import java.io.File;
040:        import java.io.FileReader;
041:        import java.io.LineNumberReader;
042:
043:        import java.util.ArrayList;
044:        import java.util.Collection;
045:        import java.util.Enumeration;
046:        import java.util.Iterator;
047:        import java.util.Properties;
048:
049:        /**
050:         * The <code>FindConflict</code> class is used to search into a Workspace if
051:         * some files have conflict inside or if two version of a file are in conflict.
052:         * <p>
053:         * The result is presented in a list of file on the standard output.
054:         * <ul>
055:         * <li>When it's written conflict "on" file then it means thats a version
056:         * conflict.</li>
057:         * <li>When it's written conflict "in" file then it means there's conflicts
058:         * inside the text file.</li>
059:         * </ul>
060:         *
061:         * @author Smack
062:         * @version 1.0, 26/05/04
063:         * @see org.libresource.so6.core.exec.Main
064:         * @since JDK1.4
065:         */
066:        public class FindConflict {
067:            /**
068:             * The <code>FindConflict</code> class is used to search into a Workspace
069:             * if some files have conflict inside or if two version of a file are in
070:             * conflict.
071:             * <p>
072:             * The result is presented in a list of file on the standard output.
073:             * <ul>
074:             * <li>When it's written conflict "on" file then it means thats a version
075:             * conflict.</li>
076:             * <li>When it's written conflict "in" file then it means there's conflicts
077:             * inside the text file.</li>
078:             * </ul>
079:             *
080:             * @param args
081:             *            <ul>
082:             *            <li>The WsConnection property file path
083:             *            (.so6/1/so6.properties)</li>
084:             *            </ul>
085:             * @throws Exception
086:             */
087:            public static void main(String[] args) throws Exception {
088:                if (args.length != 1) {
089:                    System.err.println("Usage: wscPath");
090:                    System.err.println(" (1) wscPath: path of the file "
091:                            + WsConnection.SO6_WSC_FILE);
092:                } else {
093:                    String wsPath = args[0];
094:                    System.out
095:                            .println("Start searching conflict in workspace : "
096:                                    + wsPath);
097:
098:                    Collection c = searchConflict(wsPath);
099:
100:                    for (Iterator i = c.iterator(); i.hasNext();) {
101:                        System.out.println(i.next());
102:                    }
103:                }
104:            }
105:
106:            /**
107:             * Search into the workspace of a connection the set of conflicts.
108:             *
109:             * @param wscPath
110:             * @return The set of ConflictFile
111:             * @throws Exception
112:             */
113:            public static Collection searchConflict(String wscPath)
114:                    throws Exception {
115:                ArrayList result = new ArrayList();
116:                WsConnection ws = new WsConnection(wscPath);
117:                DBType dbType = ws.getDBType();
118:                dbType.updateFromWalk(ws.getPath(), ws.getXmlAutoDetection());
119:
120:                Properties props = dbType.getDBTypeData();
121:                File f;
122:
123:                for (Enumeration e = props.keys(); e.hasMoreElements();) {
124:                    String path = (String) e.nextElement();
125:                    f = new File(ws.getPath(), path);
126:
127:                    if (!f.exists()) {
128:                        continue;
129:                    }
130:
131:                    int type = Integer.parseInt(props.getProperty(path));
132:
133:                    switch (type) {
134:                    case DBType.TYPE_UNKNOWN:
135:
136:                        // do nothing
137:                        break;
138:
139:                    case DBType.TYPE_DIR:
140:                    case DBType.TYPE_FILE_XML:
141:                    case DBType.TYPE_FILE:
142:                    case DBType.TYPE_FILE_BIN:
143:
144:                        // check file name
145:                        if (path.indexOf("#") != -1) {
146:                            result.add(new ConflictFile(path, false));
147:                        }
148:
149:                        break;
150:
151:                    case DBType.TYPE_FILE_TXT:
152:
153:                        //	check file name
154:                        if (path.indexOf("#") != -1) {
155:                            result.add(new ConflictFile(path, false));
156:                        }
157:
158:                        // check inside
159:                        if (isFileInConflict(ws.getPath(), path)) {
160:                            result.add(new ConflictFile(path, true));
161:                        }
162:
163:                        break;
164:                    }
165:                }
166:
167:                return result;
168:            }
169:
170:            /**
171:             * Check inside a file if it contains at least a bloc of conflict.
172:             *
173:             * @param basePath
174:             * @param path
175:             * @return @throws
176:             *         Exception
177:             */
178:            public static boolean isFileInConflict(String basePath, String path)
179:                    throws Exception {
180:                File f = new File(basePath + File.separator + path);
181:
182:                if (!f.exists()) {
183:                    //throw new Exception("Error the file " + f.getPath() + " does not
184:                    // exist");
185:                    return false;
186:                }
187:
188:                if (f.length() == 0) {
189:                    return false;
190:                }
191:
192:                // check inside
193:                LineNumberReader input = null;
194:
195:                try {
196:                    input = new LineNumberReader(new FileReader(f));
197:
198:                    String startConflict;
199:                    String firstBlock;
200:                    String secondBlock;
201:
202:                    while ((startConflict = input.readLine()) != null) {
203:                        if (startConflict
204:                                .startsWith(TextFileFunctions.CONFLICT_BLOC_START)) {
205:                            // Maybe a conflict -> check further
206:                            while ((firstBlock = input.readLine()) != null) {
207:                                if (firstBlock
208:                                        .startsWith(TextFileFunctions.CONFLICT_BLOC_PADDING)) {
209:                                    // inside the first part
210:                                } else if (firstBlock
211:                                        .startsWith(TextFileFunctions.CONFLICT_BLOC_SPLIT)) {
212:                                    // end of the fisrt part
213:                                    while ((secondBlock = input.readLine()) != null) {
214:                                        if (secondBlock
215:                                                .startsWith(TextFileFunctions.CONFLICT_BLOC_PADDING)) {
216:                                            // inside the second part
217:                                        } else if (secondBlock
218:                                                .startsWith(TextFileFunctions.CONFLICT_BLOC_END)) {
219:                                            // End of the conflict
220:                                            return true;
221:                                        } else {
222:                                            return false;
223:                                        }
224:                                    }
225:                                } else {
226:                                    return false;
227:                                }
228:                            }
229:                        }
230:                    }
231:                } finally {
232:                    if (input != null) {
233:                        input.close();
234:                    }
235:                }
236:
237:                return false;
238:            }
239:
240:            public static class ConflictFile {
241:                private String path;
242:                private boolean inside;
243:
244:                public ConflictFile(String path, boolean conflictInside) {
245:                    this .path = path;
246:                    this .inside = conflictInside;
247:                }
248:
249:                public boolean isInside() {
250:                    return inside;
251:                }
252:
253:                public String getPath() {
254:                    return path;
255:                }
256:
257:                public void setInside(boolean b) {
258:                    inside = b;
259:                }
260:
261:                public void setPath(String string) {
262:                    path = string;
263:                }
264:
265:                public String toString() {
266:                    return "Conflict " + (inside ? "in" : "on") + " file "
267:                            + path;
268:                }
269:            }
270:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.