Source Code Cross Referenced for WebXmlIo.java in  » Testing » jakarta-cactus » org » apache » cactus » integration » ant » deployment » webapp » 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 » Testing » jakarta cactus » org.apache.cactus.integration.ant.deployment.webapp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2003 The Apache Software Foundation.
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         * 
018:         * ========================================================================
019:         */
020:        package org.apache.cactus.integration.ant.deployment.webapp;
021:
022:        import java.io.File;
023:        import java.io.FileInputStream;
024:        import java.io.FileOutputStream;
025:        import java.io.IOException;
026:        import java.io.InputStream;
027:        import java.io.OutputStream;
028:
029:        import javax.xml.parsers.DocumentBuilder;
030:        import javax.xml.parsers.DocumentBuilderFactory;
031:        import javax.xml.parsers.ParserConfigurationException;
032:
033:        import org.apache.xml.serialize.OutputFormat;
034:        import org.apache.xml.serialize.XMLSerializer;
035:        import org.w3c.dom.Document;
036:        import org.w3c.dom.DocumentType;
037:        import org.xml.sax.EntityResolver;
038:        import org.xml.sax.InputSource;
039:        import org.xml.sax.SAXException;
040:
041:        /**
042:         * Provides convenience methods for reading and writing web deployment
043:         * descriptors.
044:         *
045:         * @since Cactus 1.5
046:         * @version $Id: WebXmlIo.java 239003 2004-05-31 20:05:27Z vmassol $
047:         */
048:        public class WebXmlIo {
049:
050:            // Inner Classes -----------------------------------------------------------
051:
052:            /**
053:             * Implementation of the SAX EntityResolver interface that looks up the
054:             * web-app DTDs from the JAR.
055:             */
056:            private static class WebXmlEntityResolver implements  EntityResolver {
057:
058:                /**
059:                 * @see org.xml.sax.EntityResolver#resolveEntity
060:                 */
061:                public InputSource resolveEntity(String thePublicId,
062:                        String theSystemId) throws SAXException, IOException {
063:                    WebXmlVersion version = WebXmlVersion.valueOf(thePublicId);
064:                    if (version != null) {
065:                        String fileName = version.getSystemId().substring(
066:                                version.getSystemId().lastIndexOf('/'));
067:                        InputStream in = this .getClass().getResourceAsStream(
068:                                "/org/apache/cactus/integration/ant/deployment/resources"
069:                                        + fileName);
070:                        if (in != null) {
071:                            return new InputSource(in);
072:                        }
073:                    }
074:                    return null;
075:                }
076:
077:            }
078:
079:            // Public Methods ----------------------------------------------------------
080:
081:            /**
082:             * Creates a new empty deployment descriptor.
083:             * 
084:             * @param theVersion The version of the descriptor to create
085:             * @return The new descriptor
086:             * @throws ParserConfigurationException If the XML parser was not correctly
087:             *          configured
088:             */
089:            public static WebXml newWebXml(WebXmlVersion theVersion)
090:                    throws ParserConfigurationException {
091:                DocumentBuilderFactory factory = DocumentBuilderFactory
092:                        .newInstance();
093:                factory.setValidating(false);
094:                factory.setNamespaceAware(false);
095:                DocumentBuilder builder = factory.newDocumentBuilder();
096:                DocumentType docType = null;
097:                if (theVersion != null) {
098:                    docType = builder.getDOMImplementation()
099:                            .createDocumentType("web-app",
100:                                    theVersion.getPublicId(),
101:                                    theVersion.getSystemId());
102:                }
103:                Document doc = builder.getDOMImplementation().createDocument(
104:                        "", "web-app", docType);
105:                return new WebXml(doc);
106:            }
107:
108:            /**
109:             * Parses a deployment descriptor stored in a regular file.
110:             * 
111:             * @param theFile The file to parse
112:             * @param theEntityResolver A SAX entity resolver, or <code>null</code> to
113:             *        use the default
114:             * @return The parsed descriptor
115:             * @throws SAXException If the file could not be parsed
116:             * @throws ParserConfigurationException If the XML parser was not correctly
117:             *          configured
118:             * @throws IOException If an I/O error occurs
119:             */
120:            public static WebXml parseWebXmlFromFile(File theFile,
121:                    EntityResolver theEntityResolver) throws SAXException,
122:                    ParserConfigurationException, IOException {
123:                InputStream in = null;
124:                try {
125:                    in = new FileInputStream(theFile);
126:                    return parseWebXml(in, theEntityResolver);
127:                } finally {
128:                    if (in != null) {
129:                        try {
130:                            in.close();
131:                        } catch (IOException ioe) {
132:                            // we'll pass on the original IO error, so ignore this one
133:                        }
134:                    }
135:                }
136:            }
137:
138:            /**
139:             * Parses a deployment descriptor provided as input stream.
140:             * 
141:             * @param theInput The input stream
142:             * @param theEntityResolver A SAX entity resolver, or <code>null</code> to
143:             *        use the default
144:             * @return The parsed descriptor
145:             * @throws SAXException If the input could not be parsed
146:             * @throws ParserConfigurationException If the XML parser was not correctly
147:             *          configured
148:             * @throws IOException If an I/O error occurs
149:             */
150:            public static WebXml parseWebXml(InputStream theInput,
151:                    EntityResolver theEntityResolver) throws SAXException,
152:                    ParserConfigurationException, IOException {
153:                DocumentBuilderFactory factory = DocumentBuilderFactory
154:                        .newInstance();
155:                factory.setValidating(false);
156:                factory.setNamespaceAware(false);
157:                DocumentBuilder builder = factory.newDocumentBuilder();
158:                if (theEntityResolver != null) {
159:                    builder.setEntityResolver(theEntityResolver);
160:                } else {
161:                    builder.setEntityResolver(new WebXmlEntityResolver());
162:                }
163:                return new WebXml(builder.parse(theInput));
164:            }
165:
166:            /**
167:             * Writes the specified document to a file.
168:             * 
169:             * @param theWebXml The descriptor to serialize
170:             * @param theFile The file to write to
171:             * @throws IOException If an I/O error occurs
172:             */
173:            public static void writeWebXml(WebXml theWebXml, File theFile)
174:                    throws IOException {
175:                writeWebXml(theWebXml, theFile, null, false);
176:            }
177:
178:            /**
179:             * Writes the specified document to a file.
180:             * 
181:             * @param theWebXml The descriptor to serialize
182:             * @param theFile The file to write to
183:             * @param theEncoding The character encoding to use
184:             * @throws IOException If an I/O error occurs
185:             */
186:            public static void writeWebXml(WebXml theWebXml, File theFile,
187:                    String theEncoding) throws IOException {
188:                writeWebXml(theWebXml, theFile, theEncoding, false);
189:            }
190:
191:            /**
192:             * Writes the specified document to a file.
193:             * 
194:             * @param theWebXml The descriptor to serialize
195:             * @param theFile The file to write to
196:             * @param theEncoding The character encoding to use
197:             * @param isIndent Whether the written XML should be indented
198:             * @throws IOException If an I/O error occurs
199:             */
200:            public static void writeWebXml(WebXml theWebXml, File theFile,
201:                    String theEncoding, boolean isIndent) throws IOException {
202:                OutputStream out = null;
203:                try {
204:                    out = new FileOutputStream(theFile);
205:                    writeWebXml(theWebXml, out, theEncoding, isIndent);
206:                } finally {
207:                    if (out != null) {
208:                        try {
209:                            out.close();
210:                        } catch (IOException ioe) {
211:                            // we'll pass on the original IO error, so ignore this one
212:                        }
213:                    }
214:                }
215:            }
216:
217:            /**
218:             * Writes the specified document to an output stream.
219:             * 
220:             * @param theWebXml The descriptor to serialize
221:             * @param theOutput The output stream to write to
222:             * @param theEncoding The character encoding to use
223:             * @param isIndent Whether the written XML should be indented
224:             * @throws IOException If an I/O error occurs
225:             */
226:            public static void writeWebXml(WebXml theWebXml,
227:                    OutputStream theOutput, String theEncoding, boolean isIndent)
228:                    throws IOException {
229:                OutputFormat outputFormat = new OutputFormat(theWebXml
230:                        .getDocument());
231:                if (theEncoding != null) {
232:                    outputFormat.setEncoding(theEncoding);
233:                }
234:                outputFormat.setIndenting(isIndent);
235:                outputFormat.setPreserveSpace(false);
236:                XMLSerializer serializer = new XMLSerializer(theOutput,
237:                        outputFormat);
238:                serializer.serialize(theWebXml.getDocument());
239:            }
240:
241:        }
ww__w_._ja_va2_s_.c_om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.