Source Code Cross Referenced for ApplicationDescriptorBuilderTask.java in  » J2EE » fleXive » com » flexive » tools » ant » 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 » fleXive » com.flexive.tools.ant 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***************************************************************
002:         *  This file is part of the [fleXive](R) project.
003:         *
004:         *  Copyright (c) 1999-2008
005:         *  UCS - unique computing solutions gmbh (http://www.ucs.at)
006:         *  All rights reserved
007:         *
008:         *  The [fleXive](R) project is free software; you can redistribute
009:         *  it and/or modify it under the terms of the GNU General Public
010:         *  License as published by the Free Software Foundation;
011:         *  either version 2 of the License, or (at your option) any
012:         *  later version.
013:         *
014:         *  The GNU General Public License can be found at
015:         *  http://www.gnu.org/copyleft/gpl.html.
016:         *  A copy is found in the textfile GPL.txt and important notices to the
017:         *  license from the author are found in LICENSE.txt distributed with
018:         *  these libraries.
019:         *
020:         *  This library is distributed in the hope that it will be useful,
021:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
022:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023:         *  GNU General Public License for more details.
024:         *
025:         *  For further information about UCS - unique computing solutions gmbh,
026:         *  please see the company website: http://www.ucs.at
027:         *
028:         *  For further information about [fleXive](R), please see the
029:         *  project website: http://www.flexive.org
030:         *
031:         *
032:         *  This copyright notice MUST APPEAR in all copies of the file!
033:         ***************************************************************/package com.flexive.tools.ant;
034:
035:        import org.apache.tools.ant.BuildException;
036:        import org.apache.tools.ant.Task;
037:
038:        import java.io.*;
039:        import java.util.ArrayList;
040:        import java.util.List;
041:
042:        /**
043:         * ANT task to build application.xml descriptors on the fly with descriptor entries
044:         * for drop-in applications
045:         *
046:         * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
047:         */
048:        public class ApplicationDescriptorBuilderTask extends Task {
049:
050:            private String dropDir = null;
051:            private String srcFile = null;
052:            private String destFile = null;
053:
054:            public void setDropDir(String dropDir) {
055:                this .dropDir = dropDir;
056:            }
057:
058:            public void setSrcFile(String srcFile) {
059:                this .srcFile = srcFile;
060:            }
061:
062:            public void setDestFile(String destFile) {
063:                this .destFile = destFile;
064:            }
065:
066:            public String getTaskName() {
067:                return "applicationDescriptorBuilder";
068:            }
069:
070:            public void execute() throws BuildException {
071:                if (srcFile == null || !(new File(srcFile).exists()))
072:                    throw new BuildException("argument srcFile (" + srcFile
073:                            + ") does not exist!");
074:                storeFile(loadFile(new File(srcFile)).replace(
075:                        "<!--DROP_IN_PLACEHOLDER-->", processDrops()),
076:                        new File(destFile));
077:            }
078:
079:            /**
080:             * Load the contents of a file, returning it as a String.
081:             * This method should only be used when really necessary since no real error handling is performed!!!
082:             *
083:             * @param file the File to load
084:             * @return file contents
085:             */
086:            public static String loadFile(File file) {
087:                try {
088:                    return loadFromInputStream(new FileInputStream(file),
089:                            (int) file.length());
090:                } catch (FileNotFoundException e) {
091:                    throw new BuildException(e);
092:                }
093:            }
094:
095:            /**
096:             * Load a String from an InputStream (until end of stream)
097:             *
098:             * @param in     InputStream
099:             * @param length length of the string if &lt; -1 (NOT number of bytes to read!)
100:             * @return String
101:             */
102:            public static String loadFromInputStream(InputStream in, int length) {
103:                StringBuilder sb = new StringBuilder(length > 0 ? length : 5000);
104:                try {
105:                    int read;
106:                    byte[] buffer = new byte[1024];
107:                    while ((read = in.read(buffer)) != -1) {
108:                        sb.append(new String(buffer, 0, read));
109:                    }
110:                } catch (IOException e) {
111:                    throw new BuildException(e);
112:                } finally {
113:                    if (in != null) {
114:                        try {
115:                            in.close();
116:                        } catch (IOException e) {
117:                            // ignore
118:                        }
119:                    }
120:                }
121:                return sb.toString();
122:            }
123:
124:            /**
125:             * Rather primitive "write String to file" helper, returns <code>false</code> if failed
126:             *
127:             * @param contents the String to store
128:             * @param file     the file, if existing it will be overwritten
129:             * @return if successful
130:             */
131:            public static boolean storeFile(String contents, File file) {
132:                FileOutputStream out = null;
133:                try {
134:                    out = new FileOutputStream(file);
135:                    out.write(contents.getBytes("UTF-8"));
136:                    out.flush();
137:                    out.close();
138:                    return true;
139:                } catch (IOException e) {
140:                    return false;
141:                } finally {
142:                    if (out != null) {
143:                        try {
144:                            out.close();
145:                        } catch (IOException e) {
146:                            //ignore
147:                        }
148:                    }
149:                }
150:            }
151:
152:            private String processDrops() {
153:                StringBuilder sb = new StringBuilder(500).append("\n");
154:                StringBuilder dropNames = new StringBuilder(100);
155:                File drops = new File(dropDir);
156:                if (!drops.exists() || !drops.isDirectory())
157:                    throw new BuildException("argument dropDir (" + dropDir
158:                            + ") is not a valid directory!");
159:                List<File> jar = new ArrayList<File>(5);
160:                List<File> ejb = new ArrayList<File>(5);
161:                List<File> war = new ArrayList<File>(5);
162:                for (File f : drops.listFiles()) {
163:                    if (f.getAbsolutePath().toLowerCase().endsWith("-ejb.jar"))
164:                        ejb.add(f);
165:                    else if (f.getAbsolutePath().toLowerCase().endsWith(".jar"))
166:                        jar.add(f);
167:                    else if (f.getAbsolutePath().toLowerCase().endsWith(".war"))
168:                        war.add(f);
169:                    else if (!f.getName().startsWith(".")
170:                            && !f.getName().equals("drops.archives")) //ignore .svn, .cvs etc files
171:                        System.out.println("Warning: Unrecognized drop file: "
172:                                + f.getName());
173:                }
174:                // Currently, JARs will be copied to the ear/lib directory and do not have to be registered
175:                /*
176:                 for (File f : jar) {
177:                 sb.append("    <module>\n" + "      <java>").
178:                 append(f.getName()).
179:                 append("</java>\n" + "    </module>\n\n");
180:                 }
181:                 */
182:                for (File f : ejb) {
183:                    sb.append("    <module>\n" + "      <ejb>").append(
184:                            f.getName()).append(
185:                            "</ejb>\n" + "    </module>\n\n");
186:                }
187:                for (File f : war) {
188:                    if (dropNames.length() > 0)
189:                        dropNames.append(',');
190:                    dropNames.append(f.getName().substring(0,
191:                            f.getName().lastIndexOf('.')));
192:                    sb.append(
193:                            "    <module>\n" + "        <web>\n"
194:                                    + "            <web-uri>").append(
195:                            f.getName()).append(
196:                            "</web-uri>\n" + "            <context-root>/")
197:                            .append(
198:                                    f.getName().substring(0,
199:                                            f.getName().lastIndexOf('.')))
200:                            .append(
201:                                    "</context-root>\n" + "        </web>\n"
202:                                            + "    </module>\n");
203:                }
204:                storeFile(dropNames.toString(), new File(drops
205:                        .getAbsolutePath()
206:                        + File.separatorChar + "drops.archives"));
207:                return sb.toString();
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.