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


001:        /* Copyright 2001, 2005 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.channels;
007:
008:        import java.io.IOException;
009:        import java.io.OutputStream;
010:        import java.util.Enumeration;
011:        import java.util.HashSet;
012:        import java.util.Iterator;
013:        import java.util.Map;
014:        import java.util.Set;
015:        import java.util.TreeSet;
016:
017:        import org.jasig.portal.IMimeResponse;
018:        import org.jasig.portal.PortalException;
019:        import org.jasig.portal.UPFileSpec;
020:        import org.jasig.portal.security.IPerson;
021:        import org.jasig.portal.services.PersonDirectory;
022:        import org.jasig.portal.services.persondir.IPersonAttributeDao;
023:        import org.jasig.portal.utils.DocumentFactory;
024:        import org.jasig.portal.utils.XSLT;
025:        import org.w3c.dom.Document;
026:        import org.w3c.dom.Element;
027:        import org.xml.sax.ContentHandler;
028:
029:        /**
030:         * This channel demonstrates the method of obtaining and displaying
031:         * standard uPortal person attributes.
032:         *
033:         * Implements IMimeResponse in order to support the inline display of jpegPhotos
034:         * Note:  for proper operation, one should use an idempotent baseActionURL.
035:         *
036:         * @author Ken Weiner, kweiner@unicon.net
037:         * @author Yuji Shinozaki, ys2n@virginia.edu
038:         * @version $Revision: 36388 $ $Date: 2006-01-06 10:59:42 -0700 (Fri, 06 Jan 2006) $
039:         */
040:        public class CPersonAttributes extends BaseChannel implements 
041:                IMimeResponse {
042:
043:            private static final String sslLocation = "CPersonAttributes/CPersonAttributes.ssl";
044:
045:            public void renderXML(ContentHandler out) throws PortalException {
046:                IPerson person = staticData.getPerson();
047:                Document doc = DocumentFactory.getNewDocument();
048:
049:                Element attributesE = doc.createElement("attributes");
050:
051:                IPersonAttributeDao pa = PersonDirectory
052:                        .getPersonAttributeDao();
053:                Set possibleAttrs = pa.getPossibleUserAttributeNames();
054:
055:                if (possibleAttrs != null)
056:                    possibleAttrs = new HashSet(possibleAttrs);
057:                else
058:                    possibleAttrs = new HashSet();
059:
060:                for (Enumeration attribs = person.getAttributeNames(); attribs
061:                        .hasMoreElements();) {
062:                    // Get the attribute name
063:                    String attName = (String) attribs.nextElement();
064:
065:                    // Remove this attr from the list of possible attrs
066:                    possibleAttrs.remove(attName);
067:
068:                    // Set the attribute
069:                    Element attributeE = doc.createElement("attribute");
070:
071:                    Element nameE = doc.createElement("name");
072:                    nameE.appendChild(doc.createTextNode(attName));
073:                    attributeE.appendChild(nameE);
074:
075:                    // Get the IPerson attribute value for this eduPerson attribute name
076:                    if (person.getAttributeValues(attName) != null) {
077:                        Object[] values = person.getAttributeValues(attName);
078:                        for (int i = 0; i < values.length; i++) {
079:                            if (log.isTraceEnabled())
080:                                log.trace("type of value[" + i + "] is "
081:                                        + values[i].getClass().getName());
082:                            String value = values[i].toString();
083:                            Element valueE = doc.createElement("value");
084:                            valueE.appendChild(doc.createTextNode(value));
085:                            attributeE.appendChild(valueE);
086:                        }
087:                    }
088:
089:                    attributesE.appendChild(attributeE);
090:                }
091:
092:                //Sort the set of possible attributes
093:                possibleAttrs = new TreeSet(possibleAttrs);
094:
095:                //Add the unknown attributes to the element list.
096:                for (Iterator attribs = possibleAttrs.iterator(); attribs
097:                        .hasNext();) {
098:                    // Get the attribute name
099:                    String attName = (String) attribs.next();
100:
101:                    // Set the attribute
102:                    Element attributeE = doc.createElement("attribute");
103:
104:                    Element nameE = doc.createElement("name");
105:                    nameE.appendChild(doc.createTextNode(attName));
106:                    attributeE.appendChild(nameE);
107:
108:                    attributesE.appendChild(attributeE);
109:                }
110:
111:                doc.appendChild(attributesE);
112:
113:                XSLT xslt = XSLT.getTransformer(this , runtimeData.getLocales());
114:                xslt.setXML(doc);
115:                xslt.setStylesheetParameter("baseActionURL", runtimeData
116:                        .getBaseActionURL());
117:                xslt.setStylesheetParameter("downloadWorkerURL",
118:                        runtimeData.getBaseWorkerURL(
119:                                UPFileSpec.FILE_DOWNLOAD_WORKER, true));
120:                xslt.setXSL(sslLocation, runtimeData.getBrowserInfo());
121:                xslt.setTarget(out);
122:                xslt.transform();
123:            }
124:
125:            // IMimeResponse implementation -- ys2n@virginia.edu
126:            /**
127:             * Returns the MIME type of the content.
128:             */
129:            public java.lang.String getContentType() {
130:                // In the future we will need some sort of way of grokking the
131:                // mime-type of the byte-array and returning an appropriate mime-type
132:                // Right now there is no good way of doing that, and we will
133:                // assume that the only thing we will be delivering is a jpegPhoto.
134:                // attribute with a mimetype of image/jpeg
135:                // In the future however, we may need a way to deliver different
136:                // attributes as differenct mimetypes (e.g certs).
137:                //
138:                String mimetype;
139:                // runtime parameter "attribute" determines which attribute to return when
140:                // called as an IMimeResponse.
141:                String attrName = runtimeData.getParameter("attribute");
142:
143:                if ("jpegPhoto".equals(attrName)) {
144:                    mimetype = "image/jpeg";
145:                } else {
146:                    // default -- an appropriate choice?
147:                    mimetype = "application/octet-stream";
148:                }
149:                return mimetype;
150:            }
151:
152:            /**
153:             * Returns the MIME content in the form of an input stream.
154:             * Returns null if the code needs the OutputStream object
155:             */
156:            public java.io.InputStream getInputStream() throws IOException {
157:                String attrName = runtimeData.getParameter("attribute");
158:                IPerson person = staticData.getPerson();
159:
160:                if (attrName == null) {
161:                    attrName = "";
162:                }
163:
164:                // get the image out of the IPerson as a byte array.
165:                // Note:  I am assuming here that the only thing that this
166:                // IMimeResponse will return is a jpegPhoto.  Some other
167:                // generalized mechanism will need to be inserted here to
168:                // support other mimetypes and IPerson attributes.
169:                byte[] imgBytes = (byte[]) person.getAttribute(attrName);
170:
171:                // need to create a ByteArrayInputStream()
172:
173:                if (imgBytes == null) {
174:                    imgBytes = new byte[0]; // let's avoid a null pointer
175:                }
176:                java.io.InputStream is = (java.io.InputStream) new java.io.ByteArrayInputStream(
177:                        imgBytes);
178:
179:                return is;
180:            }
181:
182:            /**
183:             * Pass the OutputStream object to the download code if it needs special handling
184:             * (like outputting a Zip file).  Unimplemented.
185:             */
186:            public void downloadData(OutputStream out) throws IOException {
187:            }
188:
189:            /**
190:             * Returns the name of the MIME file.
191:             */
192:            public java.lang.String getName() {
193:                // As noted above the only attribute we support right now is "image/jpeg" for
194:                // the jpegPhoto attribute.
195:
196:                String payloadName;
197:                if ("jpegPhoto".equals(runtimeData.getParameter("attribute")))
198:                    payloadName = "image.jpg";
199:                else
200:                    payloadName = "unknown";
201:                return payloadName;
202:            }
203:
204:            /**
205:             * Returns a list of header values that can be set in the HttpResponse.
206:             * Returns null if no headers need to be set.
207:             */
208:            public Map getHeaders() {
209:                return null;
210:            }
211:
212:            /**
213:             * Let the channel know that there were problems with the download
214:             * @param e
215:             */
216:            public void reportDownloadError(Exception e) {
217:                log.error(e.getMessage(), e);
218:            }
219:
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.