Source Code Cross Referenced for SessionAttributeGenerator.java in  » Web-Framework » cocoon » org » apache » cocoon » generation » 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 » Web Framework » cocoon » org.apache.cocoon.generation 
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:        package org.apache.cocoon.generation;
018:
019:        import org.apache.avalon.framework.parameters.Parameters;
020:        import org.apache.cocoon.ProcessingException;
021:        import org.apache.cocoon.environment.ObjectModelHelper;
022:        import org.apache.cocoon.environment.Request;
023:        import org.apache.cocoon.environment.Session;
024:        import org.apache.cocoon.environment.SourceResolver;
025:        import org.apache.cocoon.xml.XMLUtils;
026:        import org.apache.cocoon.xml.IncludeXMLConsumer;
027:        import org.apache.excalibur.xml.sax.XMLizable;
028:        import org.w3c.dom.Node;
029:        import org.xml.sax.SAXException;
030:
031:        import java.io.IOException;
032:        import java.util.Map;
033:
034:        /**
035:         * @cocoon.sitemap.component.documentation
036:         * Generates a document from a session attribute.
037:         *
038:         * @cocoon.sitemap.component.name   sessionattribute
039:         * @cocoon.sitemap.component.label  content
040:         * @cocoon.sitemap.component.logger sitemap.generator.sessionattribute
041:         *
042:         * Generates a document from a session attribute. The attribute may be a DOM
043:         * node, an <code>XMLizable</code>, or any other object, and is streamed using
044:         * the same rules as for &lt;xsp:expr&gt; in XSPs (see {@link
045:         * org.apache.cocoon.components.language.markup.xsp.XSPObjectHelper}).
046:         * <p>
047:         * Name of the session attribute is specified using src attribute of the generate
048:         * tag, or, if no src tag present, using attr-name parameter.
049:         * <p>
050:         * This generator has 2 parameters:
051:         * <ul>
052:         * <li><code>attr-name</code> : the session attribute name (mandatory if no src
053:         *     attribute specified).
054:         * </li>
055:         * <li><code>root-element</code> (optional) : the name of the root element of the
056:         *     produced document. This parameter is optional if the session attribute is
057:         *     a DOM or an <code>XMLizable</code>.
058:         * </li>
059:         * </ul>
060:         * <p>
061:         * Example usage :
062:         * <pre>
063:         *   &lt;map:generator name="session-attr" logger="sitemap.generator.session-attr"
064:         *     src="org.apache.cocoon.generation.SessionAttributeGenerator"/&gt;
065:         *   ...
066:         *   &lt;map:generate type="session-attr"&gt;
067:         *     &lt;map:parameter name="attr-name" value="myAttribute"/&gt;
068:         *     &lt;map:parameter name="root-element" value="root"/&gt;
069:         *   &lt;/map:generate&gt;
070:         * </pre>
071:         *
072:         * @see org.apache.cocoon.transformation.ReadDOMSessionTransformer
073:         * @see org.apache.cocoon.transformation.WriteDOMSessionTransformer
074:         * @author <a href="mailto:cedric.damioli@anyware-tech.com">C&eacute;dric Damioli</a>
075:         * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
076:         * @version $Id: SessionAttributeGenerator.java 433543 2006-08-22 06:22:54Z crossley $
077:         */
078:        public class SessionAttributeGenerator extends AbstractGenerator {
079:
080:            public static final String ATTR_NAME = "attr-name";
081:            public static final String ELEMENT_NAME = "root-element";
082:
083:            /** The object to generate */
084:            private Object attrObject;
085:
086:            /** The element name */
087:            private String elementName;
088:
089:            /**
090:             * Setup the file generator :try to retrieve the session attribute given as sitemap parameter
091:             */
092:            public void setup(SourceResolver resolver, Map objectModel,
093:                    String src, Parameters par) throws ProcessingException,
094:                    SAXException, IOException {
095:
096:                super .setup(resolver, objectModel, src, par);
097:
098:                // Get the element name (can be null if the object is a DOM or an XMLizable)
099:                this .elementName = par.getParameter(ELEMENT_NAME, null);
100:
101:                // Get the attribute name
102:                String attrName = par.getParameter(ATTR_NAME, src);
103:                if (attrName == null) {
104:                    String msg = "SessionAttributeGenerator needs an attribute name !";
105:                    getLogger().error(msg);
106:                    throw new ProcessingException(msg);
107:                }
108:
109:                // Get the object to stream
110:                Request request = ObjectModelHelper.getRequest(objectModel);
111:                Session session = request.getSession(false);
112:                if (session != null) {
113:                    this .attrObject = session.getAttribute(attrName);
114:                }
115:
116:                // Controls
117:                if (this .attrObject == null) {
118:                    if (this .elementName == null) {
119:                        // Can't generate nothing...
120:                        String msg = "Session attribute '" + attrName
121:                                + "' doesn't exist";
122:                        getLogger().error(msg);
123:                        throw new ProcessingException(msg);
124:                    } else {
125:                        if (getLogger().isDebugEnabled()) {
126:                            getLogger()
127:                                    .debug(
128:                                            "Session attribute '"
129:                                                    + attrName
130:                                                    + "' doesn't exist : will generate a single '"
131:                                                    + this .elementName
132:                                                    + "' element.");
133:                        }
134:                    }
135:                } else {
136:                    // Need an element name for non-xml objects
137:                    if (this .elementName == null
138:                            && !(this .attrObject instanceof  XMLizable)
139:                            && !(this .attrObject instanceof  Node)) {
140:
141:                        String msg = "Session attribute '" + attrName
142:                                + "' needs an enclosing element : class is "
143:                                + this .attrObject.getClass().getName();
144:
145:                        getLogger().warn(msg);
146:                        throw new ProcessingException(msg);
147:                    }
148:                }
149:            }
150:
151:            /**
152:             * Generate XML data
153:             */
154:            public void generate() throws IOException, SAXException,
155:                    ProcessingException {
156:                xmlConsumer.startDocument();
157:
158:                if (this .elementName != null) {
159:                    xmlConsumer.startElement("", this .elementName,
160:                            this .elementName, XMLUtils.EMPTY_ATTRIBUTES);
161:                    XMLUtils.valueOf(new IncludeXMLConsumer(xmlConsumer),
162:                            this .attrObject);
163:                    xmlConsumer.endElement("", this .elementName,
164:                            this .elementName);
165:                } else {
166:                    XMLUtils.valueOf(new IncludeXMLConsumer(xmlConsumer),
167:                            this.attrObject);
168:                }
169:
170:                xmlConsumer.endDocument();
171:            }
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.