Source Code Cross Referenced for XMLLayoutDefinitionReader.java in  » IDE-Netbeans » visualweb.api.designer » com » sun » rave » web » ui » renderer » template » xml » 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 » IDE Netbeans » visualweb.api.designer » com.sun.rave.web.ui.renderer.template.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:        package com.sun.rave.web.ui.renderer.template.xml;
0042:
0043:        import com.sun.rave.web.ui.component.util.descriptors.ComponentType;
0044:        import com.sun.rave.web.ui.component.util.descriptors.LayoutAttribute;
0045:        import com.sun.rave.web.ui.component.util.descriptors.LayoutComponent;
0046:        import com.sun.rave.web.ui.component.util.descriptors.LayoutDefinition;
0047:        import com.sun.rave.web.ui.component.util.descriptors.LayoutElement;
0048:        import com.sun.rave.web.ui.component.util.descriptors.LayoutFacet;
0049:        import com.sun.rave.web.ui.component.util.descriptors.LayoutForEach;
0050:        import com.sun.rave.web.ui.component.util.descriptors.LayoutIf;
0051:        import com.sun.rave.web.ui.component.util.descriptors.LayoutMarkup;
0052:        import com.sun.rave.web.ui.component.util.descriptors.LayoutStaticText;
0053:        import com.sun.rave.web.ui.component.util.descriptors.LayoutWhile;
0054:        import com.sun.rave.web.ui.component.util.descriptors.Resource;
0055:        import com.sun.rave.web.ui.component.util.event.Handler;
0056:        import com.sun.rave.web.ui.component.util.event.HandlerDefinition;
0057:        import com.sun.rave.web.ui.component.util.event.IODescriptor;
0058:        import com.sun.rave.web.ui.util.IncludeInputStream;
0059:
0060:        import java.io.IOException;
0061:        import java.io.BufferedInputStream;
0062:        import java.io.InputStream;
0063:        import java.net.URL;
0064:        import java.util.ArrayList;
0065:        import java.util.HashMap;
0066:        import java.util.Iterator;
0067:        import java.util.List;
0068:        import java.util.Map;
0069:
0070:        import javax.xml.parsers.DocumentBuilder;
0071:        import javax.xml.parsers.DocumentBuilderFactory;
0072:        import javax.xml.parsers.ParserConfigurationException;
0073:
0074:        import org.w3c.dom.Document;
0075:        import org.w3c.dom.Element;
0076:        import org.w3c.dom.Node;
0077:        import org.w3c.dom.NodeList;
0078:        import org.w3c.dom.NamedNodeMap;
0079:
0080:        import org.xml.sax.EntityResolver;
0081:        import org.xml.sax.ErrorHandler;
0082:        import org.xml.sax.SAXException;
0083:
0084:        /**
0085:         *  <p>	This class is responsible for doing the actual parsing of an XML
0086:         *	document following the layout.dtd.  It produces a {@link LayoutElement}
0087:         *	tree with a {@link LayoutDefinition} object at the root of the tree.</p>
0088:         *
0089:         *  @author Ken Paulsen	(ken.paulsen@sun.com)
0090:         */
0091:        public class XMLLayoutDefinitionReader {
0092:
0093:            /**
0094:             *	Constructor.
0095:             *
0096:             *	@param	url		A URL pointing to the {@link LayoutDefinition}
0097:             *	@param	entityResolver	EntityResolver to use, may be (null)
0098:             *	@param	errorHandler	ErrorHandler to use, may be (null)
0099:             *	@param	baseURI		The base URI passed to DocumentBuilder.parse()
0100:             */
0101:            public XMLLayoutDefinitionReader(URL url,
0102:                    EntityResolver entityResolver, ErrorHandler errorHandler,
0103:                    String baseURI) {
0104:                _url = url;
0105:                _entityResolver = entityResolver;
0106:                _errorHandler = errorHandler;
0107:                _baseURI = baseURI;
0108:            }
0109:
0110:            /**
0111:             *	Accessor for the URL.
0112:             */
0113:            public URL getURL() {
0114:                return _url;
0115:            }
0116:
0117:            /**
0118:             *	Accessor for the entityResolver.
0119:             */
0120:            public EntityResolver getEntityResolver() {
0121:                return _entityResolver;
0122:            }
0123:
0124:            /**
0125:             *	Accessor for the ErrorHandler.
0126:             */
0127:            public ErrorHandler getErrorHandler() {
0128:                return _errorHandler;
0129:            }
0130:
0131:            /**
0132:             *	Accessor for the base URI.
0133:             */
0134:            public String getBaseURI() {
0135:                return _baseURI;
0136:            }
0137:
0138:            /**
0139:             *	<p> The read method opens the given URL and parses the XML document
0140:             *	    that it points to.  It then walks the DOM and populates a
0141:             *	    {@link LayoutDefinition} structure, which is returned.</p>
0142:             *
0143:             *	@return	The {@link LayoutDefinition}
0144:             *
0145:             *	@throws	IOException
0146:             */
0147:            public LayoutDefinition read() throws IOException {
0148:                // Open the URL
0149:                InputStream inputStream = new IncludeInputStream(
0150:                        new BufferedInputStream(getURL().openStream()));
0151:                Document doc = null;
0152:
0153:                try {
0154:                    // Get a DocumentBuilderFactory and set it up
0155:                    DocumentBuilderFactory dbf = DocumentBuilderFactory
0156:                            .newInstance();
0157:                    dbf.setNamespaceAware(true);
0158:                    dbf.setValidating(true);
0159:                    dbf.setIgnoringComments(true);
0160:                    dbf.setIgnoringElementContentWhitespace(false);
0161:                    dbf.setCoalescing(false);
0162:                    // The opposite of creating entity ref nodes is expanding inline
0163:                    dbf.setExpandEntityReferences(true);
0164:
0165:                    // Get a DocumentBuilder...
0166:                    DocumentBuilder db = null;
0167:                    try {
0168:                        db = dbf.newDocumentBuilder();
0169:                    } catch (ParserConfigurationException ex) {
0170:                        throw new RuntimeException(ex);
0171:                    }
0172:                    if (getEntityResolver() != null) {
0173:                        db.setEntityResolver(getEntityResolver());
0174:                    }
0175:                    if (getErrorHandler() != null) {
0176:                        db.setErrorHandler(getErrorHandler());
0177:                    }
0178:
0179:                    // Parse the XML file
0180:                    try {
0181:                        doc = db.parse(inputStream, getBaseURI());
0182:                    } catch (SAXException ex) {
0183:                        throw new RuntimeException(ex);
0184:                    }
0185:                } finally {
0186:                    try {
0187:                        inputStream.close();
0188:                    } catch (Exception ex) {
0189:                        // Ignore...
0190:                    }
0191:                }
0192:
0193:                // Populate the LayoutDefinition from the Document
0194:                return createLayoutDefinition(doc);
0195:            }
0196:
0197:            /**
0198:             *	This method is responsible for extracting all the information out of
0199:             *	the supplied document and filling the {@link LayoutDefinition} structure.
0200:             *
0201:             *	@param	doc	The Document object to read info from
0202:             *
0203:             *	@return	The new {@link LayoutDefinition} Object 
0204:             */
0205:            private LayoutDefinition createLayoutDefinition(Document doc) {
0206:                // Get the document element (LAYOUT_DEFINITION_ELEMENT)
0207:                Node node = doc.getDocumentElement();
0208:                if (!node.getNodeName().equalsIgnoreCase(
0209:                        LAYOUT_DEFINITION_ELEMENT)) {
0210:                    throw new RuntimeException("Document Element must be '"
0211:                            + LAYOUT_DEFINITION_ELEMENT + "'");
0212:                }
0213:
0214:                // Create a new LayoutDefinition (the id is not propagated here)
0215:                LayoutDefinition ld = new LayoutDefinition("");
0216:
0217:                // Do "resources" first, they are defined at the top of the document
0218:                List childElements = getChildElements(node, RESOURCES_ELEMENT);
0219:                Iterator it = childElements.iterator();
0220:                if (it.hasNext()) {
0221:                    // Found the RESOURCES_ELEMENT, there is at most 1
0222:                    addResources(ld, (Node) it.next());
0223:                }
0224:
0225:                // Do "types", they need to be defined before parsing the layout
0226:                childElements = getChildElements(node, TYPES_ELEMENT);
0227:                it = childElements.iterator();
0228:                if (it.hasNext()) {
0229:                    // Found the TYPES_ELEMENT, there is at most 1
0230:                    addTypes(ld, (Node) it.next());
0231:                }
0232:
0233:                // Do "handlers" next, they need to be defined before parsing the layout
0234:                childElements = getChildElements(node, HANDLERS_ELEMENT);
0235:                it = childElements.iterator();
0236:                if (it.hasNext()) {
0237:                    // Found the HANDLERS_ELEMENT, there is at most 1
0238:                    cacheHandlerDefs((Node) it.next());
0239:                }
0240:
0241:                // Look to see if there is an EVENT_ELEMENT defined
0242:                childElements = getChildElements(node, EVENT_ELEMENT);
0243:                it = childElements.iterator();
0244:                if (it.hasNext()) {
0245:                    // Found the EVENT_ELEMENT, there is at most 1
0246:                    // Get the event type
0247:                    Node eventNode = (Node) it.next();
0248:                    String type = (String) getAttributes(eventNode).get(
0249:                            TYPE_ATTRIBUTE);
0250:
0251:                    // Set the Handlers for the given event type (name)
0252:                    List handlers = ld.getHandlers(type);
0253:                    ld.setHandlers(type, getHandlers(eventNode, handlers));
0254:                }
0255:
0256:                // Next look for "layout", there is exactly 1
0257:                childElements = getChildElements(node, LAYOUT_ELEMENT);
0258:                it = childElements.iterator();
0259:                if (it.hasNext()) {
0260:                    // Found the LAYOUT_ELEMENT, there is only 1
0261:                    addChildLayoutElements(ld, (Node) it.next());
0262:                } else {
0263:                    throw new RuntimeException("A '" + LAYOUT_ELEMENT
0264:                            + "' element is required in the XML document!");
0265:                }
0266:
0267:                // Return the LayoutDefinition
0268:                return ld;
0269:            }
0270:
0271:            /**
0272:             *	This method iterates throught the child RESOURCE_ELEMENT nodes and
0273:             *	adds new resource objects to the {@link LayoutDefinition}.
0274:             *
0275:             *	@param	ld	The LayoutDefinition
0276:             *	@param	node	Parent Node containing the RESOURCE_ELEMENT nodes
0277:             */
0278:            private void addResources(LayoutDefinition ld, Node node) {
0279:                // Get the child nodes
0280:                Iterator it = getChildElements(node, RESOURCE_ELEMENT)
0281:                        .iterator();
0282:
0283:                // Walk children (we only care about RESOURCE_ELEMENT)
0284:                while (it.hasNext()) {
0285:                    // Found a RESOURCE_ELEMENT
0286:                    ld.addResource(createResource((Node) it.next()));
0287:                }
0288:            }
0289:
0290:            /**
0291:             *	This method takes the given Resource Element node and reads the
0292:             *	ID_ATTRIBUTE, EXTRA_INFO_ATTRIBUTE and FACTORY_CLASS_ATTRIBUTE
0293:             *	attributes.  It then instantiates a new Resource with the values of
0294:             *	these two attributes.
0295:             *
0296:             *	@param	node	The Resource node to extract information from
0297:             *			when creating the Resource
0298:             */
0299:            private Resource createResource(Node node) {
0300:                // Pull off the attributes
0301:                Map attributes = getAttributes(node);
0302:                String id = (String) attributes.get(ID_ATTRIBUTE);
0303:                String extraInfo = (String) attributes
0304:                        .get(EXTRA_INFO_ATTRIBUTE);
0305:                String factoryClass = (String) attributes
0306:                        .get(FACTORY_CLASS_ATTRIBUTE);
0307:
0308:                // Make sure required values are present
0309:                if ((factoryClass == null) || (id == null)
0310:                        || (extraInfo == null)
0311:                        || (factoryClass.trim().equals(""))
0312:                        || (id.trim().equals(""))
0313:                        || (extraInfo.trim().equals(""))) {
0314:                    throw new RuntimeException("'" + ID_ATTRIBUTE + "', '"
0315:                            + EXTRA_INFO_ATTRIBUTE + "', and '"
0316:                            + FACTORY_CLASS_ATTRIBUTE
0317:                            + "' are required attributes of '"
0318:                            + RESOURCE_ELEMENT + "' Element!");
0319:                }
0320:
0321:                // Create the new Resource
0322:                return new Resource(id, extraInfo, factoryClass);
0323:            }
0324:
0325:            /**
0326:             *	This method iterates through the child COMPONENT_TYPE_ELEMENT nodes
0327:             *	and adds new ComponentTypes to the {@link LayoutDefinition}.
0328:             *
0329:             *	@param	ld	The LayoutDefinition
0330:             *	@param	node	Parent Node containing the COMPONENT_TYPE_ELEMENT nodes
0331:             */
0332:            private void addTypes(LayoutDefinition ld, Node node) {
0333:                // Get the child nodes
0334:                Iterator it = getChildElements(node, COMPONENT_TYPE_ELEMENT)
0335:                        .iterator();
0336:
0337:                // Walk the COMPONENT_TYPE_ELEMENT elements
0338:                while (it.hasNext()) {
0339:                    ld.addComponentType(createComponentType((Node) it.next()));
0340:                }
0341:            }
0342:
0343:            /**
0344:             *	This method takes the given ComponentType Element node and reads the
0345:             *	ID_ATTRIBUTE and FACTORY_CLASS_ATTRIBUTE attributes.  It then
0346:             *	instantiates a new ComponentType with the values of these two
0347:             *	attributes.
0348:             *
0349:             *	@param	node	The ComponentType node to extract information from
0350:             *			when creating the ComponentType
0351:             */
0352:            private ComponentType createComponentType(Node node) {
0353:                // Pull off the attributes
0354:                Map attributes = getAttributes(node);
0355:                String id = (String) attributes.get(ID_ATTRIBUTE);
0356:                String factoryClass = (String) attributes
0357:                        .get(FACTORY_CLASS_ATTRIBUTE);
0358:
0359:                // Make sure required values are present
0360:                if ((factoryClass == null) || (id == null)
0361:                        || (factoryClass.trim().equals(""))
0362:                        || (id.trim().equals(""))) {
0363:                    throw new RuntimeException("Both '" + ID_ATTRIBUTE
0364:                            + "' and '" + FACTORY_CLASS_ATTRIBUTE
0365:                            + "' are required attributes of '"
0366:                            + COMPONENT_TYPE_ELEMENT + "' Element!");
0367:                }
0368:
0369:                // Create the new ComponentType
0370:                return new ComponentType(id, factoryClass);
0371:            }
0372:
0373:            /**
0374:             *	<p> This method iterates through the child HANDLER_DEFINITION_ELEMENT
0375:             *	    nodes and caches them, so they may be retrieved later by Handlers
0376:             *	    referring to them.</p>
0377:             *
0378:             *	@param	node	Parent Node containing HANDLER_DEFINITION_ELEMENT nodes
0379:             */
0380:            private void cacheHandlerDefs(Node node) {
0381:                HandlerDefinition def = null;
0382:
0383:                // Get the child nodes
0384:                Iterator it = getChildElements(node, HANDLER_DEFINITION_ELEMENT)
0385:                        .iterator();
0386:                while (it.hasNext()) {
0387:                    // Found a HANDLER_DEFINITION_ELEMENT, cache it
0388:                    def = createHandlerDefinition((Node) it.next());
0389:                    _handlerDefs.put(def.getId(), def);
0390:                }
0391:            }
0392:
0393:            /**
0394:             *	<p> This method takes the given HANDLER_DEFINITION_ELEMENT node and
0395:             *	    reads the ID_ATTRIBUTE, CLASS_NAME_ATTRIBUTE, and
0396:             *	    METHOD_NAME_ATTRIBUTE attributes.  It then instantiates a new
0397:             *	    HandlerDefinition object.</p>
0398:             *
0399:             *	<p> Next it looks to see if the HandlerDefinition has child inputDef,
0400:             *	    outputDef, and/or nested handler elements.  If so it processes
0401:             *	    them.</p>
0402:             *
0403:             *	@param	node	The HANDLER_DEFINITION_ELEMENT node to extract
0404:             *			information from when creating the HandlerDefinition.
0405:             *
0406:             *	@return	The newly created HandlerDefinition.
0407:             */
0408:            public HandlerDefinition createHandlerDefinition(Node node) {
0409:
0410:                // Create he HandlerDefinition
0411:                Map attributes = getAttributes(node);
0412:                String value = (String) attributes.get(ID_ATTRIBUTE);
0413:                HandlerDefinition hd = new HandlerDefinition(value);
0414:
0415:                // hd.setDescription(_description)
0416:
0417:                // Check for a className
0418:                value = (String) attributes.get(CLASS_NAME_ATTRIBUTE);
0419:                if ((value != null) && !value.equals("")) {
0420:                    // Found a className, now get the methodName
0421:                    String tmpStr = (String) attributes
0422:                            .get(METHOD_NAME_ATTRIBUTE);
0423:                    if ((tmpStr == null) || tmpStr.equals("")) {
0424:                        throw new IllegalArgumentException(
0425:                                "You must provide a '" + METHOD_NAME_ATTRIBUTE
0426:                                        + "' attribute on the '"
0427:                                        + HANDLER_DEFINITION_ELEMENT
0428:                                        + "' element with "
0429:                                        + CLASS_NAME_ATTRIBUTE
0430:                                        + " atttribute equal to '" + value
0431:                                        + "'.");
0432:                    }
0433:                    hd.setHandlerMethod(value, tmpStr);
0434:                }
0435:
0436:                // Add child handlers to this HandlerDefinition.  This allows a
0437:                // HandlerDefinition to define handlers that should be invoked before
0438:                // the method defined by this handler definition is invoked.
0439:                List handlers = hd.getChildHandlers();
0440:                hd.setChildHandlers(getHandlers(node, handlers));
0441:
0442:                // Add InputDef objects to the HandlerDefinition
0443:                addInputDefs(hd, node);
0444:
0445:                // Add OutputDef objects to the HandlerDefinition
0446:                addOutputDefs(hd, node);
0447:
0448:                // Return the newly created HandlerDefinition object
0449:                return hd;
0450:            }
0451:
0452:            /**
0453:             *	<p> This method creates a List of Handlers from the provided Node.  It
0454:             *	    will look at the child Elements for HANDLER_ELEMENT elements.
0455:             *	    When found, it will create a new Handler object and add it to a
0456:             *	    List that is created internally.  This List is returned.</p>
0457:             *
0458:             *	@param	node	    Node containing HANDLER_ELEMENT elements.
0459:             *	@param	handlers    List of existing handlers.
0460:             *
0461:             *	@return	A List of Handler objects, empty List if no Handlers found
0462:             */
0463:            private List getHandlers(Node node, List handlers) {
0464:                // Get the child nodes
0465:                Iterator it = getChildElements(node, HANDLER_ELEMENT)
0466:                        .iterator();
0467:
0468:                // Walk children (we only care about HANDLER_ELEMENT)
0469:                if (handlers == null) {
0470:                    handlers = new ArrayList();
0471:                }
0472:                while (it.hasNext()) {
0473:                    // Found a HANDLER_ELEMENT
0474:                    handlers.add(createHandler((Node) it.next()));
0475:                }
0476:
0477:                // Return the handlers
0478:                return handlers;
0479:            }
0480:
0481:            /**
0482:             *	<p> This method creates a Handler from the given HandlerNode.  It will
0483:             *	    add input and/or output mappings specified by any child Elements
0484:             *	    named INPUT_ELEMENT or OUTPUT_MAPPING_ELEMENT.</p>
0485:             *
0486:             *	@param	handlerNode	The Node describing the Handler to be created.
0487:             *
0488:             *	@return	The newly created Handler.
0489:             */
0490:            private Handler createHandler(Node handlerNode) {
0491:                // Pull off attributes...
0492:                String id = (String) getAttributes(handlerNode).get(
0493:                        ID_ATTRIBUTE);
0494:                if ((id == null) || (id.trim().equals(""))) {
0495:                    throw new RuntimeException("'" + ID_ATTRIBUTE
0496:                            + "' attribute not found on '" + HANDLER_ELEMENT
0497:                            + "' Element!");
0498:                }
0499:
0500:                // Find the HandlerDefinition associated with this Handler
0501:                HandlerDefinition handlerDef = (HandlerDefinition) _handlerDefs
0502:                        .get(id);
0503:                if (handlerDef == null) {
0504:                    throw new IllegalArgumentException(
0505:                            HANDLER_ELEMENT
0506:                                    + " elements "
0507:                                    + ID_ATTRIBUTE
0508:                                    + " attribute must match the "
0509:                                    + ID_ATTRIBUTE
0510:                                    + " attribute of a "
0511:                                    + HANDLER_DEFINITION_ELEMENT
0512:                                    + ".  A HANDLER_ELEMENT with '"
0513:                                    + id
0514:                                    + "' was specified, however there is no cooresponding "
0515:                                    + HANDLER_DEFINITION_ELEMENT
0516:                                    + " with a matching " + ID_ATTRIBUTE
0517:                                    + " attribute.");
0518:                }
0519:
0520:                // Create new Handler
0521:                Handler handler = new Handler(handlerDef);
0522:
0523:                // Add the inputs
0524:                Map attributes = null;
0525:                Node inputNode = null;
0526:                Iterator it = getChildElements(handlerNode, INPUT_ELEMENT)
0527:                        .iterator();
0528:                while (it.hasNext()) {
0529:                    // Processing an INPUT_ELEMENT
0530:                    inputNode = (Node) it.next();
0531:                    attributes = getAttributes(inputNode);
0532:                    handler.setInputValue((String) attributes
0533:                            .get(NAME_ATTRIBUTE), getValueFromNode(inputNode,
0534:                            attributes));
0535:                }
0536:
0537:                // Add the OutputMapping objects
0538:                it = getChildElements(handlerNode, OUTPUT_MAPPING_ELEMENT)
0539:                        .iterator();
0540:                while (it.hasNext()) {
0541:                    // Processing an OUTPUT_MAPPING_ELEMENT
0542:                    attributes = getAttributes((Node) it.next());
0543:                    handler.setOutputMapping((String) attributes
0544:                            .get(OUTPUT_NAME_ATTRIBUTE), (String) attributes
0545:                            .get(TARGET_KEY_ATTRIBUTE), (String) attributes
0546:                            .get(TARGET_TYPE_ATTRIBUTE));
0547:                }
0548:
0549:                // Return the newly created handler
0550:                return handler;
0551:            }
0552:
0553:            /**
0554:             *	<p> This method adds InputDefs to the given HandlerDefinition object.
0555:             *	    It will look at the child elements for those named
0556:             *	    INPUT_DEF_ELEMENT.  It will create an IODescriptor for each and add
0557:             *	    it to the HandlerDefinition.</p>
0558:             *
0559:             *	@param	hd	HandlerDefinition
0560:             *	@param	hdNode	HandlerDefinition Node, its children will be searched
0561:             */
0562:            private void addInputDefs(HandlerDefinition hd, Node hdNode) {
0563:                // Get the child nodes
0564:                Iterator it = getChildElements(hdNode, INPUT_DEF_ELEMENT)
0565:                        .iterator();
0566:
0567:                // Walk children (we only care about INPUT_DEF_ELEMENT)
0568:                while (it.hasNext()) {
0569:                    // Found a INPUT_DEF_ELEMENT
0570:                    hd.addInputDef(createIODescriptor((Node) it.next()));
0571:                }
0572:            }
0573:
0574:            /**
0575:             *	<p> This method adds OutputDefs to the given HandlerDefinition object.
0576:             *	    It will look at the child elements for those named
0577:             *	    OUTPUT_DEF_ELEMENT.  It will create an IODescriptor for each and
0578:             *	    add it to the HandlerDefinition.</p>
0579:             *
0580:             *	@param	hd	HandlerDefinition
0581:             *	@param	hdNode	HandlerDefinition Node, its children will be searched
0582:             */
0583:            private void addOutputDefs(HandlerDefinition hd, Node hdNode) {
0584:                // Get the child nodes
0585:                Iterator it = getChildElements(hdNode, OUTPUT_DEF_ELEMENT)
0586:                        .iterator();
0587:
0588:                // Walk children (we only care about OUTPUT_DEF_ELEMENT)
0589:                while (it.hasNext()) {
0590:                    // Found a OUTPUT_DEF_ELEMENT
0591:                    hd.addOutputDef(createIODescriptor((Node) it.next()));
0592:                }
0593:            }
0594:
0595:            /** 
0596:             *	<p> This method will create an IODescriptor from the given node.  The
0597:             *	    node must contain atleast a NAME_ATTRIBUTE and a TYPE_ATTRIBUTE
0598:             *	    attribute.  It may also contain a DEFAULT_ATTRIBUTE and a
0599:             *	    REQUIRED_ATTRIBUTE.  These are only meaningful for input
0600:             *	    IODescriptors, however -- this method does not know the difference
0601:             *	    between input and output descriptors.</p>
0602:             *
0603:             *	@param	node	The node holding info used to create an IODescriptor.
0604:             *
0605:             *	@return	A newly created IODescriptor.
0606:             */
0607:            private IODescriptor createIODescriptor(Node node) {
0608:                // Get the attributes
0609:                Map attributes = getAttributes(node);
0610:                String name = (String) attributes.get(NAME_ATTRIBUTE);
0611:                if ((name == null) || name.equals("")) {
0612:                    throw new IllegalArgumentException("Name must be provided!");
0613:                }
0614:                String type = (String) attributes.get(TYPE_ATTRIBUTE);
0615:                if ((type == null) || type.equals("")) {
0616:                    throw new IllegalArgumentException("Type must be provided!");
0617:                }
0618:                Object def = attributes.get(DEFAULT_ATTRIBUTE);
0619:                String req = (String) attributes.get(REQUIRED_ATTRIBUTE);
0620:
0621:                // Create the IODescriptor
0622:                IODescriptor ioDesc = new IODescriptor(name, type);
0623:                ioDesc.setDefault(def);
0624:                if (req != null) {
0625:                    ioDesc.setRequired(Boolean.valueOf(req).booleanValue());
0626:                }
0627:                // ioDesc.setDescription(attributes.get(DESCRIPTION_ATTRIBUTE))
0628:
0629:                // Return the new IODescriptor
0630:                return ioDesc;
0631:            }
0632:
0633:            /**
0634:             *	This method adds ...
0635:             *
0636:             *	@param	ld
0637:             *	@param	node
0638:             */
0639:            private void addChildLayoutElements(LayoutElement layElt, Node node) {
0640:                // Get the child nodes
0641:                Iterator it = getChildElements(node).iterator();
0642:
0643:                // Walk children (we care about IF_ELEMENT, ATTRIBUTE_ELEMENT,
0644:                // MARKUP_ELEMENT, FACET_ELEMENT, STATIC_TEXT_ELEMENT,
0645:                // COMPONENT_ELEMENT, EVENT_ELEMENT, FOREACH_ELEMENT, and
0646:                // WHILE_ELEMENT)
0647:                Node childNode = null;
0648:                String name = null;
0649:                while (it.hasNext()) {
0650:                    childNode = (Node) it.next();
0651:                    name = childNode.getNodeName();
0652:                    if (name.equalsIgnoreCase(IF_ELEMENT)) {
0653:                        // Found a IF_ELEMENT
0654:                        layElt.addChildLayoutElement(createLayoutIf(layElt,
0655:                                childNode));
0656:                    } else if (name.equalsIgnoreCase(ATTRIBUTE_ELEMENT)) {
0657:                        // Found a ATTRIBUTE_ELEMENT
0658:                        layElt.addChildLayoutElement(createLayoutAttribute(
0659:                                layElt, childNode));
0660:                    } else if (name.equalsIgnoreCase(MARKUP_ELEMENT)) {
0661:                        // Found a MARKUP_ELEMENT
0662:                        layElt.addChildLayoutElement(createLayoutMarkup(layElt,
0663:                                childNode));
0664:                    } else if (name.equalsIgnoreCase(FACET_ELEMENT)) {
0665:                        // Found a FACET_ELEMENT
0666:                        layElt.addChildLayoutElement(createLayoutFacet(layElt,
0667:                                childNode));
0668:                    } else if (name.equalsIgnoreCase(STATIC_TEXT_ELEMENT)) {
0669:                        // Found a STATIC_TEXT_ELEMENT
0670:                        layElt.addChildLayoutElement(createLayoutStaticText(
0671:                                layElt, childNode));
0672:                    } else if (name.equalsIgnoreCase(COMPONENT_ELEMENT)) {
0673:                        // Found a COMPONENT_ELEMENT
0674:                        layElt.addChildLayoutElement(createLayoutComponent(
0675:                                layElt, childNode));
0676:                    } else if (name.equalsIgnoreCase(EVENT_ELEMENT)) {
0677:                        // Found a EVENT_ELEMENT
0678:                        // Get the event type
0679:                        name = (String) getAttributes(childNode).get(
0680:                                TYPE_ATTRIBUTE);
0681:                        // Set the Handlers for the given event type (name)
0682:                        List handlers = layElt.getHandlers(name);
0683:                        layElt.setHandlers(name, getHandlers(childNode,
0684:                                handlers));
0685:                    } else if (name.equalsIgnoreCase(FOREACH_ELEMENT)) {
0686:                        // Found a FOREACH_ELEMENT
0687:                        layElt.addChildLayoutElement(createLayoutForEach(
0688:                                layElt, childNode));
0689:                    } else if (name.equalsIgnoreCase(WHILE_ELEMENT)) {
0690:                        // Found a WHILE_ELEMENT
0691:                        layElt.addChildLayoutElement(createLayoutWhile(layElt,
0692:                                childNode));
0693:                    } else {
0694:                        throw new RuntimeException("Unknown Element Found: '"
0695:                                + childNode.getNodeName() + "' under '"
0696:                                + node.getNodeName() + "'.");
0697:                    }
0698:                }
0699:            }
0700:
0701:            /**
0702:             *	<p> This method creates a new {@link LayoutIf}
0703:             *	    {@link LayoutElement}.</p>
0704:             *
0705:             *	@param	parent	The parent LayoutElement.
0706:             *	@param	node	The {@link IF_ELEMENT} node to extract information from
0707:             *			when creating the LayoutIf
0708:             */
0709:            private LayoutElement createLayoutIf(LayoutElement parent, Node node) {
0710:                // Pull off attributes...
0711:                String condition = (String) getAttributes(node).get(
0712:                        CONDITION_ATTRIBUTE);
0713:                if ((condition == null) || (condition.trim().equals(""))) {
0714:                    throw new RuntimeException("'" + CONDITION_ATTRIBUTE
0715:                            + "' attribute not found on '" + IF_ELEMENT
0716:                            + "' Element!");
0717:                }
0718:
0719:                // Create new LayoutIf
0720:                LayoutElement ifElt = new LayoutIf(parent, condition);
0721:
0722:                // Add children...
0723:                addChildLayoutElements(ifElt, node);
0724:
0725:                // Return the if
0726:                return ifElt;
0727:            }
0728:
0729:            /**
0730:             *	<p> This method creates a new {@link LayoutForEach}
0731:             *	    {@link LayoutElement}.</p>
0732:             *
0733:             *	@param	parent	The parent {@link LayoutElement}.
0734:             *	@param	node	The {@link #FOREACH_ELEMENT} node to extract
0735:             *			information from when creating the
0736:             *			{@link LayoutForEach}.
0737:             *
0738:             *	@return The new {@link LayoutForEach} {@link LayoutElement}.
0739:             */
0740:            private LayoutElement createLayoutForEach(LayoutElement parent,
0741:                    Node node) {
0742:                // Pull off attributes...
0743:                String list = (String) getAttributes(node).get(LIST_ATTRIBUTE);
0744:                if ((list == null) || (list.trim().equals(""))) {
0745:                    throw new RuntimeException("'" + LIST_ATTRIBUTE
0746:                            + "' attribute not found on '" + FOREACH_ELEMENT
0747:                            + "' Element!");
0748:                }
0749:                String key = (String) getAttributes(node).get(KEY_ATTRIBUTE);
0750:                if ((key == null) || (key.trim().equals(""))) {
0751:                    throw new RuntimeException("'" + KEY_ATTRIBUTE
0752:                            + "' attribute not found on '" + FOREACH_ELEMENT
0753:                            + "' Element!");
0754:                }
0755:
0756:                // Create new LayoutForEach
0757:                LayoutElement forEachElt = new LayoutForEach(parent, list, key);
0758:
0759:                // Add children...
0760:                addChildLayoutElements(forEachElt, node);
0761:
0762:                // Return the forEach
0763:                return forEachElt;
0764:            }
0765:
0766:            /**
0767:             *	<p> This method creates a new {@link LayoutWhile}
0768:             *	    {@link LayoutElement}.</p>
0769:             *
0770:             *	@param	parent	The parent {@link LayoutElement}.
0771:             *	@param	node	The {@link #WHILE_ELEMENT} node to extract information
0772:             *			from when creating the LayoutWhile.
0773:             *
0774:             *	@return The new {@link LayoutWhile} {@link LayoutElement}.
0775:             */
0776:            private LayoutElement createLayoutWhile(LayoutElement parent,
0777:                    Node node) {
0778:                // Pull off attributes...
0779:                String condition = (String) getAttributes(node).get(
0780:                        CONDITION_ATTRIBUTE);
0781:                if ((condition == null) || (condition.trim().equals(""))) {
0782:                    throw new RuntimeException("'" + CONDITION_ATTRIBUTE
0783:                            + "' attribute not found on '" + WHILE_ELEMENT
0784:                            + "' Element!");
0785:                }
0786:
0787:                // Create new LayoutWhile
0788:                LayoutElement whileElt = new LayoutWhile(parent, condition);
0789:
0790:                // Add children...
0791:                addChildLayoutElements(whileElt, node);
0792:
0793:                // Return the while
0794:                return whileElt;
0795:            }
0796:
0797:            /**
0798:             *
0799:             *
0800:             *	@param	parent	The parent {@link LayoutElement}.
0801:             *	@param	node	The ATTRIBUTE_ELEMENT node to extract information from
0802:             *			when creating the LayoutAttribute
0803:             */
0804:            private LayoutElement createLayoutAttribute(LayoutElement parent,
0805:                    Node node) {
0806:                // Pull off attributes...
0807:                Map attributes = getAttributes(node);
0808:                String name = (String) attributes.get(NAME_ATTRIBUTE);
0809:                if ((name == null) || (name.trim().equals(""))) {
0810:                    throw new RuntimeException("'" + NAME_ATTRIBUTE
0811:                            + "' attribute not found on '" + ATTRIBUTE_ELEMENT
0812:                            + "' Element!");
0813:                }
0814:                String value = (String) attributes.get(VALUE_ATTRIBUTE);
0815:                String property = (String) attributes.get(PROPERTY_ATTRIBUTE);
0816:
0817:                // Create new LayoutAttribute
0818:                LayoutElement attributeElt = new LayoutAttribute(parent, name,
0819:                        value, property);
0820:
0821:                // Add children... (event children are supported)
0822:                addChildLayoutElements(attributeElt, node);
0823:
0824:                // Return the LayoutAttribute
0825:                return attributeElt;
0826:            }
0827:
0828:            /**
0829:             *
0830:             *
0831:             *	@param	parent	The parent {@link LayoutElement}.
0832:             *	@param	node	The MARKUP_ELEMENT node to extract information from
0833:             *			when creating the LayoutMarkup
0834:             */
0835:            private LayoutElement createLayoutMarkup(LayoutElement parent,
0836:                    Node node) {
0837:                // Pull off attributes...
0838:                Map attributes = getAttributes(node);
0839:                String tag = (String) attributes.get(TAG_ATTRIBUTE);
0840:                if ((tag == null) || (tag.trim().equals(""))) {
0841:                    throw new RuntimeException("'" + TAG_ATTRIBUTE
0842:                            + "' attribute not found on '" + MARKUP_ELEMENT
0843:                            + "' Element!");
0844:                }
0845:                String type = (String) attributes.get(TYPE_ATTRIBUTE);
0846:
0847:                // Create new LayoutMarkup
0848:                LayoutElement markupElt = new LayoutMarkup(parent, tag, type);
0849:
0850:                // Add children...
0851:                addChildLayoutElements(markupElt, node);
0852:
0853:                // Return the LayoutMarkup
0854:                return markupElt;
0855:            }
0856:
0857:            /**
0858:             *
0859:             *
0860:             *	@param	parent	The parent {@link LayoutElement}.
0861:             *	@param	node	The FACET_ELEMENT node to extract information from
0862:             *			when creating the LayoutFacet
0863:             */
0864:            private LayoutElement createLayoutFacet(LayoutElement parent,
0865:                    Node node) {
0866:                // Pull off attributes...
0867:                // id
0868:                String id = (String) getAttributes(node).get(ID_ATTRIBUTE);
0869:                if ((id == null) || (id.trim().equals(""))) {
0870:                    throw new RuntimeException("'" + ID_ATTRIBUTE
0871:                            + "' attribute not found on '" + FACET_ELEMENT
0872:                            + "' Element!");
0873:                }
0874:
0875:                // isRendered
0876:                String rendered = (String) getAttributes(node).get(
0877:                        RENDERED_ATTRIBUTE);
0878:                boolean isRendered = true;
0879:                if ((rendered == null) || rendered.trim().equals("")
0880:                        || rendered.equals(AUTO_RENDERED)) {
0881:                    // Automatically determine if this LayoutFacet should be rendered
0882:                    rendered = AUTO_RENDERED;
0883:                    LayoutElement layoutComponent = parent;
0884:                    while (layoutComponent != null) {
0885:                        if (layoutComponent instanceof  LayoutComponent) {
0886:                            isRendered = false;
0887:                            break;
0888:                        }
0889:                        layoutComponent = layoutComponent.getParent();
0890:                    }
0891:                } else {
0892:                    isRendered = Boolean.getBoolean(rendered);
0893:                }
0894:
0895:                // Create new LayoutFacet
0896:                LayoutFacet facetElt = new LayoutFacet(parent, id);
0897:                facetElt.setRendered(isRendered);
0898:
0899:                // Add children...
0900:                addChildLayoutElements(facetElt, node);
0901:
0902:                // Return the LayoutFacet
0903:                return facetElt;
0904:            }
0905:
0906:            /**
0907:             *	<p> This method returns true if any of the parent
0908:             *	    {@link LayoutElement}s are {@link LayoutComponent}s.</p>
0909:             *
0910:             *	@param	elt	The LayoutElement to check.
0911:             *
0912:             *	@return true if it has a LayoutComponent ancestor.
0913:             */
0914:            private static boolean hasLayoutComponentAncestor(LayoutElement elt) {
0915:                elt = elt.getParent();
0916:                while (elt != null) {
0917:                    if (elt instanceof  LayoutComponent) {
0918:                        return true;
0919:                    } else if (elt instanceof  LayoutFacet) {
0920:                        // Don't consider it a child if it is a facet
0921:                        return false;
0922:                    }
0923:                    elt = elt.getParent();
0924:                }
0925:
0926:                // Not found
0927:                return false;
0928:            }
0929:
0930:            /**
0931:             *
0932:             *
0933:             *	@param	node	The COMPONENT_ELEMENT node to extract information from
0934:             *			when creating the LayoutComponent
0935:             */
0936:            private LayoutElement createLayoutComponent(LayoutElement parent,
0937:                    Node node) {
0938:                // Pull off attributes...
0939:                Map attributes = getAttributes(node);
0940:                String id = (String) attributes.get(ID_ATTRIBUTE);
0941:                String type = (String) attributes.get(TYPE_ATTRIBUTE);
0942:                if ((type == null) || (type.trim().equals(""))) {
0943:                    throw new RuntimeException("'" + TYPE_ATTRIBUTE
0944:                            + "' attribute not found on '" + COMPONENT_ELEMENT
0945:                            + "' Element!");
0946:                }
0947:
0948:                // Create new LayoutComponent
0949:                LayoutComponent component = new LayoutComponent(parent, id,
0950:                        getComponentType(parent, type));
0951:
0952:                // Check for overwrite flag
0953:                String overwrite = (String) attributes.get(OVERWRITE_ATTRIBUTE);
0954:                if ((overwrite != null) && (overwrite.length() > 0)) {
0955:                    component.setOverwrite(Boolean.valueOf(overwrite)
0956:                            .booleanValue());
0957:                }
0958:
0959:                if (hasLayoutComponentAncestor(component)) {
0960:                    component.setFacetChild(false);
0961:                } else {
0962:                    // Need to add this so that it has the correct facet name
0963:                    // Check to see if this LayoutComponent is inside a LayoutFacet
0964:                    while (parent != null) {
0965:                        if (parent instanceof  LayoutFacet) {
0966:                            // Inside a LayoutFacet, use its id... only if this facet
0967:                            // is a child of a LayoutComponent (otherwise, it is a
0968:                            // layout facet used for layout, not for defining a facet
0969:                            // of a UIComponent)
0970:                            if (hasLayoutComponentAncestor(parent)) {
0971:                                id = parent.getUnevaluatedId();
0972:                                break;
0973:                            }
0974:                        }
0975:                        if (parent instanceof  LayoutComponent) {
0976:                            // Not inside a LayoutFacet
0977:                            break;
0978:                        }
0979:                        parent = parent.getParent();
0980:                    }
0981:                    // Set the facet name
0982:                    component.addOption(LayoutComponent.FACET_NAME, id);
0983:                }
0984:
0985:                // Add children... (different for component LayoutElements)
0986:                addChildLayoutComponentChildren(component, node);
0987:
0988:                // Return the LayoutComponent
0989:                return component;
0990:            }
0991:
0992:            /**
0993:             *
0994:             */
0995:            private void addChildLayoutComponentChildren(
0996:                    LayoutComponent component, Node node) {
0997:                // Get the child nodes
0998:                Iterator it = getChildElements(node).iterator();
0999:
1000:                // Walk children (we care about FACET_ELEMENT and OPTION_ELEMENT)
1001:                Node childNode = null;
1002:                String name = null;
1003:                while (it.hasNext()) {
1004:                    childNode = (Node) it.next();
1005:                    name = childNode.getNodeName();
1006:                    if (name.equalsIgnoreCase(COMPONENT_ELEMENT)) {
1007:                        // Found a COMPONENT_ELEMENT
1008:                        component.addChildLayoutElement(createLayoutComponent(
1009:                                component, childNode));
1010:                    } else if (name.equalsIgnoreCase(FACET_ELEMENT)) {
1011:                        // Found a FACET_ELEMENT
1012:                        component.addChildLayoutElement(createLayoutFacet(
1013:                                component, childNode));
1014:                    } else if (name.equalsIgnoreCase(OPTION_ELEMENT)) {
1015:                        // Found a OPTION_ELEMENT
1016:                        addOption(component, childNode);
1017:                    } else if (name.equalsIgnoreCase(EVENT_ELEMENT)) {
1018:                        // Found a EVENT_ELEMENT
1019:                        // Get the event type
1020:                        name = (String) getAttributes(childNode).get(
1021:                                TYPE_ATTRIBUTE);
1022:
1023:                        // Set the Handlers for the given event type (name)
1024:                        List handlers = component.getHandlers(name);
1025:                        component.setHandlers(name, getHandlers(childNode,
1026:                                handlers));
1027:                    } else {
1028:                        throw new RuntimeException("Unknown Element Found: '"
1029:                                + childNode.getNodeName() + "' under '"
1030:                                + COMPONENT_ELEMENT + "'.");
1031:                    }
1032:                }
1033:            }
1034:
1035:            /**
1036:             *	This method adds an option to the given LayoutComponent based on the
1037:             *	information in the given OPTION_ELEMENT Node.
1038:             *
1039:             *	@param	component   The LayoutComponent
1040:             *	@param	node	    The OPTION_ELEMENT node
1041:             */
1042:            private void addOption(LayoutComponent component, Node node) {
1043:                // Pull off the attributes
1044:                Map attributes = getAttributes(node);
1045:
1046:                // Get the name
1047:                String name = (String) attributes.get(NAME_ATTRIBUTE);
1048:                if ((name == null) || (name.trim().equals(""))) {
1049:                    throw new RuntimeException("'" + NAME_ATTRIBUTE
1050:                            + "' attribute not found on '" + OPTION_ELEMENT
1051:                            + "' Element!");
1052:                }
1053:                name = name.trim();
1054:
1055:                // Get the value
1056:                Object value = getValueFromNode(node, attributes);
1057:
1058:                // Add the option to the component (value may be null)
1059:                component.addOption(name, value);
1060:            }
1061:
1062:            /**
1063:             *	<p> This method reads obtains the VALUE_ATTRIBUTE from the given node,
1064:             *	    or from the child LIST_ELEMENT element.  If neither are provided,
1065:             *	    null is returned.  The attribute takes precedence over the child
1066:             *	    LIST_ELEMENT element.</p>
1067:             *
1068:             *	@param	node	    Node containing the value attribute or LIST_ELEMENT
1069:             *	@param	attributes  Map of attributes which may contain VALUE_ATTRIBUTE
1070:             *
1071:             *	@return	The value (as a String or List), or null if not specified
1072:             */
1073:            private Object getValueFromNode(Node node, Map attributes) {
1074:                Object value = attributes.get(VALUE_ATTRIBUTE);
1075:                if (value == null) {
1076:                    // The value attribute may be null if multiple values are supplied.
1077:                    // Walk children (we only care about LIST_ELEMENT)
1078:                    List list = new ArrayList();
1079:                    Iterator it = getChildElements(node, LIST_ELEMENT)
1080:                            .iterator();
1081:                    while (it.hasNext()) {
1082:                        // Add a value to the List
1083:                        list.add(getAttributes((Node) it.next()).get(
1084:                                VALUE_ATTRIBUTE));
1085:                    }
1086:                    if (list.size() > 0) {
1087:                        // Only use the list if it has values
1088:                        value = list;
1089:                    }
1090:                }
1091:                return value;
1092:            }
1093:
1094:            /**
1095:             *
1096:             *
1097:             *	@param	node	The STATIC_TEXT_ELEMENT node to extract information
1098:             *			from when creating the {@link LayoutStaticText}
1099:             */
1100:            private LayoutElement createLayoutStaticText(LayoutElement parent,
1101:                    Node node) {
1102:                // Create new LayoutComponent
1103:                LayoutStaticText text = new LayoutStaticText(parent, "",
1104:                        getTextNodesAsString(node));
1105:
1106:                // Add all the attributes from the static text as options
1107:                //	component.addOptions(getAttributes(node));
1108:
1109:                // Add escape... FIXME
1110:
1111:                // Return the LayoutStaticText
1112:                return text;
1113:            }
1114:
1115:            //////////////////////////////////////////////////////////////////////
1116:            //	Utility Methods
1117:            //////////////////////////////////////////////////////////////////////
1118:
1119:            /**
1120:             *	This method returns a List of all child Elements below the given Node.
1121:             *
1122:             *	@param	node	The node to pull child elements from.
1123:             *
1124:             *	@return	List of child elements found below the given node.
1125:             */
1126:            public List getChildElements(Node node) {
1127:                return getChildElements(node, null);
1128:            }
1129:
1130:            /**
1131:             *	<p> This method returns a List of all child Elements below the given
1132:             *	    Node matching the given name.  If name equals null, all Elements
1133:             *	    below this node will be returned.</p>
1134:             *
1135:             *	@param	node	The node to pull child elements from.
1136:             *	@param	name	The name of the Elements to return.
1137:             *
1138:             *	@return	List of child elements found below the given node matching
1139:             *		the name (if provided).
1140:             */
1141:            public List getChildElements(Node node, String name) {
1142:                // Get the child nodes
1143:                NodeList nodes = node.getChildNodes();
1144:                if (nodes == null) {
1145:                    // No children, just return an empty List
1146:                    return new ArrayList(0);
1147:                }
1148:
1149:                // Create a new List to store the child Elements
1150:                List list = new ArrayList();
1151:
1152:                // Add all the child Elements to the List
1153:                Node childNode = null;
1154:                for (int idx = 0; idx < nodes.getLength(); idx++) {
1155:                    childNode = nodes.item(idx);
1156:                    if (childNode.getNodeType() != Node.ELEMENT_NODE) {
1157:                        // Skip TEXT_NODE and other Node types
1158:                        continue;
1159:                    }
1160:
1161:                    // Add to the list if name is null, or it matches the node name
1162:                    if ((name == null)
1163:                            || childNode.getNodeName().equalsIgnoreCase(name)) {
1164:                        list.add(childNode);
1165:                    }
1166:                }
1167:
1168:                // Return the list of Elements
1169:                return list;
1170:            }
1171:
1172:            /**
1173:             *	This method returns the String representation of all the
1174:             *	Node.TEXT_NODE nodes that are children of the given Node.
1175:             *
1176:             *	@param	node	The node to pull child elements from.
1177:             *
1178:             *	@return	The String representation of all the Node.TEXT_NODE type nodes
1179:             *		under the given node.
1180:             */
1181:            public String getTextNodesAsString(Node node) {
1182:                // Get the child nodes
1183:                NodeList nodes = node.getChildNodes();
1184:                if (nodes == null) {
1185:                    // No children, return null
1186:                    return null;
1187:                }
1188:
1189:                // Create a StringBuffer
1190:                StringBuffer buf = new StringBuffer("");
1191:
1192:                // Add all the child Element values to the StringBuffer
1193:                Node childNode = null;
1194:                for (int idx = 0; idx < nodes.getLength(); idx++) {
1195:                    childNode = nodes.item(idx);
1196:                    if ((childNode.getNodeType() != Node.TEXT_NODE)
1197:                            && (childNode.getNodeType() != Node.CDATA_SECTION_NODE)) {
1198:                        // Skip all other Node types
1199:                        continue;
1200:                    }
1201:                    buf.append(childNode.getNodeValue());
1202:                }
1203:
1204:                // Return the String
1205:                return buf.toString();
1206:            }
1207:
1208:            /**
1209:             *	This method returns a Map of all attributes for the given Node.  Each
1210:             *	attribute name will be stored in the map in lower case so case can be
1211:             *	ignored.
1212:             *
1213:             *	@param	node	The node to pull attributes from.
1214:             *
1215:             *	@return	Map of attributes found on the given node.
1216:             */
1217:            public Map getAttributes(Node node) {
1218:                // Get the attributes
1219:                NamedNodeMap attributes = node.getAttributes();
1220:                if ((attributes == null) || (attributes.getLength() == 0)) {
1221:                    // No attributes, just return an empty Map
1222:                    return new HashMap(0);
1223:                }
1224:
1225:                // Create a Map to contain the attributes
1226:                Map map = new HashMap();
1227:
1228:                // Add all the attributes to the Map
1229:                Node attNode = null;
1230:                for (int idx = 0; idx < attributes.getLength(); idx++) {
1231:                    attNode = attributes.item(idx);
1232:                    map.put(attNode.getNodeName().toLowerCase(), attNode
1233:                            .getNodeValue());
1234:                }
1235:
1236:                // Return the map
1237:                return map;
1238:            }
1239:
1240:            /**
1241:             *	This utility method returns the requested component type.  If it is
1242:             *	not found, it throws an IllegalArgumentException.
1243:             *
1244:             *	@param	elt	A LayoutElement whose root is {@link LayoutDefinition}
1245:             *	@param	type	The String type to lookup
1246:             *
1247:             *	@return the ComponentType
1248:             */
1249:            public ComponentType getComponentType(LayoutElement elt, String type) {
1250:                // Find the ComponentType
1251:                ComponentType componentType = elt.getLayoutDefinition()
1252:                        .getComponentType(type);
1253:                if (componentType == null) {
1254:                    throw new IllegalArgumentException("ComponentType '" + type
1255:                            + "' not defined!");
1256:                }
1257:                return componentType;
1258:            }
1259:
1260:            //////////////////////////////////////////////////////////////////////
1261:            //	Constants
1262:            //////////////////////////////////////////////////////////////////////
1263:
1264:            public static final String ATTRIBUTE_ELEMENT = "attribute";
1265:            public static final String COMPONENT_ELEMENT = "component";
1266:            public static final String COMPONENT_TYPE_ELEMENT = "componenttype";
1267:            public static final String EVENT_ELEMENT = "event";
1268:            public static final String FACET_ELEMENT = "facet";
1269:            public static final String FOREACH_ELEMENT = "foreach";
1270:            public static final String HANDLER_ELEMENT = "handler";
1271:            public static final String HANDLERS_ELEMENT = "handlers";
1272:            public static final String HANDLER_DEFINITION_ELEMENT = "handlerdefinition";
1273:            public static final String IF_ELEMENT = "if";
1274:            public static final String INPUT_DEF_ELEMENT = "inputdef";
1275:            public static final String INPUT_ELEMENT = "input";
1276:            public static final String LAYOUT_DEFINITION_ELEMENT = "layoutdefinition";
1277:            public static final String LAYOUT_ELEMENT = "layout";
1278:            public static final String LIST_ELEMENT = "list";
1279:            public static final String MARKUP_ELEMENT = "markup";
1280:            public static final String OPTION_ELEMENT = "option";
1281:            public static final String OUTPUT_DEF_ELEMENT = "outputdef";
1282:            public static final String OUTPUT_MAPPING_ELEMENT = "outputmapping";
1283:            public static final String STATIC_TEXT_ELEMENT = "statictext";
1284:            public static final String TYPES_ELEMENT = "types";
1285:            public static final String RESOURCES_ELEMENT = "resources";
1286:            public static final String RESOURCE_ELEMENT = "resource";
1287:            public static final String WHILE_ELEMENT = "while";
1288:
1289:            public static final String CLASS_NAME_ATTRIBUTE = "classname";
1290:            public static final String CONDITION_ATTRIBUTE = "condition";
1291:            public static final String DEFAULT_ATTRIBUTE = "default";
1292:            public static final String DESCRIPTION_ATTRIBUTE = "description";
1293:            public static final String EXTRA_INFO_ATTRIBUTE = "extrainfo";
1294:            public static final String FACTORY_CLASS_ATTRIBUTE = "factoryclass";
1295:            public static final String ID_ATTRIBUTE = "id";
1296:            public static final String KEY_ATTRIBUTE = "key";
1297:            public static final String LIST_ATTRIBUTE = "list";
1298:            public static final String METHOD_NAME_ATTRIBUTE = "methodname";
1299:            public static final String NAME_ATTRIBUTE = "name";
1300:            public static final String OUTPUT_NAME_ATTRIBUTE = "outputname";
1301:            public static final String OVERWRITE_ATTRIBUTE = "overwrite";
1302:            public static final String PROPERTY_ATTRIBUTE = "property";
1303:            public static final String RENDERED_ATTRIBUTE = "rendered";
1304:            public static final String REQUIRED_ATTRIBUTE = "required";
1305:            public static final String TAG_ATTRIBUTE = "tag";
1306:            public static final String TARGET_KEY_ATTRIBUTE = "targetkey";
1307:            public static final String TARGET_TYPE_ATTRIBUTE = "targettype";
1308:            public static final String TYPE_ATTRIBUTE = "type";
1309:            public static final String VALUE_ATTRIBUTE = "value";
1310:
1311:            public static final String AUTO_RENDERED = "auto";
1312:
1313:            /**
1314:             *	This is used to set the "value" option for static text fields.
1315:             */
1316:            //    public static final String VALUE_OPTION	=   "value";
1317:            private URL _url = null;
1318:            private EntityResolver _entityResolver = null;
1319:            private ErrorHandler _errorHandler = null;
1320:            private String _baseURI = null;
1321:
1322:            private Map _handlerDefs = new HashMap();
1323:        }
ww_w__.__j___av_a_2___s._co_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.