Source Code Cross Referenced for PersonDirXmlParser.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » services » persondir » support » legacy » 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 » uPortal_rel 2 6 1 GA » org.jasig.portal.services.persondir.support.legacy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2004 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.services.persondir.support.legacy;
007:
008:        import java.util.ArrayList;
009:        import java.util.List;
010:        import java.util.StringTokenizer;
011:
012:        import org.apache.commons.logging.Log;
013:        import org.apache.commons.logging.LogFactory;
014:        import org.jasig.portal.utils.XML;
015:        import org.springframework.dao.DataIntegrityViolationException;
016:        import org.w3c.dom.Document;
017:        import org.w3c.dom.Element;
018:        import org.w3c.dom.Node;
019:        import org.w3c.dom.NodeList;
020:
021:        /**
022:         * Static function class which parses a Document such as that contained in
023:         * a PersonDirs.xml file to obtain a List of PersonDirInfo objects.
024:         * 
025:         * @version $Revision: 35676 $ $Date: 2005-04-26 09:34:30 -0700 (Tue, 26 Apr 2005) $
026:         * @since uPortal 2.5
027:         */
028:        class PersonDirXmlParser {
029:
030:            private static final Log log = LogFactory
031:                    .getLog(PersonDirXmlParser.class);
032:
033:            /**
034:             * Computes a List of PersonDirInfo objects from a Document.
035:             * @param personDirDoc PersonDirInfo document
036:             * @return a List of PersonDirInfo objects
037:             * @throws IllegalArgumentException if param personDirDoc is null
038:             * @throws DataAccessException on failure
039:             */
040:            static List getPersonDirInfos(Document personDirDoc) {
041:                if (personDirDoc == null)
042:                    throw new IllegalArgumentException(
043:                            "Cannot get PersonDirInfos from a null document.");
044:
045:                List infos = new ArrayList();
046:
047:                // Each directory source is a <PersonDirInfo> (and its contents)
048:                NodeList list = personDirDoc
049:                        .getElementsByTagName("PersonDirInfo");
050:                for (int i = 0; i < list.getLength(); i++) { // foreach
051:                    // PersonDirInfo
052:                    Element dirinfo = (Element) list.item(i);
053:
054:                    // Java object into which we're trying to parse the PersonDirInfo
055:                    // element
056:                    PersonDirInfo pdi = new PersonDirInfo();
057:
058:                    // foreach tag under the <PersonDirInfo>
059:                    for (Node param = dirinfo.getFirstChild(); param != null; param = param
060:                            .getNextSibling()) {
061:
062:                        if (!(param instanceof  Element))
063:                            continue; // whitespace (typically \n) between tags
064:                        Element pele = (Element) param;
065:                        String tagname = pele.getTagName();
066:                        String value = XML.getElementText(pele);
067:
068:                        try {
069:                            // each tagname corresponds to an object data field
070:                            if (tagname.equals("url")) {
071:                                pdi.setUrl(value);
072:                            } else if (tagname.equals("res-ref-name")) {
073:                                pdi.setResRefName(value);
074:                            } else if (tagname.equals("ldap-ref-name")) {
075:                                pdi.setLdapRefName(value);
076:                            } else if (tagname.equals("logonid")) {
077:                                pdi.setLogonid(value);
078:                            } else if (tagname.equals("driver")) {
079:                                pdi.setDriver(value);
080:                            } else if (tagname.equals("logonpassword")) {
081:                                pdi.setLogonpassword(value);
082:                            } else if (tagname.equals("uidquery")) {
083:                                pdi.setUidquery(value);
084:                            } else if (tagname.equals("usercontext")) {
085:                                pdi.setUsercontext(value);
086:                            } else if (tagname.equals("timeout")) {
087:                                pdi.setLdaptimelimit(Integer.parseInt(value));
088:                            } else if (tagname.equals("attributes")) {
089:                                NodeList anodes = pele
090:                                        .getElementsByTagName("attribute");
091:                                int anodecount = anodes.getLength();
092:                                if (anodecount != 0) {
093:                                    String[] attributenames = new String[anodecount];
094:                                    String[] attributealiases = new String[anodecount];
095:                                    for (int j = 0; j < anodecount; j++) {
096:                                        Element anode = (Element) anodes
097:                                                .item(j);
098:                                        NodeList namenodes = anode
099:                                                .getElementsByTagName("name");
100:                                        String aname = "$$$";
101:                                        if (namenodes.getLength() != 0)
102:                                            aname = XML
103:                                                    .getElementText((Element) namenodes
104:                                                            .item(0));
105:                                        attributenames[j] = aname;
106:                                        NodeList aliasnodes = anode
107:                                                .getElementsByTagName("alias");
108:                                        if (aliasnodes.getLength() == 0) {
109:                                            attributealiases[j] = aname;
110:                                        } else {
111:                                            attributealiases[j] = XML
112:                                                    .getElementText((Element) aliasnodes
113:                                                            .item(0));
114:                                        }
115:                                    }
116:                                    pdi.setAttributenames(attributenames);
117:                                    pdi.setAttributealiases(attributealiases);
118:
119:                                } else {
120:                                    // The <attributes> tag contains a list of names
121:                                    // and optionally aliases each in the form
122:                                    // name[:alias]
123:                                    // The name is an LDAP property or database column
124:                                    // name.
125:                                    // The alias, if it exists, is an eduPerson property
126:                                    // that
127:                                    // corresponds to the previous LDAP or DBMS name.
128:                                    // If no alias is specified, the eduPerson name is
129:                                    // also
130:                                    // the LDAP or DBMS column name.
131:                                    StringTokenizer st = new StringTokenizer(
132:                                            value);
133:                                    int n = st.countTokens();
134:                                    String[] attributenames = new String[n];
135:                                    String[] attributealiases = new String[n];
136:                                    for (int k = 0; k < n; k++) {
137:                                        String tk = st.nextToken();
138:                                        int pos = tk.indexOf(':');
139:                                        if (pos > 0) { // There is an alias
140:                                            attributenames[k] = tk.substring(0,
141:                                                    pos);
142:                                            attributealiases[k] = tk
143:                                                    .substring(pos + 1);
144:
145:                                        } else { // There is no alias
146:                                            attributenames[k] = tk;
147:                                            attributealiases[k] = tk;
148:                                        }
149:                                    }
150:                                    pdi.setAttributenames(attributenames);
151:                                    pdi.setAttributealiases(attributealiases);
152:                                }
153:                            } else {
154:                                log
155:                                        .warn("PersonDirectory::getParameters(): Unrecognized tag ["
156:                                                + tagname
157:                                                + "] in PersonDirs.xml");
158:                            }
159:                        } catch (Throwable t) {
160:                            throw new DataIntegrityViolationException(
161:                                    "Error processing tag [" + tagname
162:                                            + "] with value [" + value
163:                                            + "] in PersonDirInfo [" + dirinfo
164:                                            + "]", t);
165:                        }
166:
167:                    }
168:
169:                    String validationMessage = pdi.validate();
170:                    if (validationMessage != null)
171:                        throw new DataIntegrityViolationException(
172:                                "Processing PersonDirInfo " + "element ["
173:                                        + dirinfo + "] resulted in an invalid"
174:                                        + " PersonDirInfo object: "
175:                                        + validationMessage);
176:                    infos.add(pdi); // Add one LDAP or JDBC source to the list
177:                }
178:                return infos;
179:
180:            }
181:
182:            private PersonDirXmlParser() {
183:                // this is a static function class.  It is stateless.  It implements no
184:                // interface.  This method keeps you from instantiating or extending it, since
185:                // it is intended to be neither instantiated nor extended.
186:            }
187:        }
w__w___w___._j___ava2__s_._c__o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.