Source Code Cross Referenced for EventsXMLHelper.java in  » Workflow-Engines » Bossa » com » bigbross » bossa » io » 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 » Bossa » com.bigbross.bossa.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Bossa Workflow System
003:         *
004:         * $Id: EventsXMLHelper.java,v 1.1 2004/03/15 22:20:31 gdvieira Exp $
005:         *
006:         * Copyright (C) 2004 OpenBR Sistemas S/C Ltda.
007:         *
008:         * This file is part of Bossa.
009:         *
010:         * Bossa is free software; you can redistribute it and/or modify it
011:         * under the terms of version 2 of the GNU General Public License as
012:         * published by the Free Software Foundation.
013:         *
014:         * This program is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
017:         * General Public License for more details.
018:         *
019:         * You should have received a copy of the GNU General Public
020:         * License along with this program; if not, write to the
021:         * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
022:         * Boston, MA 02111-1307, USA.
023:         */
024:
025:        package com.bigbross.bossa.io;
026:
027:        import java.io.BufferedOutputStream;
028:        import java.io.FileNotFoundException;
029:        import java.io.FileOutputStream;
030:        import java.io.IOException;
031:        import java.io.OutputStream;
032:        import java.util.Iterator;
033:        import java.util.List;
034:        import java.util.Map;
035:
036:        import javax.xml.transform.OutputKeys;
037:        import javax.xml.transform.Transformer;
038:        import javax.xml.transform.TransformerConfigurationException;
039:        import javax.xml.transform.sax.SAXTransformerFactory;
040:        import javax.xml.transform.sax.TransformerHandler;
041:        import javax.xml.transform.stream.StreamResult;
042:
043:        import org.xml.sax.SAXException;
044:        import org.xml.sax.helpers.AttributesImpl;
045:
046:        import com.bigbross.bossa.notify.Event;
047:
048:        /**
049:         * This class provides a static method to convert an event list to a
050:         * XML encoded file. <p>
051:         *
052:         * The XML encoding is as follows:
053:         * <pre>&lt;events>
054:         *  &lt;event>
055:         *   &lt;id>open_work_item&lt;/id>
056:         *   &lt;time>1071696763305&lt;/time>
057:         *   &lt;attribute id="case_type_id">purchase&lt;/attribute>
058:         *   &lt;attribute id="resource_id">joedoe&lt;/attribute>
059:         *   &lt;attribute id="case_id">1&lt;/attribute>
060:         *   &lt;attribute id="work_item_id">check_price&lt;/attribute>
061:         *  &lt;/event>
062:         * &lt;/events></pre>
063:         * 
064:         * The <code>events</code> element is used to group a list of events.
065:         * The <code>event</code> element represents a single event and it is
066:         * composed by a single <code>id</code> element, a single <code>time</code>
067:         * element and zero or more <code>attribute</code> elements. <p>
068:         * 
069:         * The <code>id</code> element contains the id of the event. The
070:         * <code>time</code> element contains the time of the event as the
071:         * number of milliseconds since January 1, 1970, 00:00:00 GMT. Each
072:         * <code>attribute</code> element represents one attribute mapping of
073:         * the event. <p> 
074:         *
075:         * @author <a href="http://www.bigbross.com">BigBross Team</a>
076:         */
077:        public class EventsXMLHelper {
078:
079:            /**
080:             * Converts the provided event list to a XML file. If the file exists,
081:             * it will be overwritten. <p>
082:             * 
083:             * @param events the events to be exported.
084:             * @param file the name of the file.
085:             * @throws DataTransferException if an error happens during the export.
086:             */
087:            public static void export(List events, String file)
088:                    throws DataTransferException {
089:                try {
090:                    SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory
091:                            .newInstance();
092:                    TransformerHandler handler = factory
093:                            .newTransformerHandler();
094:                    Transformer transformer = handler.getTransformer();
095:                    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
096:                    OutputStream out = new BufferedOutputStream(
097:                            new FileOutputStream(file));
098:                    StreamResult streamResult = new StreamResult(out);
099:                    handler.setResult(streamResult);
100:
101:                    AttributesImpl atb = new AttributesImpl();
102:                    handler.startDocument();
103:                    handler.startElement("", "", "events", atb);
104:                    for (Iterator i = events.iterator(); i.hasNext();) {
105:                        Event e = (Event) i.next();
106:                        String id = e.getId();
107:                        String time = Long.toString(e.getTime().getTime());
108:                        atb.clear();
109:                        handler.startElement("", "", "event", atb);
110:                        handler.startElement("", "", "id", atb);
111:                        handler.characters(id.toCharArray(), 0, id.length());
112:                        handler.endElement("", "", "id");
113:                        handler.startElement("", "", "time", atb);
114:                        handler
115:                                .characters(time.toCharArray(), 0, time
116:                                        .length());
117:                        handler.endElement("", "", "time");
118:                        for (Iterator j = e.getAttributes().entrySet()
119:                                .iterator(); j.hasNext();) {
120:                            Map.Entry entry = (Map.Entry) j.next();
121:                            String propId = (String) entry.getKey();
122:                            String propValue = (String) entry.getValue();
123:                            atb.clear();
124:                            atb.addAttribute("", "", "id", "CDATA", propId);
125:                            handler.startElement("", "", "attribute", atb);
126:                            handler.characters(propValue.toCharArray(), 0,
127:                                    propValue.length());
128:                            handler.endElement("", "", "attribute");
129:                        }
130:                        handler.endElement("", "", "event");
131:                    }
132:                    handler.endElement("", "", "events");
133:                    handler.endDocument();
134:                    out.close();
135:                } catch (FileNotFoundException e) {
136:                    throw new DataTransferException("File not found.", e);
137:                } catch (IOException e) {
138:                    throw new DataTransferException("I/O error.", e);
139:                } catch (TransformerConfigurationException e) {
140:                    throw new DataTransferException(
141:                            "Unable to start XML exporter.", e);
142:                } catch (SAXException e) {
143:                    throw new DataTransferException("Error creating XML.", e);
144:                }
145:            }
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.