Source Code Cross Referenced for RestfulActionMapper.java in  » J2EE » webwork-2.2.6 » com » opensymphony » webwork » dispatcher » mapper » 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 » J2EE » webwork 2.2.6 » com.opensymphony.webwork.dispatcher.mapper 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.opensymphony.webwork.dispatcher.mapper;
002:
003:        import org.apache.commons.logging.Log;
004:        import org.apache.commons.logging.LogFactory;
005:
006:        import com.opensymphony.webwork.RequestUtils;
007:
008:        import javax.servlet.http.HttpServletRequest;
009:        import java.net.URLDecoder;
010:        import java.util.HashMap;
011:        import java.util.Iterator;
012:        import java.util.Map;
013:        import java.util.StringTokenizer;
014:
015:        /**
016:         * A custom action mapper using the following format:
017:         * <p/>
018:         * <p/>
019:         * <ul><tt>http://HOST/ACTION_NAME/PARAM_NAME1/PARAM_VALUE1/PARAM_NAME2/PARAM_VALUE2</tt></ul>
020:         * <p/>
021:         * You can have as many parameters you'd like to use. Alternatively the URL can be shortened to the following:
022:         * <p/>
023:         * <ul><tt>http://HOST/ACTION_NAME/PARAM_VALUE1/PARAM_NAME2/PARAM_VALUE2</tt></ul>
024:         * <p/>
025:         * This is the same as:
026:         * <p/>
027:         * <ul><tt>http://HOST/ACTION_NAME/ACTION_NAME + "Id"/PARAM_VALUE1/PARAM_NAME2/PARAM_VALUE2</tt></ul>
028:         * <p/>
029:         * Suppose for example we would like to display some articles by id at using the following URL sheme:
030:         * <p/>
031:         * <ul><tt>http://HOST/article/Id</tt></ul>
032:         * <p/>
033:         * <p/>
034:         * Your action just needs a setArticleId() method, and requests such as /article/1, /article/2, etc will all map
035:         * to that URL pattern.
036:         * <p/>
037:         * <b>Note: The RestfulActionMapper is not supported if you use the (deprecated) ServletDispatcher!</b>
038:         *
039:         * @author <a href="mailto:cameron@datacodex.net">Cameron Braid</a>
040:         * @author <a href="mailto:jerome.bernard@xtremejava.com">Jerome Bernard</a>
041:         * @author Patrick Lightbody
042:         */
043:        public class RestfulActionMapper implements  ActionMapper {
044:            protected static final Log LOG = LogFactory
045:                    .getLog(RestfulActionMapper.class);
046:
047:            public ActionMapping getMapping(HttpServletRequest request) {
048:                String uri = RequestUtils.getServletPath(request);
049:
050:                int nextSlash = uri.indexOf('/', 1);
051:                if (nextSlash == -1) {
052:                    return null;
053:                }
054:
055:                String actionName = uri.substring(1, nextSlash);
056:                HashMap parameters = new HashMap();
057:                try {
058:                    StringTokenizer st = new StringTokenizer(uri
059:                            .substring(nextSlash), "/");
060:                    boolean isNameTok = true;
061:                    String paramName = null;
062:                    String paramValue;
063:
064:                    // check if we have the first parameter name
065:                    if ((st.countTokens() % 2) != 0) {
066:                        isNameTok = false;
067:                        paramName = actionName + "Id";
068:                    }
069:
070:                    while (st.hasMoreTokens()) {
071:                        if (isNameTok) {
072:                            paramName = URLDecoder.decode(st.nextToken(),
073:                                    "UTF-8");
074:                            isNameTok = false;
075:                        } else {
076:                            paramValue = URLDecoder.decode(st.nextToken(),
077:                                    "UTF-8");
078:
079:                            if ((paramName != null) && (paramName.length() > 0)) {
080:                                parameters.put(paramName, paramValue);
081:                            }
082:
083:                            isNameTok = true;
084:                        }
085:                    }
086:                } catch (Exception e) {
087:                    LOG.warn(e);
088:                }
089:
090:                return new ActionMapping(actionName, "", "", parameters);
091:            }
092:
093:            public String getUriFromActionMapping(ActionMapping mapping) {
094:                String base = mapping.getNamespace() + mapping.getName();
095:                for (Iterator iterator = mapping.getParams().entrySet()
096:                        .iterator(); iterator.hasNext();) {
097:                    Map.Entry entry = (Map.Entry) iterator.next();
098:                    String name = (String) entry.getKey();
099:                    if (name.equals(mapping.getName() + "Id")) {
100:                        base = base + "/" + entry.getValue();
101:                        break;
102:                    }
103:                }
104:
105:                return base;
106:            }
107:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.