Source Code Cross Referenced for WriteDOMSessionTransformer.java in  » Web-Framework » cocoon » org » apache » cocoon » transformation » 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.transformation 
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.transformation;
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.dom.DOMBuilder;
026:        import org.xml.sax.Attributes;
027:        import org.xml.sax.SAXException;
028:
029:        import java.io.IOException;
030:        import java.util.HashMap;
031:        import java.util.Iterator;
032:        import java.util.Map;
033:
034:        /**
035:         * @cocoon.sitemap.component.documentation
036:         * Make a DOM object from SAX events and write it to the session.
037:         * 
038:         * @cocoon.sitemap.component.name   writeDOMsession
039:         * @cocoon.sitemap.component.logger sitemap.transformer.writeDOMsession
040:         * 
041:         * 
042:         * Make a DOM object from SAX events and write it to the session.
043:         *
044:         * Usage in sitemap:
045:         *    <map:transform type="writeDOMsession">
046:         *      <map:parameter name="dom-name" value="content"/>
047:         *      <map:parameter name="dom-root-element" value="companies"/>
048:         *    </map:transform>
049:         *
050:         * Where:
051:         *   dom-name is the name for the DOM object in the session
052:         *   dom-root-element is the trigger that will be the root element of the DOM
053:         *
054:         * @author <a href="mailto:sven.beauprez@the-ecorp.com">Sven Beauprez</a>
055:         * @version CVS $Id: WriteDOMSessionTransformer.java 433543 2006-08-22 06:22:54Z crossley $
056:         */
057:
058:        public class WriteDOMSessionTransformer extends AbstractTransformer {
059:
060:            public static final String DOM_NAME = "dom-name";
061:            public static final String DOM_ROOT_ELEMENT = "dom-root-element";
062:
063:            private boolean buildDom = false;
064:            private boolean sessionAvailable = false;
065:
066:            private Session session;
067:            private DOMBuilder builder;
068:
069:            private String DOMName;
070:            private String rootElement;
071:            private Map storedPrefixMap;
072:
073:            /**
074:             * Recyclable
075:             */
076:            public void recycle() {
077:                super .recycle();
078:                this .session = null;
079:                this .builder = null;
080:                this .buildDom = false;
081:                this .sessionAvailable = false;
082:            }
083:
084:            /** BEGIN SitemapComponent methods **/
085:
086:            public void setup(SourceResolver resolver, Map objectModel,
087:                    String source, Parameters parameters)
088:                    throws ProcessingException, SAXException, IOException {
089:                getLogger().debug("WriteSessionTransformer: setup");
090:                Request request = ObjectModelHelper.getRequest(objectModel);
091:                session = request.getSession(false);
092:                if (session != null) {
093:                    DOMName = parameters.getParameter(
094:                            WriteDOMSessionTransformer.DOM_NAME, null);
095:                    rootElement = parameters.getParameter(
096:                            WriteDOMSessionTransformer.DOM_ROOT_ELEMENT, null);
097:                    if (DOMName != null && rootElement != null) {
098:                        //only now we know it is usefull to store something in the session
099:                        getLogger()
100:                                .debug(
101:                                        "WriteSessionTransformer: "
102:                                                + WriteDOMSessionTransformer.DOM_NAME
103:                                                + "="
104:                                                + DOMName
105:                                                + "; "
106:                                                + WriteDOMSessionTransformer.DOM_ROOT_ELEMENT
107:                                                + "=" + rootElement);
108:                        sessionAvailable = true;
109:                        storedPrefixMap = new HashMap();
110:                    } else {
111:                        getLogger()
112:                                .error(
113:                                        "WriteSessionTransformer: need "
114:                                                + WriteDOMSessionTransformer.DOM_NAME
115:                                                + " and "
116:                                                + WriteDOMSessionTransformer.DOM_ROOT_ELEMENT
117:                                                + " parameters");
118:                    }
119:                } else {
120:                    getLogger().error(
121:                            "WriteSessionTransformer: no session object");
122:                }
123:            }
124:
125:            /** END SitemapComponent methods **/
126:
127:            /** BEGIN SAX ContentHandler handlers **/
128:
129:            public void startPrefixMapping(String prefix, String uri)
130:                    throws SAXException {
131:                super .startPrefixMapping(prefix, uri);
132:                if (buildDom) {
133:                    builder.startPrefixMapping(prefix, uri);
134:                } else {
135:                    storePrefixMapping(prefix, uri);
136:                }
137:            }
138:
139:            public void startElement(String uri, String name, String raw,
140:                    Attributes attributes) throws SAXException {
141:                //only build the DOM tree if session is available
142:                if (name.equalsIgnoreCase(rootElement) && sessionAvailable) {
143:                    getLogger().debug(
144:                            "WriteSessionTransformer: start building DOM tree");
145:                    buildDom = true;
146:                    builder = new DOMBuilder();
147:                    builder.startDocument();
148:                    launchStoredMappings();
149:                    builder.startElement(uri, name, raw, attributes);
150:                } else if (buildDom) {
151:                    builder.startElement(uri, name, raw, attributes);
152:                }
153:                super .contentHandler.startElement(uri, name, raw, attributes);
154:            }
155:
156:            public void endElement(String uri, String name, String raw)
157:                    throws SAXException {
158:                if (name.equalsIgnoreCase(rootElement) && sessionAvailable) {
159:                    buildDom = false;
160:                    builder.endElement(uri, name, raw);
161:                    builder.endDocument();
162:                    getLogger()
163:                            .debug(
164:                                    "WriteSessionTransformer: putting DOM tree in session object");
165:                    session.setAttribute(DOMName, builder.getDocument()
166:                            .getFirstChild());
167:                    getLogger()
168:                            .debug(
169:                                    "WriteSessionTransformer: DOM tree is in session object");
170:                } else if (buildDom) {
171:                    builder.endElement(uri, name, raw);
172:                }
173:                super .contentHandler.endElement(uri, name, raw);
174:            }
175:
176:            public void characters(char c[], int start, int len)
177:                    throws SAXException {
178:                if (buildDom) {
179:                    builder.characters(c, start, len);
180:                }
181:                super .contentHandler.characters(c, start, len);
182:            }
183:
184:            public void startCDATA() throws SAXException {
185:                if (buildDom) {
186:                    builder.startCDATA();
187:                }
188:                super .lexicalHandler.startCDATA();
189:            }
190:
191:            public void endCDATA() throws SAXException {
192:                if (buildDom) {
193:                    builder.endCDATA();
194:                }
195:                super .lexicalHandler.endCDATA();
196:            }
197:
198:            /** END SAX ContentHandler handlers **/
199:
200:            protected void storePrefixMapping(String prefix, String uri) {
201:                storedPrefixMap.put(prefix, uri);
202:            }
203:
204:            protected void launchStoredMappings() throws SAXException {
205:                Iterator it = storedPrefixMap.keySet().iterator();
206:                while (it.hasNext()) {
207:                    String pre = (String) it.next();
208:                    String uri = (String) storedPrefixMap.get(pre);
209:                    getLogger().debug(
210:                            "WriteSessionTransformer: launching prefix mapping[ pre: "
211:                                    + pre + " uri: " + uri + " ]");
212:                    builder.startPrefixMapping(pre, uri);
213:                }
214:            }
215:
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.