Source Code Cross Referenced for IncludeXML.java in  » Workflow-Engines » wfmopen-2.1.1 » de » danet » an » workflow » 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 » Workflow Engines » wfmopen 2.1.1 » de.danet.an.workflow.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the WfMOpen project.
003:         * Copyright (C) 2001-2005 Danet GmbH (www.danet.de), BU-TEL.
004:         * All rights reserved.
005:         *
006:         * This program is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU General Public License as published by
008:         * the Free Software Foundation; either version 2 of the License, or
009:         * (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * $Id: IncludeXML.java,v 1.4 2007/03/27 21:59:44 mlipp Exp $
021:         *
022:         * $Log: IncludeXML.java,v $
023:         * Revision 1.4  2007/03/27 21:59:44  mlipp
024:         * Fixed lots of checkstyle warnings.
025:         *
026:         * Revision 1.3  2006/09/29 12:32:10  drmlipp
027:         * Consistently using WfMOpen as projct name now.
028:         *
029:         * Revision 1.2  2005/04/28 11:14:51  drmlipp
030:         * Added filter option.
031:         *
032:         * Revision 1.1  2005/04/27 09:25:17  drmlipp
033:         * Added utility for including XML in process description.
034:         *
035:         */
036:        package de.danet.an.workflow.util;
037:
038:        import java.io.FileInputStream;
039:        import java.io.FileOutputStream;
040:        import java.io.IOException;
041:        import java.io.StringWriter;
042:
043:        import javax.xml.parsers.ParserConfigurationException;
044:        import javax.xml.parsers.SAXParser;
045:        import javax.xml.parsers.SAXParserFactory;
046:        import javax.xml.transform.OutputKeys;
047:        import javax.xml.transform.TransformerConfigurationException;
048:        import javax.xml.transform.TransformerFactory;
049:        import javax.xml.transform.sax.SAXTransformerFactory;
050:        import javax.xml.transform.sax.TransformerHandler;
051:        import javax.xml.transform.stream.StreamResult;
052:
053:        import org.xml.sax.Attributes;
054:        import org.xml.sax.InputSource;
055:        import org.xml.sax.SAXException;
056:        import org.xml.sax.XMLReader;
057:        import org.xml.sax.helpers.AttributesImpl;
058:        import org.xml.sax.helpers.XMLFilterImpl;
059:
060:        /**
061:         * This class provides ...
062:         *
063:         * @author <a href="mailto:lipp@danet.de">unknown</a>
064:         * @version $Revision: 1.4 $
065:         */
066:
067:        public class IncludeXML {
068:
069:            private class IncludeHandler extends XMLFilterImpl {
070:
071:                /**
072:                 * @see org.xml.sax.ContentHandler#characters
073:                 */
074:                public void characters(char[] chars, int start, int end)
075:                        throws SAXException {
076:                    String text = new String(chars, start, end);
077:                    if (text.startsWith("%include(")
078:                            && text.indexOf(')') == text.length() - 1) {
079:                        String fn = text.substring(9, text.length() - 1);
080:                        System.out.println("Including " + fn + " ...");
081:                        String tbi = null;
082:                        try {
083:                            tbi = xmlFileAsString(fn);
084:                        } catch (Exception e) {
085:                            System.out.println("Cannot include " + fn + ": "
086:                                    + e.getMessage());
087:                            throw new SAXException(e);
088:                        }
089:                        super .characters(tbi.toCharArray(), 0, tbi
090:                                .toCharArray().length);
091:                        return;
092:                    }
093:                    super .characters(chars, start, end);
094:                }
095:            }
096:
097:            private class IncludeFilter extends XMLFilterImpl {
098:
099:                /** 
100:                 * @see org.xml.sax.ContentHandler#startElement
101:                 */
102:                public void startElement(String namespaceURI, String localName,
103:                        String qName, Attributes atts) throws SAXException {
104:                    if (vxmlXsiFilter
105:                            && namespaceURI
106:                                    .equals("http://www.w3.org/2001/vxml")
107:                            && localName.equals("vxml")) {
108:                        AttributesImpl a = new AttributesImpl(atts);
109:                        for (int i = 0; i < a.getLength(); i++) {
110:                            if (a.getQName(i).startsWith("xmlns:")
111:                                    && (a.getValue(i)
112:                                            .equals("http://www.w3.org/2001/XMLSchema-instance"))) {
113:                                a.removeAttribute(i);
114:                                i -= 1;
115:                                continue;
116:                            }
117:                            if (a
118:                                    .getURI(i)
119:                                    .equals(
120:                                            "http://www.w3.org/2001/XMLSchema-instance")) {
121:                                a.removeAttribute(i);
122:                                i -= 1;
123:                                continue;
124:                            }
125:                        }
126:                        atts = a;
127:                    }
128:                    super .startElement(namespaceURI, localName, qName, atts);
129:                }
130:            }
131:
132:            private String inFileName = null;
133:            private String outFileName = null;
134:            private boolean vxmlXsiFilter = false;
135:
136:            private SAXParserFactory spf = SAXParserFactory.newInstance();
137:            private SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactory
138:                    .newInstance();
139:
140:            private String xmlFileAsString(String fileName) throws IOException,
141:                    TransformerConfigurationException,
142:                    ParserConfigurationException, SAXException {
143:                TransformerHandler serializer = stf.newTransformerHandler();
144:                serializer.getTransformer().setOutputProperty(
145:                        OutputKeys.INDENT, "no");
146:                serializer.getTransformer().setOutputProperty(
147:                        OutputKeys.OMIT_XML_DECLARATION, "yes");
148:                StringWriter res = new StringWriter();
149:                serializer.setResult(new StreamResult(res));
150:
151:                SAXParser sp = spf.newSAXParser();
152:                XMLReader reader = sp.getXMLReader();
153:
154:                IncludeFilter incf = new IncludeFilter();
155:                incf.setContentHandler(serializer);
156:                incf.setDTDHandler(serializer);
157:
158:                reader.setContentHandler(incf);
159:                reader.setDTDHandler(incf);
160:                reader.setFeature("http://xml.org/sax/features/namespaces",
161:                        true);
162:                reader.parse(new InputSource(new FileInputStream(fileName)));
163:                return res.toString();
164:            }
165:
166:            private void parseArgs(String[] args) {
167:                for (int i = 0; i < args.length; i++) {
168:                    if (args[i].startsWith("-")) {
169:                        if (args[i].equals("-vxmlXsiFilter")) {
170:                            vxmlXsiFilter = true;
171:                        }
172:                    } else {
173:                        if (inFileName == null) {
174:                            inFileName = args[i];
175:                        } else if (outFileName == null) {
176:                            outFileName = args[i];
177:                        }
178:                    }
179:                }
180:            }
181:
182:            public void run(String[] args) throws Exception {
183:                parseArgs(args);
184:
185:                // prepare output transformer
186:                TransformerHandler serializer = stf.newTransformerHandler();
187:                serializer.getTransformer().setOutputProperty(
188:                        OutputKeys.ENCODING, "ISO-8859-1");
189:                serializer.getTransformer().setOutputProperty(
190:                        OutputKeys.INDENT, "yes");
191:                serializer.setResult(new StreamResult(new FileOutputStream(
192:                        outFileName)));
193:
194:                IncludeHandler ih = new IncludeHandler();
195:                ih.setContentHandler(serializer);
196:                ih.setDTDHandler(serializer);
197:
198:                SAXParser sp = spf.newSAXParser();
199:                XMLReader reader = sp.getXMLReader();
200:                reader.setContentHandler(ih);
201:                reader.setDTDHandler(ih);
202:                reader.parse(new InputSource(new FileInputStream(inFileName)));
203:
204:                // 	var tf = Packages.javax.xml.transform.TransformerFactory.newInstance();
205:                // 	var t = tf.newTransformer();
206:                // 	var xmlString = new java.io.StringWriter();
207:                // 	t.transform(new Packages.javax.xml.transform.stream.StreamSource(inFile),
208:                // 		    new Packages.javax.xml.transform.stream.StreamResult(xmlString));
209:
210:            }
211:
212:            public static void main(String[] args) throws Exception {
213:                try {
214:                    (new IncludeXML()).run(args);
215:                } catch (Exception e) {
216:                    e.printStackTrace();
217:                }
218:            }
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.