Source Code Cross Referenced for PropertiesDPUserContext.java in  » Portal » Open-Portal » com » sun » portal » desktop » context » 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 » Portal » Open Portal » com.sun.portal.desktop.context 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved. 
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms. 
004:         */
005:        package com.sun.portal.desktop.context;
006:
007:        import java.util.Properties;
008:        import java.io.FileInputStream;
009:        import java.io.File;
010:        import java.io.IOException;
011:        import java.io.BufferedReader;
012:        import java.io.FileReader;
013:        import java.io.FilenameFilter;
014:        import java.io.BufferedWriter;
015:        import java.io.FileWriter;
016:        import java.io.StringReader;
017:
018:        import java.util.Set;
019:        import java.util.HashSet;
020:        import com.iplanet.sso.SSOToken;
021:        import javax.servlet.http.HttpServletRequest;
022:
023:        public class PropertiesDPUserContext implements  DPUserContext {
024:
025:            protected static final String DEFAULT_FILENAME = "/etc/opt/SUNWportal/dp-user-context.properties";
026:
027:            protected static final String DOCUMENTPATH_KEY = "documentPath";
028:
029:            protected DesktopContext desktopContext = null;
030:            protected Properties properties = null;
031:            protected static FilenameFilter dpFilenameFilter = new DPDocumentFilenameFilter();
032:
033:            public PropertiesDPUserContext() {
034:                this (DEFAULT_FILENAME);
035:            }
036:
037:            public PropertiesDPUserContext(String filename) {
038:                properties = new Properties();
039:
040:                FileInputStream fis = null;
041:                try {
042:                    fis = new FileInputStream(new File(filename));
043:                    properties.load(fis);
044:                } catch (IOException ioe) {
045:                    throw new ContextError(
046:                            "PropertiesDPContext.PropertiesDPContext()", ioe);
047:                }
048:            }
049:
050:            public void init(HttpServletRequest req) {
051:                desktopContext = DesktopContextThreadLocalizer.get();
052:
053:                if (desktopContext == null) {
054:                    throw new ContextError(
055:                            "PropertiesDPContext.init(): desktop context was null");
056:                }
057:            }
058:
059:            public void init(SSOToken ssoToken) {
060:                desktopContext = DesktopContextThreadLocalizer.get();
061:                if (desktopContext == null) {
062:                    throw new ContextError(
063:                            "PropertiesDPContext.init(): desktop context was null");
064:                }
065:            }
066:
067:            public void init(HttpServletRequest req, String uid, String pw) {
068:                desktopContext = DesktopContextThreadLocalizer.get();
069:                if (desktopContext == null) {
070:                    throw new ContextError(
071:                            "PropertiesDPContext.init(): desktop context was null");
072:                }
073:            }
074:
075:            protected DesktopContext getDesktopContext() {
076:                return desktopContext;
077:            }
078:
079:            public Set getDPDocumentNames() {
080:                File docPath = new File(getDPDocumentPath());
081:
082:                File[] dpDocuments = docPath.listFiles(dpFilenameFilter);
083:
084:                Set names = new HashSet();
085:
086:                for (int i = 0; i < dpDocuments.length; i++) {
087:                    File f = dpDocuments[i];
088:                    names.add(f.toString());
089:                }
090:                return names;
091:            }
092:
093:            public String getDPDocument(String name) {
094:                File f = new File(name);
095:                return readFile(f).toString();
096:            }
097:
098:            public byte[] getDPUserDocument() {
099:                String path = getDPDocumentPath();
100:
101:                if (path == null) {
102:                    throw new ContextError(
103:                            "DPContext.getDPUserDocument(): path was null");
104:                }
105:
106:                File f = new File(path, "dp-user.xml");
107:
108:                if (!f.exists()) {
109:                    return null;
110:                }
111:                if (!f.canRead()) {
112:                    return null;
113:                }
114:
115:                StringBuffer buf = readFile(f);
116:
117:                return buf.toString().getBytes();
118:            }
119:
120:            public void storeDPUserDocument(String dp) {
121:
122:                String path = getDPDocumentPath();
123:                if (path == null) {
124:                    throw new ContextError("DPContext.getDPUserDocument(): "
125:                            + "path was null");
126:                }
127:                File f = new File(path, "dp-user.xml");
128:                writeFile(f, dp);
129:            }
130:
131:            protected StringBuffer readFile(File f) {
132:                if (!f.canRead()) {
133:                    throw new ContextError(
134:                            "PropertiesDPContext.readFile(): cannot read file: "
135:                                    + f);
136:                }
137:
138:                StringBuffer buf = new StringBuffer();
139:
140:                try {
141:                    BufferedReader br = new BufferedReader(new FileReader(f));
142:
143:                    String line = null;
144:
145:                    while ((line = br.readLine()) != null) {
146:                        buf.append(line);
147:                    }
148:                    br.close();
149:                } catch (IOException ioe) {
150:                    throw new ContextError("PropertiesDPContext.readFile(): ",
151:                            ioe);
152:                }
153:
154:                return buf;
155:            }
156:
157:            protected void writeFile(File f, String s) {
158:
159:                if (!f.exists()) {
160:                    try {
161:                        f.createNewFile();
162:                    } catch (IOException ioe) {
163:                        throw new ContextError(
164:                                "PropertiesDPContext.writeFile(): "
165:                                        + "failed to create file: " + f, ioe);
166:                    }
167:                }
168:
169:                if (!f.canWrite()) {
170:                    throw new ContextError("PropertiesDPContext.writeFile(): "
171:                            + "cannot write to file: " + f);
172:                }
173:
174:                try {
175:                    BufferedReader br = new BufferedReader(new StringReader(s));
176:                    BufferedWriter bw = new BufferedWriter(new FileWriter(f));
177:                    String line = null;
178:                    while ((line = br.readLine()) != null) {
179:                        bw.write(line);
180:                        bw.newLine();
181:                    }
182:                    bw.flush();
183:                    bw.close();
184:                    br.close();
185:                } catch (IOException ioe) {
186:                    throw new ContextError("PropertiesDPContext.writeFile(): ",
187:                            ioe);
188:                }
189:            }
190:
191:            public long getDPUserDocumentLastModified() {
192:                return -1;
193:            }
194:
195:            public long getDPDocumentLastModified(String name) {
196:                return -1;
197:            }
198:
199:            public long getDPUserDocumentLastRead() {
200:                return -1;
201:            }
202:
203:            public long getDPDocumentLastRead(String name) {
204:                return -1;
205:            }
206:
207:            protected String getDPDocumentPath() {
208:                String filename = properties.getProperty(DOCUMENTPATH_KEY);
209:
210:                return filename;
211:            }
212:
213:            protected void setDPUserDocumentLastModified() {
214:            }
215:
216:            protected void setDPUserDocumentLastRead() {
217:            }
218:
219:            protected void setDPDocumentLastRead(String name) {
220:            }
221:
222:            private static class DPDocumentFilenameFilter implements 
223:                    FilenameFilter {
224:                public boolean accept(File dir, String name) {
225:                    if (name.equals("dp-user.xml")) {
226:                        //
227:                        // skip the user level document here
228:                        //
229:
230:                        return false;
231:                    }
232:
233:                    if (!name.startsWith("dp-")) {
234:                        return false;
235:                    }
236:
237:                    if (!name.endsWith(".xml")) {
238:                        return false;
239:                    }
240:
241:                    return true;
242:                }
243:            }
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.