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


001:        /*
002:         * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004:         */
005:
006:        package com.sun.portal.harness;
007:
008:        import java.io.FileInputStream;
009:
010:        import java.util.Vector;
011:        import java.util.HashMap;
012:        import java.util.Iterator;
013:        import java.util.Locale;
014:
015:        import org.w3c.dom.Document;
016:        import org.w3c.dom.Element;
017:        import org.w3c.dom.NodeList;
018:        import org.w3c.dom.Node;
019:
020:        import javax.xml.parsers.DocumentBuilder;
021:        import javax.xml.parsers.DocumentBuilderFactory;
022:
023:        class UsersFile {
024:
025:            public static final String DEFAULT_USER = "default";
026:
027:            // We make the UsersFile an actual object rather than just a static switchboard mainly
028:            // to avoid repeating the top level child scanning.
029:
030:            private UsersFile(Document doc) throws ProviderHarnessException {
031:
032:                m_UserTab = new HashMap();
033:                m_DefaultUser = null;
034:                m_Global = null;
035:
036:                Element e = doc.getDocumentElement();
037:                if (e == null) {
038:                    throw new ProviderHarnessException(
039:                            "No root node in Users.xml document");
040:                }
041:                if (!e.getNodeName().equals("Users")) {
042:                    throw new ProviderHarnessException(
043:                            "Root node in Users.xml document is not Users");
044:                }
045:
046:                NodeList kids = e.getChildNodes();
047:                for (int i = 0; i < kids.getLength(); ++i) {
048:                    Node child = kids.item(i);
049:                    if (child instanceof  Element) {
050:                        Element chelt = (Element) child;
051:                        if (chelt.getNodeName().equals("User")) {
052:                            String nm = chelt.getAttribute("Name");
053:                            m_UserTab.put(nm, chelt);
054:                            continue;
055:                        }
056:                        if (chelt.getNodeName().equals("Global")) {
057:                            m_Global = chelt;
058:                            continue;
059:                        }
060:                        if (chelt.getNodeName().equals("DefaultUser")) {
061:                            m_DefaultUser = chelt;
062:                        }
063:                    }
064:                }
065:            }
066:
067:            static UsersFile makeUsersFile(Document doc)
068:                    throws ProviderHarnessException {
069:                return new UsersFile(doc);
070:            }
071:
072:            static void getUserNames(String file, Vector v)
073:                    throws ProviderHarnessException {
074:                DocumentBuilder db = null;
075:
076:                try {
077:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
078:                            .newInstance();
079:                    db = dbf.newDocumentBuilder();
080:                } catch (Exception ex) {
081:                    throw new ProviderHarnessException(
082:                            "Failure creating document builder", ex);
083:                }
084:
085:                Document doc = null;
086:
087:                // process compfile first.  This sets up our channel name.  Also,
088:                // any parameters entered from compfile will then take precedence over
089:                // the more global ones (PropHashMap() uses the FIRST entered.
090:
091:                try {
092:                    db.setEntityResolver(new ParEntryEntityResolver());
093:                    doc = db.parse(new FileInputStream(file));
094:                } catch (Exception ex) {
095:                    throw new ProviderHarnessException(
096:                            "Failure reading users xml - " + file, ex);
097:                }
098:
099:                UsersFile uf = new UsersFile(doc);
100:                uf.getUserNames(v);
101:            }
102:
103:            void getUserNames(Vector v) {
104:                v.clear();
105:
106:                if (m_DefaultUser != null) {
107:                    v.add(DEFAULT_USER);
108:                }
109:
110:                Iterator it = m_UserTab.keySet().iterator();
111:                while (it.hasNext()) {
112:                    v.add((String) it.next());
113:                }
114:            }
115:
116:            String getLocale(String user) throws ProviderHarnessException {
117:                String ls = getUserElement(user).getAttribute("Locale");
118:                if (ls.equals("")) {
119:                    return Locale.getDefault().toString();
120:                }
121:                return ls;
122:            }
123:
124:            Element getUserProps(String user) throws ProviderHarnessException {
125:                return subElement(getUserElement(user), "Properties", false);
126:            }
127:
128:            Element getUserChannelProps(String user, String chan)
129:                    throws ProviderHarnessException {
130:                return getChannelProperties(getUserElement(user), chan);
131:            }
132:
133:            Element getGlobalProps() throws ProviderHarnessException {
134:                return subElement(checkGlobal(), "Properties", false);
135:            }
136:
137:            Element getGlobalChannelProps(String chan)
138:                    throws ProviderHarnessException {
139:                return getChannelProperties(checkGlobal(), chan);
140:            }
141:
142:            void getUserChannelList(String user, Vector v)
143:                    throws ProviderHarnessException {
144:                getChannelList(getUserElement(user), v);
145:            }
146:
147:            void getGlobalChannelList(Vector v) throws ProviderHarnessException {
148:                getChannelList(checkGlobal(), v);
149:            }
150:
151:            private void getChannelList(Element elt, Vector v)
152:                    throws ProviderHarnessException {
153:                v.clear();
154:
155:                Element chans = subElement(elt, "Channels", true);
156:                if (chans == null) {
157:                    return;
158:                }
159:
160:                NodeList kids = chans.getChildNodes();
161:                for (int i = 0; i < kids.getLength(); ++i) {
162:                    Node child = kids.item(i);
163:                    if (child instanceof  Element
164:                            && child.getNodeName().equals("Channel")) {
165:                        Element chelt = (Element) child;
166:                        v.add(chelt.getAttribute("Name"));
167:                    }
168:                }
169:            }
170:
171:            private Element getChannelProperties(Element elt, String chan)
172:                    throws ProviderHarnessException {
173:                Element chans = subElement(elt, "Channels", false);
174:
175:                NodeList kids = chans.getChildNodes();
176:                for (int i = 0; i < kids.getLength(); ++i) {
177:                    Node child = kids.item(i);
178:                    if (child instanceof  Element
179:                            && child.getNodeName().equals("Channel")) {
180:                        Element chelt = (Element) child;
181:                        if (chelt.getAttribute("Name").equals(chan)) {
182:                            return subElement(chelt, "Properties", false);
183:                        }
184:                    }
185:                }
186:
187:                throw new ProviderHarnessException("Cannot find channel - "
188:                        + chan);
189:            }
190:
191:            private Element getUserElement(String user)
192:                    throws ProviderHarnessException {
193:
194:                if (user.equals(DEFAULT_USER)) {
195:                    if (m_DefaultUser == null) {
196:                        throw new ProviderHarnessException(
197:                                "Users.xml has no default user.");
198:                    }
199:                    return m_DefaultUser;
200:                }
201:
202:                Element elt = (Element) m_UserTab.get(user);
203:                if (elt == null) {
204:                    throw new ProviderHarnessException(
205:                            "Users.xml does not contain user - " + user);
206:                }
207:                return elt;
208:            }
209:
210:            private Element checkGlobal() throws ProviderHarnessException {
211:                if (m_Global == null) {
212:                    throw new ProviderHarnessException(
213:                            "Users.xml does not contain <Global>.");
214:                }
215:                return m_Global;
216:            }
217:
218:            private Element subElement(Element e, String nm, boolean nullok)
219:                    throws ProviderHarnessException {
220:                NodeList kids = e.getChildNodes();
221:
222:                for (int i = 0; i < kids.getLength(); ++i) {
223:                    Node child = kids.item(i);
224:                    if (child instanceof  Element
225:                            && child.getNodeName().equals(nm)) {
226:                        return (Element) child;
227:                    }
228:                }
229:
230:                if (nullok) {
231:                    return null;
232:                }
233:
234:                throw new ProviderHarnessException("Did not find expected "
235:                        + nm + " element in " + e.getNodeName());
236:            }
237:
238:            private HashMap m_UserTab;
239:            private Element m_DefaultUser;
240:            private Element m_Global;
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.