Source Code Cross Referenced for XsltWebXmlTask.java in  » J2EE » Pustefix » de » schlund » pfixcore » util » 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 » Pustefix » de.schlund.pfixcore.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of PFIXCORE.
003:         *
004:         * PFIXCORE is free software; you can redistribute it and/or modify
005:         * it under the terms of the GNU Lesser General Public License as published by
006:         * the Free Software Foundation; either version 2 of the License, or
007:         * (at your option) any later version.
008:         *
009:         * PFIXCORE 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 Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public License
015:         * along with PFIXCORE; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         *
018:         */
019:        package de.schlund.pfixcore.util;
020:
021:        import java.io.File;
022:
023:        import javax.xml.parsers.DocumentBuilder;
024:        import javax.xml.parsers.DocumentBuilderFactory;
025:
026:        import org.apache.tools.ant.BuildException;
027:        import org.apache.tools.ant.Project;
028:        import org.w3c.dom.Document;
029:        import org.w3c.dom.Element;
030:        import org.w3c.dom.NodeList;
031:
032:        /**
033:         *
034:         * the following attributes have to be set when calling this task:
035:         * <ul>
036:         * <li>projects: relative (to ${dir.projects}) path to the projects.xml file </li>
037:         * <li>corewebxml: relative (to ${dir.projects}) path to the core web.xml file,
038:         *   which defines a minimum web.xml file</li>
039:         * </ul>
040:         *
041:         * @author <a href="mailto:benjamin@schlund.de">Benjamin Reitzammer</a>
042:         * @version $Id: XsltWebXmlTask.java 3058 2007-02-12 12:08:46Z mtld $
043:         */
044:        public class XsltWebXmlTask extends XsltGenericTask {
045:
046:            protected DocumentBuilderFactory dbFactory;
047:
048:            /** contains the location of projects.xml file, relative to srcdirResolved
049:             */
050:            protected String projects;
051:
052:            /** contains the location of core web.xml template, which is used, when a
053:             * project has no custom web.xml specified, relative to srcdirResolved
054:             */
055:            protected String corewebxml;
056:
057:            public void init() throws BuildException {
058:                super .init();
059:
060:                this .dbFactory = DocumentBuilderFactory.newInstance();
061:                dbFactory.setNamespaceAware(true);
062:                dbFactory.setValidating(false);
063:            }
064:
065:            protected void doTransformations() {
066:                StringBuffer tmp = new StringBuffer(100);
067:                tmp.append("Created web.xml for ");
068:                int created = 0;
069:                try {
070:                    if (infile != null || outfile != null) {
071:                        throw new BuildException("don't use " + ATTR_INFILE
072:                                + "/" + ATTR_OUTFILE + ", use " + ATTR_SRCDIR
073:                                + "/" + ATTR_DESTDIR + " etc. instead");
074:                    }
075:                    if (projects == null || "".equals(projects)
076:                            || corewebxml == null || "".equals(corewebxml)) {
077:                        throw new BuildException(
078:                                "Attributes 'projects' and 'corewebxml' are not allowed to be null or empty");
079:                    }
080:
081:                    File coreWebXml = new File(srcdirResolved, corewebxml);
082:                    if (!coreWebXml.exists() || !coreWebXml.canRead()) {
083:                        throw new BuildException("File '" + corewebxml
084:                                + "' can't be found or can't be read");
085:                    }
086:
087:                    DocumentBuilder domp;
088:                    Document doc;
089:                    File projectsFile = new File(srcdirResolved, projects);
090:                    try {
091:                        log("Parsing " + projectsFile, Project.MSG_DEBUG);
092:                        domp = dbFactory.newDocumentBuilder();
093:                        doc = domp.parse(projectsFile);
094:                    } catch (Exception e) {
095:                        throw new BuildException("Could not parse file "
096:                                + projectsFile, e);
097:                    }
098:
099:                    int count;
100:                    NodeList nl = doc.getElementsByTagName("project");
101:                    for (int i = 0; i < nl.getLength(); i++) {
102:                        Element currproject = (Element) nl.item(i);
103:                        String name = currproject.getAttribute("name");
104:                        log("found project " + name + " in " + projectsFile,
105:                                Project.MSG_DEBUG);
106:
107:                        File cusWebXml = new File(srcdirResolved + "/" + name
108:                                + "/conf", "web.xml");
109:                        if (cusWebXml.exists() && cusWebXml.canRead()) {
110:                            in = cusWebXml;
111:                        } else {
112:                            in = coreWebXml;
113:                        }
114:
115:                        log("Using " + in
116:                                + " as sourcefile for web.xml transformation",
117:                                Project.MSG_DEBUG);
118:                        getTransformer().setParameter(
119:                                new XsltParam("prjname", name));
120:                        getTransformer().setParameter(
121:                                new XsltParam("projectsxmlfile", projectsFile
122:                                        .getPath()));
123:                        String outdir = "webapps/" + name + "/WEB-INF";
124:                        File webinfdir = new File(getDestdir(), outdir);
125:                        webinfdir.mkdirs();
126:
127:                        NodeList webappNodes = currproject
128:                                .getElementsByTagName("webapps");
129:                        if (webappNodes != null && webappNodes.getLength() > 0) {
130:                            Element webappElem = (Element) webappNodes.item(0);
131:                            String hostBasedAttr = webappElem
132:                                    .getAttribute("hostbased");
133:                            if (hostBasedAttr != null
134:                                    && hostBasedAttr.equals("true")) {
135:                                File hostWebappsDir = new File(getDestdir(),
136:                                        "webapps_" + name);
137:                                hostWebappsDir.mkdirs();
138:                            }
139:                        }
140:
141:                        outname = "web.xml";
142:                        out = new File(webinfdir, outname);
143:                        count = doTransformationMaybe();
144:                        if (count == 0
145:                                && (out.lastModified() < projectsFile
146:                                        .lastModified())) {
147:                            doTransformation();
148:                            count = 1;
149:                        }
150:
151:                        if (count > 0) {
152:                            if (created > 0) {
153:                                tmp.append(", ");
154:                            }
155:                            tmp.append(name);
156:                            created = created + count;
157:                        }
158:                    }
159:                } finally {
160:                    if (created > 0) {
161:                        log(tmp.toString(), Project.MSG_INFO);
162:                    }
163:                    scanner = null;
164:                    inname = null; /* filename relative to srcdirResolved */
165:                    infilenameNoExt = null; /* filename relative to srcdirResolved without extension */
166:                    outname = null; /* filename relative to srcdirResolved */
167:                    in = null;
168:                    out = null;
169:                    inLastModified = 0;
170:                    outLastModified = 0;
171:                    styleLastModified = 0;
172:                }
173:            }
174:
175:            public String getProjects() {
176:                return projects;
177:            }
178:
179:            public void setProjects(String newProjects) {
180:                this .projects = newProjects;
181:            }
182:
183:            public String getCorewebxml() {
184:                return corewebxml;
185:            }
186:
187:            public void setCorewebxml(String newCorewebxml) {
188:                this.corewebxml = newCorewebxml;
189:            }
190:
191:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.