Source Code Cross Referenced for Util.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » test » web » framework » 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 » ERP CRM Financial » Kuali Financial System » edu.iu.uis.eden.test.web.framework 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2007 The Kuali Foundation.
003:         * 
004:         * 
005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         * 
009:         * http://www.opensource.org/licenses/ecl1.php
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 edu.iu.uis.eden.test.web.framework;
018:
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.io.InputStreamReader;
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:        import java.util.Map;
025:
026:        import org.apache.log4j.Logger;
027:        import org.w3c.dom.NamedNodeMap;
028:        import org.w3c.dom.Node;
029:
030:        /**
031:         * Utility class
032:         * @author Aaron Hamid (arh14 at cornell dot edu)
033:         */
034:        public final class Util {
035:            private static final Logger LOG = Logger.getLogger(Util.class);
036:
037:            private Util() {
038:            }
039:
040:            // could DOM be any less usable...
041:            public static String getAttribute(Node node, String name) {
042:                NamedNodeMap attributes = node.getAttributes();
043:                if (attributes == null)
044:                    return null;
045:                Node attrNode = attributes.getNamedItem(name);
046:                if (attrNode == null)
047:                    return null;
048:                return attrNode.getNodeValue();
049:            }
050:
051:            private static String composeAttrName(String name, String type) {
052:                if (name != null) {
053:                    return name + "-" + type;
054:                } else {
055:                    return type;
056:                }
057:            }
058:
059:            public static String getAsString(Object o, String name) {
060:                if (!(o instanceof  String)) {
061:                    LOG.warn(name + " is not a string, coercing...");
062:                    if (o == null) {
063:                        return "";
064:                    } else {
065:                        return o.toString();
066:                    }
067:                } else {
068:                    return (String) o;
069:                }
070:            }
071:
072:            /**
073:             * Looks up a resolvable Property attribute from the given Element node.  Explicit variants of the attribute
074:             * name are inspected first, and then the plain name itself is inspected and a defaultScheme is used if none
075:             * is specified in the value. e.g.:
076:             * <someelement value-literal="foo" value-resource="foo" value-url="foo" value-variable="foo" value="foo"/>
077:             * The following code would look for exactly one of the above "value" attributes.  If only the "value" attribute
078:             * was found, then the defaultScheme would be used to qualify the value if the value did not already contain
079:             * a scheme.
080:             * If more than one variant is present, a RuntimeException is thrown.
081:             * @param node the element whose attributes to check
082:             * @param name the name of the attribute
083:             * @param defaultScheme the defaultScheme to qualify an unqualified value found in the attribute with the plain name
084:             * @return a Property if found, or null
085:             * @throws RuntimeException if more than one variant is found (or more than one variant of a given scheme, e.g. value-lit/value-literal)
086:             */
087:            public static Property getResolvableAttribute(Node node,
088:                    String name, PropertyScheme defaultScheme) {
089:                NamedNodeMap allAttributes = node.getAttributes();
090:                if (allAttributes == null)
091:                    return null;
092:
093:                Iterator schemes = PropertyScheme.SCHEMES.iterator();
094:                Map properties = new HashMap();
095:                while (schemes.hasNext()) {
096:                    PropertyScheme scheme = (PropertyScheme) schemes.next();
097:                    String[] names = new String[] { scheme.getName(),
098:                            scheme.getShortName() };
099:                    for (int i = 0; i < names.length; i++) {
100:                        String attrName = composeAttrName(name, names[i]);
101:                        //LOG.info("looking for attribute: " + attrName);
102:                        Node attrNode = allAttributes.getNamedItem(attrName);
103:                        if (attrNode != null) {
104:                            //LOG.info("found attribute: " + attrNode);
105:                            if (properties.containsKey(scheme)) {
106:                                throw new RuntimeException(
107:                                        "Already specified explicit attribute for scheme: "
108:                                                + scheme);
109:                            } else {
110:                                properties.put(scheme, new Property(names[i],
111:                                        attrNode.getNodeValue()));
112:                            }
113:                        }
114:                    }
115:                }
116:
117:                if (name != null) {
118:                    Node attrNode = allAttributes.getNamedItem(name);
119:                    if (attrNode != null) {
120:                        Property property = new Property(attrNode
121:                                .getNodeValue());
122:                        if (property.scheme == null && defaultScheme != null) {
123:                            property.scheme = defaultScheme.getName();
124:                        }
125:                        properties.put(defaultScheme, property);
126:                    }
127:                }
128:
129:                if (properties.size() > 1) {
130:                    throw new RuntimeException(
131:                            "Mutually exclusive explicit attributes present");
132:                } else if (properties.size() == 0) {
133:                    return null;
134:                }
135:
136:                // there can only be 1 at this point 
137:                return (Property) properties.values().iterator().next();
138:            }
139:
140:            public static String getContent(Node node) {
141:                Node textNode = node.getFirstChild();
142:                if (textNode != null
143:                        && textNode.getNodeType() == Node.TEXT_NODE) {
144:                    return textNode.getNodeValue();
145:                } else {
146:                    return null;
147:                }
148:            }
149:
150:            public static String readResource(InputStream stream)
151:                    throws IOException {
152:                StringBuffer sb = new StringBuffer(2048);
153:                InputStreamReader reader = new InputStreamReader(stream);
154:                char[] buf = new char[1024];
155:                int read;
156:                try {
157:                    while ((read = reader.read(buf)) != -1) {
158:                        sb.append(buf, 0, read);
159:                    }
160:                } finally {
161:                    reader.close();
162:                }
163:                return sb.toString();
164:            }
165:        }
w__w___w_.j___av___a__2_s__.com___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.