Source Code Cross Referenced for SessionAttributeModule.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » components » modules » input » 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 » apache lenya 2.0 » org.apache.cocoon.components.modules.input 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.cocoon.components.modules.input;
019:
020:        import org.apache.avalon.framework.configuration.Configuration;
021:        import org.apache.avalon.framework.configuration.ConfigurationException;
022:        import org.apache.avalon.framework.thread.ThreadSafe;
023:        import org.apache.cocoon.environment.ObjectModelHelper;
024:        import org.apache.cocoon.environment.Request;
025:        import org.apache.cocoon.environment.Session;
026:
027:        import java.util.Enumeration;
028:        import java.util.Iterator;
029:        import java.util.LinkedList;
030:        import java.util.List;
031:        import java.util.Map;
032:        import java.util.SortedSet;
033:        import java.util.TreeSet;
034:
035:        /**
036:         * SessionAttributeModule accesses session attributes. If the
037:         * attribute name contains an askerisk "*" this is considered a
038:         * wildcard and all attributes that would match this wildcard are
039:         * considered to be part of an array of that name for
040:         * getAttributeValues. Only one "*" is allowed.
041:         *
042:         * @author <a href="mailto:haul@apache.org">Christian Haul</a>
043:         * @version $Id: SessionAttributeModule.java 433543 2006-08-22 06:22:54Z crossley $
044:         */
045:        public class SessionAttributeModule extends AbstractInputModule
046:                implements  ThreadSafe {
047:
048:            public Object getAttribute(String name, Configuration modeConf,
049:                    Map objectModel) throws ConfigurationException {
050:
051:                String pname = (String) this .settings.get("parameter", name);
052:                if (modeConf != null) {
053:                    pname = modeConf.getAttribute("parameter", pname);
054:                    // preferred
055:                    pname = modeConf.getChild("parameter").getValue(pname);
056:                }
057:                return ObjectModelHelper.getRequest(objectModel).getSession()
058:                        .getAttribute(pname);
059:            }
060:
061:            public Iterator getAttributeNames(Configuration modeConf,
062:                    Map objectModel) throws ConfigurationException {
063:
064:                return new IteratorHelper(ObjectModelHelper.getRequest(
065:                        objectModel).getSession().getAttributeNames());
066:            }
067:
068:            public Object[] getAttributeValues(String name,
069:                    Configuration modeConf, Map objectModel)
070:                    throws ConfigurationException {
071:
072:                Request request = ObjectModelHelper.getRequest(objectModel);
073:                String wildcard = (String) this .settings.get("parameter", name);
074:                if (modeConf != null) {
075:                    wildcard = modeConf.getAttribute("parameter", wildcard);
076:                    // preferred
077:                    wildcard = modeConf.getChild("parameter")
078:                            .getValue(wildcard);
079:                }
080:                int wildcardIndex = wildcard.indexOf("*");
081:                if (wildcardIndex != -1) {
082:                    // "*" contained in attribute name => combine all
083:                    // attributes' values that match prefix, suffix
084:
085:                    // split the attribute's name so that the "*" could be
086:                    // determined by looking at the attributes' names that
087:                    // start with the prefix and end with the suffix
088:                    //
089:                    String prefix = wildcard.substring(0, wildcardIndex);
090:                    String suffix;
091:                    if (wildcard.length() >= wildcardIndex + 1) {
092:                        suffix = wildcard.substring(wildcardIndex + 1);
093:                    } else {
094:                        suffix = "";
095:                    }
096:                    SortedSet names = new TreeSet();
097:                    Session session = request.getSession();
098:                    Enumeration allNames = session.getAttributeNames();
099:
100:                    while (allNames.hasMoreElements()) {
101:                        String pname = (String) allNames.nextElement();
102:                        if (pname.startsWith(prefix) && pname.endsWith(suffix)) {
103:                            names.add(pname);
104:                        }
105:                    }
106:
107:                    List values = new LinkedList();
108:                    Iterator j = names.iterator();
109:                    while (j.hasNext()) {
110:                        String pname = (String) j.next();
111:                        values.add(session.getAttribute(pname));
112:                    }
113:
114:                    return values.toArray();
115:
116:                } else {
117:                    // no "*" in attribute name => just return all values of
118:                    // this one attribute. Make sure, it's an array.
119:
120:                    Object value = request.getSession().getAttribute(wildcard);
121:                    if (value != null && !value.getClass().isArray()) {
122:                        Object[] values = new Object[1];
123:                        values[0] = value;
124:                        return values;
125:                    } else {
126:                        return (Object[]) value;
127:                    }
128:
129:                }
130:
131:            }
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.