Source Code Cross Referenced for LibCopier.java in  » J2EE » jag » com » finalist » jaggenerator » 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 » J2EE » jag » com.finalist.jaggenerator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*   Copyright (C) 2004 Finalist IT Group
002:         *
003:         *   This file is part of JAG - the Java J2EE Application Generator
004:         *
005:         *   JAG is free software; you can redistribute it and/or modify
006:         *   it under the terms of the GNU General Public License as published by
007:         *   the Free Software Foundation; either version 2 of the License, or
008:         *   (at your option) any later version.
009:         *   JAG is distributed in the hope that it will be useful,
010:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         *   GNU General Public License for more details.
013:         *   You should have received a copy of the GNU General Public License
014:         *   along with JAG; if not, write to the Free Software
015:         *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
016:         */
017:
018:        package com.finalist.jaggenerator;
019:
020:        import org.xml.sax.SAXException;
021:        import org.w3c.dom.Document;
022:        import org.w3c.dom.NodeList;
023:        import org.w3c.dom.Node;
024:        import org.w3c.dom.NamedNodeMap;
025:
026:        import javax.xml.parsers.ParserConfigurationException;
027:        import javax.xml.parsers.DocumentBuilderFactory;
028:        import javax.xml.parsers.DocumentBuilder;
029:        import java.io.*;
030:        import java.util.ArrayList;
031:        import java.util.Iterator;
032:        import java.util.HashMap;
033:        import java.net.URL;
034:
035:        /**
036:         * Helper class for copying jar files to the generated build file to prevent unnecessary downloads.
037:         *
038:         * User: Rudie Ekkelenkamp
039:         * Date: Apr 16, 2004
040:         * Time: 9:13:55 PM
041:         */
042:        public class LibCopier {
043:
044:            /**
045:             * Reads the libraries from the JAG generated libXmlFile and copy them if needed
046:             * from the local lib directory to the generated lib directory.
047:             * @throws javax.xml.parsers.ParserConfigurationException Indicates a serious configuration error.
048:             * @throws org.xml.sax.SAXException Encapsulate a general SAX error or warning.
049:             * @throws java.io.IOException Signals that an I/O exception of some sort has occurred
050:             * @return a Hashmap with filename/URL pairs as Strings that couldn't be copied .
051:             *
052:             */
053:            public static HashMap copyJars(String libXmlFile, String targetDir)
054:                    throws ParserConfigurationException, SAXException,
055:                    IOException {
056:
057:                File target = new File(targetDir);
058:                HashMap failedCopies = new HashMap();
059:                if (!target.exists()) {
060:                    System.out
061:                            .println("Target directory to copy files to doesn't exist.");
062:                    return null;
063:                }
064:                ArrayList libs = new ArrayList();
065:                DocumentBuilderFactory dbf = DocumentBuilderFactory
066:                        .newInstance();
067:                dbf.setValidating(true);
068:                DocumentBuilder db = dbf.newDocumentBuilder();
069:                Document doc = db.parse(libXmlFile);
070:                NodeList nl = doc.getElementsByTagName("lib");
071:                for (int i = 0; i < nl.getLength(); i++) {
072:                    Node node = nl.item(i);
073:                    NamedNodeMap atts = node.getAttributes();
074:                    String file;
075:                    Node url = atts.getNamedItem("url");
076:                    if (url != null) {
077:                        file = url.getNodeValue();
078:                        try {
079:                            URL theUrl = new URL(file);
080:                            String name = theUrl.getFile();
081:                            if (name.lastIndexOf("/") != -1) {
082:                                name = name
083:                                        .substring(name.lastIndexOf("/") + 1);
084:                            }
085:                            libs.add(name);
086:                        } catch (Exception e) {
087:                            e.printStackTrace();
088:                        }
089:                    }
090:                }
091:
092:                for (Iterator iterator = libs.iterator(); iterator.hasNext();) {
093:                    String s = (String) iterator.next();
094:                    File sourceFile = new File(".." + File.separator + "lib"
095:                            + File.separator + s);
096:                    File targetFile = new File(targetDir + File.separator + s);
097:                    if (sourceFile.exists()) {
098:                        if (!targetFile.exists()) {
099:                            // Only copy if the target file doesn't exist yet.
100:                            copy(sourceFile, targetFile);
101:                        } else {
102:                        }
103:                    } else {
104:                        failedCopies.put(s, sourceFile.getCanonicalPath());
105:                    }
106:                }
107:                return failedCopies;
108:            }
109:
110:            // Copies src file to dst file.
111:            // If the dst file does not exist, it is created
112:            private static void copy(File src, File dst) throws IOException {
113:                InputStream in = new FileInputStream(src);
114:                OutputStream out = new FileOutputStream(dst);
115:
116:                // Transfer bytes from in to out
117:                byte[] buf = new byte[1024];
118:                int len;
119:                while ((len = in.read(buf)) > 0) {
120:                    out.write(buf, 0, len);
121:                }
122:                in.close();
123:                out.close();
124:            }
125:
126:            public static void main(String[] args) {
127:                String lib = "lib.xml";
128:                try {
129:                    copyJars(lib, "c:/temp");
130:                } catch (ParserConfigurationException e) {
131:                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
132:                } catch (SAXException e) {
133:                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
134:                } catch (IOException e) {
135:                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
136:                }
137:            }
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.