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