Source Code Cross Referenced for ChangeType.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.StateMonitoring;
036:        import org.libresource.so6.core.WsConnection;
037:        import org.libresource.so6.core.command.Command;
038:        import org.libresource.so6.core.command.fs.AddBinaryFile;
039:        import org.libresource.so6.core.command.fs.Remove;
040:        import org.libresource.so6.core.command.text.AddTxtFile;
041:        import org.libresource.so6.core.command.xml.AddXmlFile;
042:        import org.libresource.so6.core.engine.log.LogUtils;
043:        import org.libresource.so6.core.engine.util.Base64;
044:        import org.libresource.so6.core.engine.util.FileUtils;
045:
046:        import java.io.BufferedOutputStream;
047:        import java.io.File;
048:        import java.io.FileOutputStream;
049:        import java.io.OutputStreamWriter;
050:
051:        import java.util.logging.Logger;
052:
053:        /**
054:         * The <code>ChangeType</code> class is used to change the type of a
055:         * previously syncronized file.
056:         * <p>
057:         * For exemple, an XML file has been detected as a text file but as it's an
058:         * important file, you prefere to synchronize it as a binary file to prevent
059:         * inside merge. Then you call this class to do so.
060:         * <p>
061:         * Some Exemples :
062:         * <ul>
063:         * <li>java -cp so6.jar ChangeType .so6/1/so6.properties build.xml BIN</li>
064:         * <li>java -cp so6.jar ChangeType .so6/1/so6.properties build.xml XML</li>
065:         * <li>java -cp so6.jar ChangeType .so6/1/so6.properties build.xml TXT</li>
066:         * </ul>
067:         *
068:         * @author Smack
069:         * @version 1.0, 26/05/04
070:         * @see org.libresource.so6.core.exec.Main
071:         * @since JDK1.4
072:         */
073:        public class ChangeType {
074:            public final static String SUPPORTED_TYPE = "BIN TXT XML";
075:
076:            public ChangeType(String wsPath, String filePath, String fileType)
077:                    throws Exception {
078:                LogUtils.removeAllHandlers(Logger.getLogger("ui.log"));
079:                LogUtils.removeAllHandlers(StateMonitoring.getInstance()
080:                        .getXMLMonitoringLogger());
081:
082:                if (SUPPORTED_TYPE.indexOf(fileType.toUpperCase()) == -1) {
083:                    throw new Exception("Invalide type declaration: "
084:                            + fileType + " is not a valide type. ("
085:                            + SUPPORTED_TYPE + ")");
086:                }
087:
088:                WsConnection ws = new WsConnection(wsPath);
089:                File file = new File(ws.getRefCopyPath() + File.separator
090:                        + filePath);
091:
092:                if (!file.exists()) {
093:                    throw new Exception("File does not exist ! (" + filePath
094:                            + ")");
095:                }
096:
097:                Command cmd1;
098:                Command cmd2 = null;
099:
100:                //
101:                long ticket = ws.getNs() + 1;
102:                cmd1 = new Remove(filePath, ws);
103:                cmd1.setTicket(ticket);
104:                ticket++;
105:
106:                if (fileType.toUpperCase().equals("BIN")) {
107:                    cmd2 = new AddBinaryFile(filePath, ws);
108:                    cmd2.setTicket(ticket);
109:                }
110:
111:                if (fileType.toUpperCase().equals("TXT")) {
112:                    cmd2 = new AddTxtFile(filePath, ws);
113:                    cmd2.setTicket(ticket);
114:                }
115:
116:                if (fileType.toUpperCase().equals("XML")) {
117:                    cmd2 = new AddXmlFile(filePath, ws);
118:                    cmd2.setTicket(ticket);
119:                }
120:
121:                // send patch
122:                File dir = FileUtils.createTmpDir();
123:                File f = File.createTempFile("changeTypePatch", null, dir);
124:                OutputStreamWriter osw = new OutputStreamWriter(
125:                        new BufferedOutputStream(new FileOutputStream(f
126:                                .getPath())));
127:                osw.write("<?xml version=\"1.0\"?>\n");
128:                osw.write("<patch>");
129:                osw.write("<name>"
130:                        + Base64.encodeBytes(ws.getWsName().getBytes("UTF-8"))
131:                        + "</name>");
132:                osw.write("<begin>" + (ticket - 1) + "</begin>");
133:                osw.write("<end>" + ticket + "</end>");
134:                osw.write("<comment>"
135:                        + Base64.encodeBytes("Change Type".getBytes("UTF-8"))
136:                        + "</comment>");
137:                osw.write("<command>");
138:                osw.write("<class>" + cmd1.getClass().getName() + "</class>");
139:                cmd1.toXML(osw);
140:                osw.write("</command>");
141:                osw.write("<command>");
142:                osw.write("<class>" + cmd2.getClass().getName() + "</class>");
143:                cmd2.toXML(osw);
144:                osw.write("</command>");
145:                osw.write("</patch>");
146:                osw.flush();
147:                osw.close();
148:
149:                //
150:                //		FileReader fr = new FileReader(f);
151:                //		LineNumberReader lnr = new LineNumberReader(fr);
152:                //		String line = null;
153:                //		System.out.println();
154:                //		while ((line = lnr.readLine()) != null)
155:                //			System.out.println(line);
156:                //		System.out.println();
157:                //		fr.close();
158:                //		
159:                ws.getClient().sendPatch(ticket - 1, ticket, f.getPath(), true);
160:                System.out.println("Patch sent");
161:
162:                //
163:                ws.update();
164:                System.out.println("Patch applied localy");
165:            }
166:
167:            /**
168:             * The <code>ChangeType</code> class is used to change the type of a
169:             * previously syncronized file.
170:             * <p>
171:             * For exemple, an XML file has been detected as a text file but as it's an
172:             * important file, you prefere to synchronize it as a binary file to prevent
173:             * inside merge. Then you call this class to do so.
174:             * <p>
175:             * Some Exemples :
176:             * <ul>
177:             * <li>java -cp so6.jar ChangeType .so6/1/so6.properties build.xml BIN
178:             * </li>
179:             * <li>java -cp so6.jar ChangeType .so6/1/so6.properties build.xml XML
180:             * </li>
181:             * <li>java -cp so6.jar ChangeType .so6/1/so6.properties build.xml TXT
182:             * </li>
183:             * </ul>
184:             *
185:             * @param args
186:             *            <ul>
187:             *            <li>Path of the WsConnection property file
188:             *            (.so6/1/so6.properties)</li>
189:             *            <li>Relative file path that we want to change the type
190:             *            (src/fr/ecoo/so6/Workspace.java )</li>
191:             *            <li>The file type (TXT-BIN-XML)</li>
192:             *            </ul>
193:             *
194:             */
195:            public static void main(String[] args) throws Exception {
196:                if (args.length != 3) {
197:                    System.err.println("Usage: wscPath filePath type");
198:                    System.err
199:                            .println(" (1) wscPath: Workspace connection property file path");
200:                    System.err.println(" (2) filePath: relative file path");
201:                    System.err.println(" (3) type: BIN TXT XML");
202:                } else if (args.length == 3) {
203:                    ChangeType ct = new ChangeType(args[0], args[1], args[2]);
204:                    System.exit(0);
205:                }
206:            }
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.