Source Code Cross Referenced for UserMeta.java in  » Content-Management-System » dspace » org » dspace » app » xmlui » wing » element » 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 » Content Management System » dspace » org.dspace.app.xmlui.wing.element 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * UserMeta.java
003:         *
004:         * Version: $Revision: 1.7 $
005:         *
006:         * Date: $Date: 2006/08/08 21:59:25 $
007:         *
008:         * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
009:         * Institute of Technology.  All rights reserved.
010:         *
011:         * Redistribution and use in source and binary forms, with or without
012:         * modification, are permitted provided that the following conditions are
013:         * met:
014:         *
015:         * - Redistributions of source code must retain the above copyright
016:         * notice, this list of conditions and the following disclaimer.
017:         *
018:         * - Redistributions in binary form must reproduce the above copyright
019:         * notice, this list of conditions and the following disclaimer in the
020:         * documentation and/or other materials provided with the distribution.
021:         *
022:         * - Neither the name of the Hewlett-Packard Company nor the name of the
023:         * Massachusetts Institute of Technology nor the names of their
024:         * contributors may be used to endorse or promote products derived from
025:         * this software without specific prior written permission.
026:         *
027:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028:         * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031:         * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033:         * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034:         * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036:         * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037:         * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038:         * DAMAGE.
039:         */
040:
041:        package org.dspace.app.xmlui.wing.element;
042:
043:        import java.util.ArrayList;
044:        import java.util.List;
045:
046:        import org.dspace.app.xmlui.wing.AttributeMap;
047:        import org.dspace.app.xmlui.wing.WingConstants;
048:        import org.dspace.app.xmlui.wing.WingContext;
049:        import org.dspace.app.xmlui.wing.WingException;
050:        import org.xml.sax.Attributes;
051:        import org.xml.sax.ContentHandler;
052:        import org.xml.sax.SAXException;
053:        import org.xml.sax.ext.LexicalHandler;
054:        import org.xml.sax.helpers.AttributesImpl;
055:        import org.xml.sax.helpers.NamespaceSupport;
056:
057:        /**
058:         * A class representing a set of metadata about the user generating this page.
059:         * 
060:         * @author Scott Phillips
061:         */
062:        public class UserMeta extends AbstractWingElement implements 
063:                WingMergeableElement, MetadataElement {
064:            /** The name of the userMeta element */
065:            public static final String E_USER_META = "userMeta";
066:
067:            /** The name of the authenticated attribute */
068:            public static final String A_AUTHENTICATED = "authenticated";
069:
070:            /** Has this UserMeta element been merged? */
071:            private boolean merged = false;
072:
073:            /** Has this user been authenticated? */
074:            private boolean authenticated = false;
075:
076:            /** The metadata contents of this UserMeta element */
077:            private List<Metadata> metadatum = new ArrayList<Metadata>();
078:
079:            /**
080:             * Construct a new userMeta
081:             * 
082:             * @param context
083:             *            (Required) The context this element is contained in, such as
084:             *            where to route SAX events and what i18n catalogue to use.
085:             * @param authenticated
086:             *            (Required) Weather the user has been authenticated.
087:             */
088:            protected UserMeta(WingContext context) throws WingException {
089:                super (context);
090:            }
091:
092:            /**
093:             * Set the user described in the meta object as authenticated.
094:             * 
095:             * @param authenticated
096:             *            (Required) True if the user is authenticated, false otherwise.
097:             */
098:            public void setAuthenticated(boolean authenticated) {
099:                this .authenticated = authenticated;
100:            }
101:
102:            /**
103:             * Add metadata about the requesting user to the document.
104:             * 
105:             * @param element
106:             *            (Required) The metadata element.
107:             * @param qualifier
108:             *            (May be null) The metadata qualifier.
109:             * @param language
110:             *            (May be null) The metadata's language
111:             * @param allowMultiple
112:             *            (Required) determine if multipe metadata element with the same
113:             *            element, qualifier and language are allowed.
114:             * @return A new metadata
115:             */
116:            public Metadata addMetadata(String element, String qualifier,
117:                    String language, boolean allowMultiple)
118:                    throws WingException {
119:                Metadata metadata = new Metadata(context, element, qualifier,
120:                        language, allowMultiple);
121:                metadatum.add(metadata);
122:                return metadata;
123:            }
124:
125:            /**
126:             * Add metadata about the requesting user to the document.
127:             * 
128:             * @param element
129:             *            (Required) The metadata element.
130:             * @param qualifier
131:             *            (May be null) The metadata qualifier.
132:             * @param language
133:             *            (May be null) The metadata's language
134:             * @return A new metadata
135:             */
136:            public Metadata addMetadata(String element, String qualifier,
137:                    String language) throws WingException {
138:                return addMetadata(element, qualifier, null, false);
139:            }
140:
141:            /**
142:             * Add metadata about the requesting user to the document.
143:             * 
144:             * @param element
145:             *            (Required) The metadata element.
146:             * @param qualifier
147:             *            (May be null) The metadata qualifier.
148:             * @return A new metadata
149:             */
150:            public Metadata addMetadata(String element, String qualifier)
151:                    throws WingException {
152:                return addMetadata(element, qualifier, null, false);
153:            }
154:
155:            /**
156:             * Add metadata about the requesting user to the document.
157:             * 
158:             * @param element
159:             *            (Required) The metadata element.
160:             * @return A new metadata
161:             */
162:            public Metadata addMetadata(String element) throws WingException {
163:                return addMetadata(element, null, null, false);
164:            }
165:
166:            /**
167:             * Determine if the given SAX event is a UserMeta element.
168:             * 
169:             * @param namespace
170:             *            The element's name space
171:             * @param localName
172:             *            The local, unqualified, name for this element
173:             * @param qName
174:             *            The qualified name for this element
175:             * @param attributes
176:             *            The element's attributes
177:             * @return True if this WingElement is equivalent to the given SAX Event.
178:             */
179:            public boolean mergeEqual(String namespace, String localName,
180:                    String qName, Attributes attributes) throws SAXException,
181:                    WingException {
182:
183:                if (!WingConstants.DRI.URI.equals(namespace))
184:                    return false;
185:
186:                if (!E_USER_META.equals(localName))
187:                    return false;
188:                return true;
189:            }
190:
191:            /**
192:             * Since metadata can not be merged there are no mergeable children. This
193:             * just return's null.
194:             * 
195:             * @param namespace
196:             *            The element's name space
197:             * @param localName
198:             *            The local, unqualified, name for this element *
199:             * @param qName
200:             *            The qualified name for this element
201:             * @param attributes
202:             *            The element's attributes
203:             * @return The child element
204:             */
205:            public WingMergeableElement mergeChild(String namespace,
206:                    String localName, String qName, Attributes attributes)
207:                    throws SAXException, WingException {
208:                // We don't merge our children but we do have one special optimization, 
209:                // if a metadata is allready in the document and it is taged as not allowing 
210:                // multiples then we do not add the new metadata to the document.
211:
212:                if (WingConstants.DRI.URI.equals(namespace)
213:                        && Metadata.E_METADATA.equals(localName)) {
214:                    String element = attributes.getValue(Metadata.A_ELEMENT);
215:                    String qualifier = attributes
216:                            .getValue(Metadata.A_QUALIFIER);
217:                    String language = attributes.getValue(Metadata.A_LANGUAGE);
218:
219:                    List<Metadata> remove = new ArrayList<Metadata>();
220:                    for (Metadata metadata : metadatum) {
221:                        if (metadata.equals(element, qualifier, language)
222:                                && !metadata.allowMultiple()) {
223:                            remove.add(metadata);
224:                        }
225:                    }
226:
227:                    // Remove all the metadata elements we found.
228:                    for (Metadata metadata : remove) {
229:                        metadata.dispose();
230:                        metadatum.remove(metadata);
231:                    }
232:                }
233:
234:                return null;
235:            }
236:
237:            /**
238:             * Inform this element that it is being merged with an existing element.
239:             */
240:            public Attributes merge(Attributes attributes) throws SAXException,
241:                    WingException {
242:                this .merged = true;
243:
244:                String mergedAuthenticated = attributes
245:                        .getValue(A_AUTHENTICATED);
246:
247:                if ("yes".equals(mergedAuthenticated)) {
248:                    // The user has allready been set to authenticated.
249:                    // Do nothing.
250:                } else if ("no".equals(mergedAuthenticated)) {
251:                    // No authenticated user yet.
252:                    if (this .authenticated) {
253:                        // Original no, but we've been told that the user is
254:                        // authenticated.
255:                        AttributesImpl attributesImpl = new AttributesImpl(
256:                                attributes);
257:                        int index = attributesImpl.getIndex(A_AUTHENTICATED);
258:                        if (index >= 0) {
259:                            attributesImpl.setValue(index, "yes");
260:                        } else {
261:                            attributesImpl.addAttribute("", A_AUTHENTICATED,
262:                                    A_AUTHENTICATED, "CDATA", "yes");
263:                        }
264:                        attributes = attributesImpl;
265:                    }
266:                } else {
267:                    // Authenticated value does not conform to the schema.
268:                    AttributesImpl attributesImpl = new AttributesImpl(
269:                            attributes);
270:                    attributesImpl.addAttribute("", A_AUTHENTICATED,
271:                            A_AUTHENTICATED, "CDATA",
272:                            (this .authenticated ? "yes" : "no"));
273:                    attributes = attributesImpl;
274:
275:                }
276:
277:                return attributes;
278:            }
279:
280:            /**
281:             * Translate this element into SAX events.
282:             * 
283:             * @param contentHandler
284:             *            (Required) The registered contentHandler where SAX events
285:             *            should be routed too.
286:             * @param lexicalHandler
287:             *            (Required) The registered lexicalHandler where lexical 
288:             *            events (such as CDATA, DTD, etc) should be routed too.
289:             * @param namespaces
290:             *            (Required) SAX Helper class to keep track of namespaces able
291:             *            to determine the correct prefix for a given namespace URI.
292:             */
293:            public void toSAX(ContentHandler contentHandler,
294:                    LexicalHandler lexicalHandler, NamespaceSupport namespaces)
295:                    throws SAXException {
296:                if (!merged) {
297:                    AttributeMap attributes = new AttributeMap();
298:                    if (authenticated)
299:                        attributes.put(A_AUTHENTICATED, "yes");
300:                    else
301:                        attributes.put(A_AUTHENTICATED, "no");
302:                    startElement(contentHandler, namespaces, E_USER_META,
303:                            attributes);
304:                }
305:
306:                for (Metadata metadata : metadatum)
307:                    metadata.toSAX(contentHandler, lexicalHandler, namespaces);
308:
309:                if (!merged)
310:                    endElement(contentHandler, namespaces, E_USER_META);
311:            }
312:
313:            /**
314:             * dispose
315:             */
316:            public void dispose() {
317:                for (AbstractWingElement content : metadatum)
318:                    content.dispose();
319:                metadatum.clear();
320:                metadatum = null;
321:                super.dispose();
322:            }
323:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.