Source Code Cross Referenced for XMLGenericModel.java in  » Web-Mail » jwebmail-0.7 » net » wastl » webmail » xml » 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 » Web Mail » jwebmail 0.7 » net.wastl.webmail.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* CVS ID: $Id: XMLGenericModel.java,v 1.1.1.1 2002/10/02 18:42:54 wastl Exp $ */
002:        package net.wastl.webmail.xml;
003:
004:        import java.util.*;
005:        import java.io.*;
006:
007:        import javax.xml.parsers.*;
008:
009:        import org.w3c.dom.*;
010:
011:        import net.wastl.webmail.server.*;
012:
013:        /*
014:         * XMLGenericModel.java
015:         *
016:         * Created: Thu May  4 15:53:12 2000
017:         *
018:         * Copyright (C) 2000 Sebastian Schaffert
019:         * 
020:         * This program is free software; you can redistribute it and/or
021:         * modify it under the terms of the GNU General Public License
022:         * as published by the Free Software Foundation; either version 2
023:         * of the License, or (at your option) any later version.
024:         * 
025:         * This program is distributed in the hope that it will be useful,
026:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
027:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
028:         * GNU General Public License for more details.
029:         * 
030:         * You should have received a copy of the GNU General Public License
031:         * along with this program; if not, write to the Free Software
032:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
033:         *
034:         */
035:
036:        /**
037:         * A generic representation of WebMail data. Contains mainly state information 
038:         * and the system configuration
039:         *
040:         * @author Sebastian Schaffert
041:         * @version
042:         */
043:
044:        public class XMLGenericModel {
045:
046:            protected Document root;
047:
048:            protected Element sysdata;
049:
050:            protected Element statedata;
051:
052:            protected WebMailServer parent;
053:
054:            protected long current_id = 0;
055:
056:            protected DocumentBuilder parser;
057:
058:            public XMLGenericModel(WebMailServer parent, Element rsysdata)
059:                    throws ParserConfigurationException {
060:
061:                this .parent = parent;
062:
063:                parser = DocumentBuilderFactory.newInstance()
064:                        .newDocumentBuilder();
065:
066:                initRoot();
067:
068:                statedata = root.createElement("STATEDATA");
069:
070:                NodeList nl = root.getDocumentElement().getElementsByTagName(
071:                        "STATEDATA");
072:                if (nl.getLength() > 0) {
073:                    System.err
074:                            .println("*** Warning: Webmail usermodel template contained a STATEDATA tag, although this should only be created at runtime!");
075:                    root.getDocumentElement().replaceChild(statedata,
076:                            nl.item(0));
077:                } else {
078:                    root.getDocumentElement().appendChild(statedata);
079:                }
080:
081:                this .sysdata = rsysdata;
082:
083:            }
084:
085:            protected void initRoot() {
086:                // Create a new usermodel from the template file
087:                try {
088:                    root = parser.parse("file://"
089:                            + parent.getProperty("webmail.xml.path")
090:                            + System.getProperty("file.separator")
091:                            + "generic_template.xml");
092:                } catch (Exception ex) {
093:                    System.err
094:                            .println("Error parsing WebMail UserModel template "
095:                                    + ex.getMessage());
096:                    ex.printStackTrace();
097:                }
098:            }
099:
100:            public Document getRoot() {
101:                return root;
102:            }
103:
104:            public Element getStateData() {
105:                return statedata;
106:            }
107:
108:            public void init() {
109:                setStateVar("base uri", parent.getBasePath());
110:                setStateVar("img base uri", parent.getImageBasePath() + "/"
111:                        + parent.getDefaultLocale().getLanguage() + "/"
112:                        + parent.getDefaultTheme());
113:                setStateVar("webmail version", parent.getVersion());
114:                setStateVar("operating system", System.getProperty("os.name")
115:                        + " " + System.getProperty("os.version") + "/"
116:                        + System.getProperty("os.arch"));
117:                setStateVar("java virtual machine", System
118:                        .getProperty("java.vendor")
119:                        + " "
120:                        + System.getProperty("java.vm.name")
121:                        + " "
122:                        + System.getProperty("java.version"));
123:            }
124:
125:            public void update() {
126:                // Insert the sysdata and userdata objects into the usermodel tree
127:                try {
128:                    NodeList nl = root.getElementsByTagName("SYSDATA");
129:                    root.getDocumentElement().replaceChild(
130:                            root.importNode(sysdata, true), nl.item(0));
131:                } catch (ArrayIndexOutOfBoundsException ex) {
132:                    System.err
133:                            .println("The WebMail GenericModel template file didn't contain a SYSDATA tag.");
134:                } catch (DOMException ex) {
135:                    System.err
136:                            .println("Something went wrong with the XML generic model.");
137:                }
138:            }
139:
140:            /**
141:             * Create a unique ID.
142:             * Important: This returns a new Unique ID within this session.
143:             * It should be used to generate IDs for Folders and messages so that they can be easily referenced
144:             */
145:            public String getNextID() {
146:                return Long.toHexString(++current_id).toUpperCase();
147:            }
148:
149:            public synchronized void setException(Exception ex) {
150:                Element exception = root.createElement("EXCEPTION");
151:                Element ex_message = root.createElement("EX_MESSAGE");
152:                Element ex_stacktrace = root.createElement("EX_STACKTRACE");
153:                exception.appendChild(ex_message);
154:                exception.appendChild(ex_stacktrace);
155:
156:                Text msg = root.createTextNode(ex.getMessage());
157:                ex_message.appendChild(msg);
158:
159:                String my_stack = "";
160:                CharArrayWriter cstream = new CharArrayWriter();
161:                ex.printStackTrace(new PrintWriter(cstream));
162:                my_stack = cstream.toString();
163:                CDATASection stack = root.createCDATASection(my_stack);
164:                ex_stacktrace.appendChild(stack);
165:
166:                NodeList nl = statedata.getElementsByTagName("EXCEPTION");
167:                if (nl.getLength() > 0) {
168:                    statedata.replaceChild(exception, nl.item(0));
169:                } else {
170:                    statedata.appendChild(exception);
171:                }
172:
173:                //XMLCommon.debugXML(root);
174:            }
175:
176:            /**
177:             * We need to synchronize that to avoid problems, but this should be fast anyway 
178:             */
179:            public synchronized void setStateVar(String name, String value) {
180:                Element var = XMLCommon.getElementByAttribute(statedata, "VAR",
181:                        "name", name);
182:                if (var == null) {
183:                    var = root.createElement("VAR");
184:                    var.setAttribute("name", name);
185:                    statedata.appendChild(var);
186:                }
187:                var.setAttribute("value", value);
188:            }
189:
190:            public Element createStateVar(String name, String value) {
191:                Element var = root.createElement("VAR");
192:                var.setAttribute("name", name);
193:                var.setAttribute("value", value);
194:                return var;
195:            }
196:
197:            public void addStateVar(String name, String value) {
198:                Element var = root.createElement("VAR");
199:                var.setAttribute("name", name);
200:                statedata.appendChild(var);
201:                var.setAttribute("value", value);
202:            }
203:
204:            /**
205:             * We need to synchronize that because it can cause problems with multiple threads
206:             */
207:            public synchronized void removeAllStateVars(String name) {
208:	NodeList nl=statedata.getElementsByTagName("VAR");
209:
210:	/* This suxx: NodeList Object is changed when removing children !!!
211:	   I will store all nodes that should be deleted in a Vector and delete them afterwards */
212:	int length=nl.getLength();
213:	Vector v=new Vector(nl.getLength());
214:	for(int i=0;i<length;i++) {	    
215:	    if(((Element)nl.item(i)).getAttribute("name").equals(name)) {	
216:		v.addElement(nl.item(i));
217:	    }
218:	}
219:	Enumeration enum=v.elements();
220:	while(enum.hasMoreElements()) {
221:	    Node n=(Node)enum.nextElement();
222:	    statedata.removeChild(n);
223:	}
224:    }
225:
226:            public String getStateVar(String name) {
227:                Element var = XMLCommon.getElementByAttribute(statedata, "VAR",
228:                        "name", name);
229:                if (var == null) {
230:                    return "";
231:                } else {
232:                    return var.getAttribute("value");
233:                }
234:            }
235:
236:        } // XMLGenericModel
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.