|
TechnicalSpecification
One-sentence summary of this page.
IntroductionThis document is a technical specification for how SmartURLs and possibly the new convention plugin for Struts2 functions and the requirements it has. DefinitionsHere are the definitions for terms used in this document. Plural forms of these are also used.
Requirements
URL MappingURLs should map directly to action-classes and view-results in a convention based manner. This can be provided on demand when an HTTP request comes into Struts or during application initialization such that the URLs that will be handled by the convention plugin are known prior to handling the first HTTP request. URL FormThe convention plugin assumes the use of the standard J2EE URL form of: http://www.example.com/context/namespace/resource/extra Here are the definitions for the URL parts excluding 'http://www.example.com' (the HTTP schema and host):
The BNF form for the URL is then: <url> ::= <schema> '://' <host> [<context>] [<namespace>] <resource> [<extra>] <schema> ::= 'http' | 'https' <host> ::= // standard host definition <context> ::= '/' identifier <namespace> ::= <namespace> | '/' identifier <namespace> <resource> ::= '/' identifier | '/' <extra> :: = <extra> | '/' identifier <extra> TODO the current extra definition might not be the best solution for REST. The namespace part of the URL directly maps to the action-namespace definition above. The resource part of the URL directly maps to the action-name definition above and in turn translates to the action-class via the action-transformation. TODO Define how the extra part of the URL is handled. Java PackagesAn application that uses the plugin will contain any number of java-packages and sub-java-packages that contain action-classes. All java-packages and sub-java-packages are located using action-package-identifiers. Package IdentifiersA configuration parameter named struts.action.package.identifiers will define a comma separated list of action-package-identifiers. These identifiers are partial package names according the Java language specification. For example, given this Java package: package com.example.actions; the Strings com, example, and actions are all partial package names. The action-package-identifiers will be the root Java package from which action-classes and sub-java-packages will be located. There default value for this configuration parameter will be: struts.action.package.identifiers=struts,struts2,action,actions MappingBy default, java-packages will map to the action-namespace and vice-versa. This mapping occurs via a namespace-transformation process. To illustrate this process, java-packages will be transformed into action-namespaces. This process would be indicative of implementations that pre-configure action-classes and view-results prior to the first request rather than locating action-classes or view-results based on the incoming URL. Namespace TransformationHere are the steps for namespace transformation.
Here are some examples of this process: 1. "com.example.actions" 2. "" 3. Skip this step 4. "" 5. "/" 1. "com.example.actions.foo" 2. "foo" 3. Skip this step 4. "foo" 5. "/foo" 1. "com.example.actions.fooBar" 2. "fooBar" 3.2. "foo-Bar" 3.3. "foo-bar" 4. "foo-bar" 5. "/foo-bar" 1. "com.example.actions.fooBAR" 2. "fooBar" 3.2. "foo-BAR" 3.4. "foo-bar" 4. "foo-bar" 5. "/foo-bar" Java ClassesAn application that uses the plugin will contain any number of action-classes, which will be defined in a java-package. Action-classes are determined in one of two ways:
MappingThese action-classes will directly map to action-names using the action-transformation. Here are the steps for transforming an action-class to action-name.
ExamplesHere are some examples of converting action-class names to action-names. "MyAction" 1. "My" 2. "my" "MySecondAction" 1. "MySecond" 2. "mySecond" 3. "my-Second" 4. "my-second" "MyURLAction" 1. "MyURL" 2. "myURL" 3. "my-URL" 4. "my-url" "DisplayAllUsers" 1. "DisplayAllUsers" 2. "displayAllUsers" 3. "display-AllUsers" 4. "display-allUsers" 2. "display-allUsers" 3. "display-all-Users" 4. "display-all-users" Complete ExamplesHere are a few examples of a fully qualified class name and how it is transformed into a complete URL path. Each step is not spelled out as above for brevity. Class: com.example.actions.admin.users.ListAllUsersAction URL: /admin/users/list-all-users Class: com.example.struts2.twoWords.SomeURL URL: /two-words/some-url ResultsThe plugin will handle view-results in two different manners.
In both cases, the plugin will map results to URLs based on the location of the view-result or the incoming URL. However, if an action-class is executed for the URL, the result code from the action-class execution will also be used in locating the appropriate view-result. Base Result LocationTODO MappingTODO Action InvocationOnce the fully qualified Java class names are converted to URL paths or vice versa, the plugin will now exactly which action-class is associated with a specific URL. The framework will execute that action-class when the URL is requested. Search hierarchy |
Sign in to add a comment
