Source Code Cross Referenced for UrlQueryParser.java in  » Workflow-Engines » Dalma » dalma » spi » 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 » Workflow Engines » Dalma » dalma.spi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package dalma.spi;
002:
003:        import java.io.UnsupportedEncodingException;
004:        import java.net.URI;
005:        import java.net.URLDecoder;
006:        import java.util.HashMap;
007:        import java.util.Map;
008:
009:        /**
010:         * Parses the query part of the URL.
011:         *
012:         * @author Kohsuke Kawaguchi
013:         */
014:        public class UrlQueryParser {
015:            private final Map<String, String> values = new HashMap<String, String>();
016:
017:            /**
018:             * Parses the query string.
019:             *
020:             * @param queryPart
021:             *      string like "a=b&amp;c=d". May contain escape like '%8D'.
022:             */
023:            public UrlQueryParser(String queryPart) {
024:                if (queryPart == null)
025:                    return; // nothing to parse, but that's not an error
026:                try {
027:                    for (String token : queryPart.split("&")) {
028:                        int idx = token.indexOf('=');
029:                        if (idx < 0) {
030:                            values.put(token, "");
031:                        } else {
032:                            values.put(token.substring(0, idx), URLDecoder
033:                                    .decode(token.substring(idx + 1), "UTF-8"));
034:                        }
035:                    }
036:                } catch (UnsupportedEncodingException e) {
037:                    throw new AssertionError(); // impossible
038:                }
039:            }
040:
041:            /**
042:             * Parses the query string.
043:             *
044:             * @param uri
045:             *      URI whose query part will be parsed
046:             */
047:            public UrlQueryParser(URI uri) {
048:                this (fixNull(uri.getQuery()));
049:            }
050:
051:            /**
052:             * Gets the value for the specified key.
053:             *
054:             * <p>
055:             * For example, if the query string was "a=b&amp;c=d",
056:             * you get "b" from {@code getValue("a")}.
057:             *
058:             * @return
059:             *      null if the value is not found for the key.
060:             */
061:            public String getValue(String key) {
062:                return getValue(key, null);
063:            }
064:
065:            /**
066:             * Gets the value for the specified key.
067:             *
068:             * <p>
069:             * For example, if the query string was "a=b&amp;c=d",
070:             * you get "b" from {@code getValue("a")}.
071:             *
072:             * @param defaultValue
073:             *      if no value was found for the given key,
074:             *      this value will be returned.
075:             */
076:            public String getValue(String key, String defaultValue) {
077:                String value = values.get(key);
078:                if (value == null)
079:                    value = defaultValue;
080:                return value;
081:            }
082:
083:            /**
084:             * Gets the value for the specified key as an integer.
085:             *
086:             * <p>
087:             * For example, if the query string was "a=b&amp;c=d",
088:             * you get "b" from {@code getValue("a")}.
089:             *
090:             * @param defaultValue
091:             *      if no value was found for the given key,
092:             *      this value will be returned.
093:             * @throws NumberFormatException
094:             *      if the value was found but not a number.
095:             */
096:            public int getValue(String key, int defaultValue)
097:                    throws NumberFormatException {
098:                String value = values.get(key);
099:                if (value == null)
100:                    return defaultValue;
101:                return Integer.parseInt(value);
102:            }
103:
104:            /**
105:             * Returns true if the query has a parameter of the given name.
106:             */
107:            public boolean has(String key) {
108:                return values.containsKey(key);
109:            }
110:
111:            /**
112:             * Adds all the key/value pairs into the given map.
113:             */
114:            public void addTo(Map<? super  String, ? super  String> map) {
115:                map.putAll(values);
116:            }
117:
118:            private static String fixNull(String s) {
119:                if (s == null)
120:                    return "";
121:                return s;
122:            }
123:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.