Source Code Cross Referenced for CastorXMLPreferencesPersistence.java in  » Web-Mail » Jwma » dtw » webmail » plugin » std » 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 » Jwma » dtw.webmail.plugin.std 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***
002:         * jwma Java WebMail
003:         * Copyright (c) 2000-2003 jwma team
004:         *
005:         * jwma is free software; you can distribute and use this source
006:         * under the terms of the BSD-style license received along with
007:         * the distribution.
008:         ***/package dtw.webmail.plugin.std;
009:
010:        import dtw.webmail.JwmaKernel;
011:        import dtw.webmail.JwmaSession;
012:        import dtw.webmail.model.JwmaException;
013:        import dtw.webmail.model.JwmaMailIdentityImpl;
014:        import dtw.webmail.model.JwmaPreferencesImpl;
015:        import dtw.webmail.plugin.PreferencesPersistencePlugin;
016:        import dtw.webmail.util.MD5;
017:        import dtw.webmail.util.config.JwmaConfiguration;
018:        import dtw.webmail.util.config.PostOffice;
019:        import org.apache.log4j.Logger;
020:
021:        import java.io.File;
022:        import java.io.FileReader;
023:        import java.io.FileWriter;
024:
025:        /**
026:         * A <tt>PreferencesPersistancePlugin</tt> implementation
027:         * based on Castor XML marshalling/unmarshalling.
028:         * <p>
029:         * Stores the preferences as XML files.
030:         *
031:         * @author Dieter Wimberger
032:         * @version 0.9.7 07/02/2003
033:         */
034:        public class CastorXMLPreferencesPersistence implements 
035:                PreferencesPersistencePlugin {
036:
037:            //logging
038:            private static Logger log = Logger
039:                    .getLogger(CastorXMLPreferencesPersistence.class);
040:
041:            //Preferences
042:            private String m_PreferencesTemplateFile; //preferences template file
043:            private String m_PreferencesMappingFile; //object <-> xml mapping file (Castor)
044:            private String m_DataDir;
045:            private CastorPreferences m_PreferencesTemplate;
046:
047:            public JwmaPreferencesImpl loadPreferences(String identity)
048:                    throws JwmaException {
049:
050:                JwmaPreferencesImpl prefs = null;
051:
052:                try {
053:                    String filename = getFilename(identity);
054:                    File f = new File(filename);
055:                    FileReader reader = null;
056:
057:                    if (f.isAbsolute()) {
058:                        reader = new FileReader(f);
059:                    } else {
060:                        reader = new FileReader(m_DataDir + filename);
061:                    }
062:
063:                    prefs = (CastorPreferences) CastorHelper.getReference()
064:                            .unmarshal(reader);
065:
066:                    reader.close();
067:                } catch (Exception ex) {
068:                    throw new JwmaException("jwma.plugin.std", true)
069:                            .setException(ex);
070:                }
071:                return prefs;
072:            }//loadPreferences
073:
074:            public void savePreferences(JwmaPreferencesImpl prefs)
075:                    throws JwmaException {
076:
077:                try {
078:                    String filename = getFilename(prefs.getUserIdentity());
079:                    FileWriter writer = new FileWriter(m_DataDir + filename);
080:                    CastorHelper.getReference().marshal(prefs, writer);
081:                    writer.close();
082:                } catch (Exception ex) {
083:                    throw new JwmaException("").setException(ex);
084:                }
085:            }//savePreferences
086:
087:            public boolean isPersistent(String identity) throws JwmaException {
088:                try {
089:                    File file = new File(m_DataDir + getFilename(identity));
090:                    return file.exists();
091:                } catch (Exception ex) {
092:                    throw new JwmaException("").setException(ex);
093:                }
094:            }//isPersistent
095:
096:            public JwmaPreferencesImpl getPreferencesTemplate(
097:                    JwmaSession session) {
098:
099:                //1. get clone
100:                JwmaPreferencesImpl prefs = m_PreferencesTemplate.getClone();
101:
102:                //2. make post office config dependent adjustments:
103:                PostOffice po = session.getPostOffice();
104:
105:                //set root folder
106:                prefs.setRootFolder(po.getRootFolder());
107:
108:                //set replyto domain from postoffice
109:                String replyto = po.getReplyToDomain();
110:                if (replyto == null || replyto.length() == 0) {
111:                    replyto = po.getAddress();
112:                }
113:
114:                ((JwmaMailIdentityImpl) prefs.getMailIdentity())
115:                        .setReplyTo(session.getUsername() + "@" + replyto);
116:
117:                return prefs;
118:            }//getPreferencesTemplate
119:
120:            public void activate() throws JwmaException {
121:                try {
122:                    JwmaKernel kernel = JwmaKernel.getReference();
123:                    String etc = kernel.getDirectoryPath(JwmaKernel.ETC_DIR);
124:
125:                    //String m_MappingFile = etc + settings.getMappingFilename();
126:                    m_PreferencesTemplateFile = etc
127:                            + JwmaConfiguration.TEMPLATE_FILENAME;
128:                    m_DataDir = kernel.getDirectoryPath(JwmaKernel.DATA_DIR);
129:
130:                    //Setup castor helper
131:                    CastorHelper helper = CastorHelper.getReference();
132:
133:                    //load mapping
134:                    //helper.loadMapping(m_MappingFile);
135:
136:                    //load the template
137:                    m_PreferencesTemplate = (CastorPreferences) helper
138:                            .unmarshal(new FileReader(m_PreferencesTemplateFile));
139:
140:                    log.info(JwmaKernel.getReference().getLogMessage(
141:                            "jwma.plugin.activation"));
142:                } catch (Exception ex) {
143:                    log.info(JwmaKernel.getReference().getLogMessage(
144:                            "jwma.plugin.failedactivation"));
145:                    if (ex instanceof  JwmaException) {
146:                        throw (JwmaException) ex;
147:                    }
148:                    throw new JwmaException("").setException(ex);
149:                }
150:            }//activate
151:
152:            public void deactivate() {
153:                //nothing important
154:            }//deactivate
155:
156:            public void setPreferencesTemplate(JwmaPreferencesImpl template)
157:                    throws JwmaException {
158:
159:                //set the reference immediately
160:                m_PreferencesTemplate = (CastorPreferences) template;
161:                //store
162:                try {
163:                    FileWriter writer = new FileWriter(
164:                            m_PreferencesTemplateFile);
165:                    CastorHelper.getReference().marshal(template, writer);
166:                    writer.close();
167:                } catch (Exception ex) {
168:                    throw new JwmaException("").setException(ex);
169:                }
170:            }//setPreferencesTemplate
171:
172:            private String getFilename(String identity) {
173:                return MD5.hash(identity) + ".xml";
174:            }//getFileName
175:
176:        }//class CastorXMLPreferencesPersistence
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.