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


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2003-2005 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.application;
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.xml.sax.EntityResolver;
036:        import org.xml.sax.InputSource;
037:        import org.xml.sax.SAXException;
038:
039:        /**
040:         * Provides convenience methods for reading and writing enterprise application
041:         * deployment descriptors (application.xml).
042:         *
043:         * @since Cactus 1.5
044:         * @version $Id: ApplicationXmlIo.java 239141 2005-02-15 10:31:44Z vmassol $
045:         */
046:        public class ApplicationXmlIo {
047:
048:            // Inner Classes -----------------------------------------------------------
049:
050:            /**
051:             * Implementation of the SAX EntityResolver interface that looks up the
052:             * application DTDs from the JAR.
053:             */
054:            private static class ApplicationXmlEntityResolver implements 
055:                    EntityResolver {
056:
057:                /**
058:                 * @see org.xml.sax.EntityResolver#resolveEntity
059:                 */
060:                public InputSource resolveEntity(String thePublicId,
061:                        String theSystemId) throws SAXException, IOException {
062:                    ApplicationXmlVersion version = ApplicationXmlVersion
063:                            .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:             * Parses a deployment descriptor stored in a regular file.
083:             * 
084:             * @param theFile The file to parse
085:             * @param theEntityResolver A SAX entity resolver, or <code>null</code> to
086:             *        use the default
087:             * @return The parsed descriptor
088:             * @throws SAXException If the file could not be parsed
089:             * @throws ParserConfigurationException If the XML parser was not correctly
090:             *          configured
091:             * @throws IOException If an I/O error occurs
092:             */
093:            public static ApplicationXml parseApplicationXmlFromFile(
094:                    File theFile, EntityResolver theEntityResolver)
095:                    throws SAXException, ParserConfigurationException,
096:                    IOException {
097:                InputStream in = null;
098:                try {
099:                    in = new FileInputStream(theFile);
100:                    return parseApplicationXml(in, theEntityResolver);
101:                } finally {
102:                    if (in != null) {
103:                        try {
104:                            in.close();
105:                        } catch (IOException ioe) {
106:                            // we'll pass on the original IO error, so ignore this one
107:                        }
108:                    }
109:                }
110:            }
111:
112:            /**
113:             * Parses a deployment descriptor provided as input stream.
114:             * 
115:             * @param theInput The input stream
116:             * @param theEntityResolver A SAX entity resolver, or <code>null</code> to
117:             *        use the default
118:             * @return The parsed descriptor
119:             * @throws SAXException If the input could not be parsed
120:             * @throws ParserConfigurationException If the XML parser was not correctly
121:             *          configured
122:             * @throws IOException If an I/O error occurs
123:             */
124:            public static ApplicationXml parseApplicationXml(
125:                    InputStream theInput, EntityResolver theEntityResolver)
126:                    throws SAXException, ParserConfigurationException,
127:                    IOException {
128:                DocumentBuilderFactory factory = DocumentBuilderFactory
129:                        .newInstance();
130:                factory.setValidating(false);
131:                factory.setNamespaceAware(false);
132:                DocumentBuilder builder = factory.newDocumentBuilder();
133:                if (theEntityResolver != null) {
134:                    builder.setEntityResolver(theEntityResolver);
135:                } else {
136:                    builder
137:                            .setEntityResolver(new ApplicationXmlEntityResolver());
138:                }
139:                return new DefaultApplicationXml(builder.parse(theInput));
140:            }
141:
142:            /**
143:             * Writes the specified document to a file.
144:             * 
145:             * @param theAppXml The descriptor to serialize
146:             * @param theFile The file to write to
147:             * @throws IOException If an I/O error occurs
148:             */
149:            public static void writeApplicationXml(ApplicationXml theAppXml,
150:                    File theFile) throws IOException {
151:                writeApplicationXml(theAppXml, theFile, null, false);
152:            }
153:
154:            /**
155:             * Writes the specified document to a file.
156:             * 
157:             * @param theAppXml The descriptor to serialize
158:             * @param theFile The file to write to
159:             * @param theEncoding The character encoding to use
160:             * @throws IOException If an I/O error occurs
161:             */
162:            public static void writeApplicationXml(ApplicationXml theAppXml,
163:                    File theFile, String theEncoding) throws IOException {
164:                writeApplicationXml(theAppXml, theFile, theEncoding, false);
165:            }
166:
167:            /**
168:             * Writes the specified document to a file.
169:             * 
170:             * @param theAppXml The descriptor to serialize
171:             * @param theFile The file to write to
172:             * @param theEncoding The character encoding to use
173:             * @param isIndent Whether the written XML should be indented
174:             * @throws IOException If an I/O error occurs
175:             */
176:            public static void writeApplicationXml(ApplicationXml theAppXml,
177:                    File theFile, String theEncoding, boolean isIndent)
178:                    throws IOException {
179:                OutputStream out = null;
180:                try {
181:                    out = new FileOutputStream(theFile);
182:                    writeApplicationXml(theAppXml, out, theEncoding, isIndent);
183:                } finally {
184:                    if (out != null) {
185:                        try {
186:                            out.close();
187:                        } catch (IOException ioe) {
188:                            // we'll pass on the original IO error, so ignore this one
189:                        }
190:                    }
191:                }
192:            }
193:
194:            /**
195:             * Writes the specified document to an output stream.
196:             * 
197:             * @param theAppXml The descriptor to serialize
198:             * @param theOutput The output stream to write to
199:             * @param theEncoding The character encoding to use
200:             * @param isIndent Whether the written XML should be indented
201:             * @throws IOException If an I/O error occurs
202:             */
203:            public static void writeApplicationXml(ApplicationXml theAppXml,
204:                    OutputStream theOutput, String theEncoding, boolean isIndent)
205:                    throws IOException {
206:                OutputFormat outputFormat = new OutputFormat(theAppXml
207:                        .getDocument());
208:                if (theEncoding != null) {
209:                    outputFormat.setEncoding(theEncoding);
210:                }
211:                outputFormat.setIndenting(isIndent);
212:                outputFormat.setPreserveSpace(false);
213:                XMLSerializer serializer = new XMLSerializer(theOutput,
214:                        outputFormat);
215:                serializer.serialize(theAppXml.getDocument());
216:            }
217:
218:        }
w__w___w___._j_a_v_a___2___s___.___c__o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.