Source Code Cross Referenced for XMLMessagePart.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: XMLMessagePart.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:
006:        import org.w3c.dom.*;
007:
008:        /*
009:         * XMLMessagePart.java
010:         *
011:         * Created: Tue Apr 18 14:08:56 2000
012:         *
013:         * Copyright (C) 2000 Sebastian Schaffert
014:         * 
015:         * This program is free software; you can redistribute it and/or
016:         * modify it under the terms of the GNU General Public License
017:         * as published by the Free Software Foundation; either version 2
018:         * of the License, or (at your option) any later version.
019:         * 
020:         * This program is distributed in the hope that it will be useful,
021:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
022:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023:         * GNU General Public License for more details.
024:         * 
025:         * You should have received a copy of the GNU General Public License
026:         * along with this program; if not, write to the Free Software
027:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
028:         *
029:         */
030:
031:        /**
032:         * A message part object for an XML message
033:         */
034:        public class XMLMessagePart {
035:
036:            protected Document root;
037:            protected Element part;
038:
039:            /**
040:             * Create a new part for the given root document.
041:             * Creates the necessary Element.
042:             */
043:            public XMLMessagePart(Document root) {
044:                this .part = root.createElement("PART");
045:                this .root = root;
046:            }
047:
048:            /**
049:             * Return a new part for a given part element
050:             */
051:            public XMLMessagePart(Element part) {
052:                this .part = part;
053:                this .root = part.getOwnerDocument();
054:            }
055:
056:            public Element getPartElement() {
057:                return part;
058:            }
059:
060:            public void setAttribute(String key, String value) {
061:                part.setAttribute(key, value);
062:            }
063:
064:            public String getAttribute(String key) {
065:                return part.getAttribute(key);
066:            }
067:
068:            public void quoteContent() {
069:                NodeList nl = part.getChildNodes();
070:                StringBuffer text = new StringBuffer();
071:                for (int i = 0; i < nl.getLength(); i++) {
072:                    Element elem = (Element) nl.item(i);
073:                    if (elem.getNodeName().equals("CONTENT")) {
074:                        String value = XMLCommon.getElementTextValue(elem);
075:                        StringTokenizer tok = new StringTokenizer(value, "\n");
076:                        while (tok.hasMoreTokens()) {
077:                            text.append("> ").append(tok.nextToken()).append(
078:                                    "\n");
079:                        }
080:                    }
081:                }
082:                removeAllContent();
083:
084:                addContent(text.toString(), 0);
085:            }
086:
087:            /**
088:             * This method is designed for content that already is in DOM format, like HTML
089:             * messages.
090:             */
091:            public void addContent(Document content) {
092:                Element content_elem = root.createElement("CONTENT");
093:                content_elem.setAttribute("quotelevel", "0");
094:
095:                /* Find all <BODY> elements and add the child nodes to the content */
096:                for (int count = 0; count < 2; count++) {
097:                    NodeList nl = content.getDocumentElement()
098:                            .getElementsByTagName(count == 0 ? "BODY" : "body");
099:                    System.err.println("While parsing HTML content: Found "
100:                            + nl.getLength() + " body elements");
101:                    for (int i = 0; i < nl.getLength(); i++) {
102:                        NodeList nl2 = nl.item(i).getChildNodes();
103:                        System.err.println("While parsing HTML content: Found "
104:                                + nl2.getLength() + " child elements");
105:                        for (int j = 0; j < nl2.getLength(); j++) {
106:                            System.err.println("Element: " + j);
107:                            content_elem.appendChild(XMLCommon.importNode(root,
108:                                    nl2.item(j), true));
109:                        }
110:                    }
111:                }
112:
113:                part.appendChild(content_elem);
114:
115:                //XMLCommon.debugXML(root);
116:            }
117:
118:            public void addContent(String content, int quotelevel) {
119:                Element content_elem = root.createElement("CONTENT");
120:                content_elem.setAttribute("quotelevel", quotelevel + "");
121:                XMLCommon.setElementTextValue(content_elem, content, true);
122:                part.appendChild(content_elem);
123:            }
124:
125:            public void insertContent(String content, int quotelevel) {
126:                Element content_elem = root.createElement("CONTENT");
127:                content_elem.setAttribute("quotelevel", quotelevel + "");
128:                XMLCommon.setElementTextValue(content_elem, content, true);
129:                Node first = part.getFirstChild();
130:                part.insertBefore(content_elem, first);
131:            }
132:
133:            public void addJavaScript(String content) {
134:                Element javascript_elem = root.createElement("JAVASCRIPT");
135:                XMLCommon.setElementTextValue(javascript_elem, content, true);
136:                part.appendChild(javascript_elem);
137:            }
138:
139:            public void removeAllContent() {
140:                XMLCommon.genericRemoveAll(part, "CONTENT");
141:            }
142:
143:            public XMLMessagePart createPart(String type) {
144:                XMLMessagePart newpart = new XMLMessagePart(root);
145:                newpart.setAttribute("type", type);
146:                appendPart(newpart);
147:                return newpart;
148:            }
149:
150:            public void insertPart(XMLMessagePart childpart) {
151:                Node first = part.getFirstChild();
152:                part.insertBefore(childpart.getPartElement(), first);
153:            }
154:
155:            public void appendPart(XMLMessagePart childpart) {
156:                part.appendChild(childpart.getPartElement());
157:            }
158:
159:            public Enumeration getParts() {
160:                // Sucking NodeList needs a Vector to store Elements that will be removed!
161:                Vector v = new Vector();
162:                NodeList parts = part.getChildNodes();
163:                for (int j = 0; j < parts.getLength(); j++) {
164:                    Element elem = (Element) parts.item(j);
165:                    if (elem.getTagName().equals("PART")) {
166:                        v.addElement(new XMLMessagePart(elem));
167:                    }
168:                }
169:                return v.elements();
170:            }
171:
172:            public void removePart(XMLMessagePart childpart) {
173:                part.removeChild(childpart.getPartElement());
174:            }
175:
176:            public void removeAllParts() {
177:                XMLCommon.genericRemoveAll(part, "PART");
178:            }
179:
180:        } // XMLMessagePart
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.