Source Code Cross Referenced for InsertNodeJXPathBindingBuilder.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » forms » binding » 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.forms.binding 
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.forms.binding;
018:
019:        import org.apache.avalon.framework.service.ServiceManager;
020:        import org.apache.excalibur.source.Source;
021:        import org.apache.excalibur.source.SourceResolver;
022:        import org.apache.excalibur.xml.xpath.XPathProcessor;
023:
024:        import org.apache.cocoon.components.source.SourceUtil;
025:        import org.apache.cocoon.forms.util.DomHelper;
026:        import org.apache.cocoon.util.location.LocationAttributes;
027:
028:        import org.w3c.dom.Document;
029:        import org.w3c.dom.DocumentFragment;
030:        import org.w3c.dom.Element;
031:        import org.w3c.dom.Node;
032:        import org.w3c.dom.NodeList;
033:
034:        /**
035:         * InsertNodeJXPathBindingBuilder provides a helper class for the Factory
036:         * implemented in {@link JXPathBindingManager} that helps construct the
037:         * actual {@link InsertNodeJXPathBinding} out of the configuration in the
038:         * provided configElement which looks like:
039:         * <pre><code>
040:         * &lt;fb:insert-node&gt;
041:         *   &lt;!-- in here comes a template that will be inserted in the target
042:         *           document --&gt;
043:         * &lt;/fb:insert-node&gt;
044:         * </code></pre>
045:         *
046:         * @version $Id: InsertNodeJXPathBindingBuilder.java 517733 2007-03-13 15:37:22Z vgritsenko $
047:         */
048:        public class InsertNodeJXPathBindingBuilder extends
049:                JXPathBindingBuilderBase {
050:
051:            /**
052:             * Creates an instance of {@link InsertNodeJXPathBinding} configured
053:             * with the nested template of the bindingElm.
054:             */
055:            public JXPathBindingBase buildBinding(Element bindingElm,
056:                    JXPathBindingManager.Assistant assistant)
057:                    throws BindingException {
058:
059:                try {
060:                    CommonAttributes commonAtts = JXPathBindingBuilderBase
061:                            .getCommonAttributes(bindingElm);
062:
063:                    DocumentFragment domTemplate = null;
064:
065:                    String src = DomHelper
066:                            .getAttribute(bindingElm, "src", null);
067:                    if (src != null) {
068:                        ServiceManager manager = assistant.getServiceManager();
069:                        SourceResolver sourceResolver = (SourceResolver) manager
070:                                .lookup(SourceResolver.ROLE);
071:                        Source source = null;
072:                        try {
073:                            source = sourceResolver.resolveURI(src);
074:                            Document document = SourceUtil.toDOM(source);
075:                            Element element = document.getDocumentElement();
076:
077:                            String xpath = DomHelper.getAttribute(bindingElm,
078:                                    "xpath", null);
079:                            if (xpath != null) {
080:                                XPathProcessor xpathProcessor = (XPathProcessor) manager
081:                                        .lookup(XPathProcessor.ROLE);
082:                                try {
083:                                    Node node = xpathProcessor
084:                                            .selectSingleNode(document, xpath);
085:                                    if (node == null) {
086:                                        throw new BindingException(
087:                                                "XPath expression '"
088:                                                        + xpath
089:                                                        + "' didn't return a result.",
090:                                                DomHelper
091:                                                        .getLocationObject(bindingElm));
092:                                    }
093:                                    if (!(node instanceof  Element)) {
094:                                        throw new BindingException(
095:                                                "XPath expression '"
096:                                                        + xpath
097:                                                        + "' did not return an element node.",
098:                                                DomHelper
099:                                                        .getLocationObject(bindingElm));
100:                                    }
101:                                    element = (Element) node;
102:                                } finally {
103:                                    manager.release(xpathProcessor);
104:                                }
105:                            }
106:                            domTemplate = document.createDocumentFragment();
107:                            domTemplate.appendChild(element);
108:                        } finally {
109:                            if (source != null) {
110:                                sourceResolver.release(source);
111:                            }
112:                            manager.release(sourceResolver);
113:                        }
114:                    } else if (bindingElm.hasChildNodes()) {
115:                        // FIXME: using the binding's document prevents it to be garbage collected.
116:                        //        --> create a new Document and use doc.importNode();
117:                        domTemplate = bindingElm.getOwnerDocument()
118:                                .createDocumentFragment();
119:                        NodeList nested = bindingElm.getChildNodes();
120:                        int size = nested.getLength();
121:                        for (int i = 0; i < size; i++) {
122:                            Node node = nested.item(i).cloneNode(true);
123:                            if (node.getNodeType() == Node.ELEMENT_NODE) {
124:                                LocationAttributes.remove((Element) node, true);
125:                            }
126:                            domTemplate.appendChild(node);
127:                        }
128:                    }
129:
130:                    // do inheritance
131:                    InsertNodeJXPathBinding otherBinding = (InsertNodeJXPathBinding) assistant
132:                            .getContext().getSuperBinding();
133:                    if (otherBinding != null) {
134:                        commonAtts = JXPathBindingBuilderBase
135:                                .mergeCommonAttributes(otherBinding
136:                                        .getCommonAtts(), commonAtts);
137:
138:                        if (domTemplate == null) {
139:                            domTemplate = otherBinding.getTemplate();
140:                        }
141:                    }
142:
143:                    return new InsertNodeJXPathBinding(commonAtts, domTemplate);
144:                } catch (BindingException e) {
145:                    throw e;
146:                } catch (Exception e) {
147:                    throw new BindingException(
148:                            "Error building the insert-node binding", e,
149:                            DomHelper.getLocationObject(bindingElm));
150:                }
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.