Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 astamuse company,Ltd.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  */
 
 package com.astamuse.asta4d.sample;
 
 import static com.astamuse.asta4d.web.dispatch.HttpMethod.GET;
 import static com.astamuse.asta4d.web.dispatch.HttpMethod.PUT;
 
 
 public class UrlRules implements UrlMappingRuleInitializer {
 
     @Override
     public void initUrlMappingRules(UrlMappingRuleHelper rules) {
         //@formatter:off
         rules.add("/""/templates/index.html");
         rules.add("/index""/templates/index.html");
         
         rules.add("/redirect-to-index").redirect("p:/index");
         
         initSampleRules(rules);
         //@formatter:on
     }
 
     private void initSampleRules(UrlMappingRuleHelper rules) {
         //@formatter:off
         
         rules.add("/js/**/*").handler(new StaticResourceHandler());
         
         rules.add("/snippet""/templates/snippet.html");
         
         // @ShowCode:showVariableinjectionStart
         rules.add("/var-injection/{name}/{age}""/templates/variableinjection.html").priority(1);
         // @ShowCode:showVariableinjectionEnd
         
         rules.add("/attributevalues""/templates/attributevalues.html");
 
         rules.add("/extend/{target}").handler(new Object(){
             @RequestHandler
             public String handle(String target){
                 return "/templates/extend/"+target+".html";
             }
         });
         
 
         rules.add("/embed/main""/templates/embed/main.html");
 
         rules.add("/ajax/getUserList").handler(GetUserListHandler.class).json();
         
         rules.add("/ajax/addUser").handler(AddUserHandler.class).rest();
         
         rules.add("/""/templates/index.html");
 
         // @ShowCode:showSuccessStart
         rules.add("/handler")
              .handler(LoginHandler.class)
              .handler(EchoHandler.class)
              .forward(LoginFailure.class"/templates/error.html")
              .forward("/templates/success.html");
         // @ShowCode:showSuccessEnd
         
 
         rules.add("/renderertypes""/templates/renderertypes.html");
         rules.add("/passvariables""/templates/passvariables.html");
         rules.add("/dynamicsnippet""/templates/dynamicsnippet.html");
 
         rules.add("/contextdata""/templates/contextdata.html");
 
         
         rules.add("/form""/templates/form/list.html");
         
         // @ShowCode:showSingleInputStart
        rules.add((HttpMethod)null"/form/singleInput")
             //specify the target template file of input page by constructor
             .handler(new SingleInputFormHandler("/templates/form/singleInput/edit.html"))
             //specify the exit target
             .redirect("/form?type=single-input");
        // @ShowCode:showSingleInputEnd
             
        // @ShowCode:showMultiStepStart
        rules.add((HttpMethod)null"/form/multistep")
             //specify the base path of target template file by constructor
             .handler(new MultiStepFormHandler("/templates/form/multistep/"))
             //specify the exit target
             .redirect("/form?type=multi-step");
        // @ShowCode:showMultiStepEnd
        
        // @ShowCode:showCascadeStart
        rules.add((HttpMethod)null"/form/cascade/add")
             //specify the base path of target template file by path var
             .var(."/templates/form/cascade/")
             .handler(CascadeFormHandler.Add.class)
             //specify the exit target
             .redirect("/form?type=cascade");
        rules.add((HttpMethod)null"/form/cascade/edit")
             //specify the base path of target template file by path var
             .var(."/templates/form/cascade/")
             .handler(CascadeFormHandler.Edit.class)
             //specify the exit target
             .redirect("/form?type=cascade");
        // @ShowCode:showCascadeEnd
           
        rules.add("/localize""/templates/localize.html");
        
        
        
        
        //@formatter:on
    }
New to GrepCode? Check out our FAQ X