add Rule realy dynamic

Splash Forums Rewrite Users add Rule realy dynamic

This topic contains 6 replies, has 4 voices, and was last updated by  salviof 2 years, 9 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #25194

    salviof
    Participant

    Hi, I whant make my rules extremaly dynamic like a for with pageInfos who add all rules, but the only way to create the Configuration is with ConfigurationBuilder, the configuration not have a add rule method by sample…

    How can I do that?

    Thanks

    #25196

    I think I don’t understand your question completely. Building rules dynamically should be easy:

    
    @Override
    public Configuration getConfiguration( ServletContext context ) {
    
      ConfigurationBuilder builder = ConfigurationBuilder.begin();
    
      if( somethingIsTrue ) {
        builder.addRule( .... )
      }
      
      return builder;
    }
    

    Or do you want to do something else?

    #25223

    salviof
    Participant

    Ok, Thanks! (I try return the Configuration class not ConfigurationBuilder)

    • This reply was modified 2 years, 9 months ago by  salviof.
    • This reply was modified 2 years, 9 months ago by  salviof.
    #25226

    It sounds like you are trying to add one rule for each item in a database, resulting in a potentially massive rule-set, perhaps you could write a single rule that would work for all database items? something like this:

    @Override
    public Configuration getConfiguration( ServletContext context ) {
    
      ConfigurationBuilder builder = ConfigurationBuilder.begin();
    
         .addRule(Join.path("/item/{id}").to("/viewItem.jsp"))
         .where(new HttpCondition() {
             public boolean evaluateHttp(HttpServletRewrite event, EvaluationContext context)
             {
                String id = context.get(ParameterValueStore.class)
                                   .get(context.get(ParameterStore.class)
                                   .get("id"));
    
                // Perform database lookup of ID.
             }
         })
      
      return builder;
    }

    Does this help?

    #25230

    captainmorgan
    Participant

    Lincoln, I’m trying to do something similar. I have a page table in the database and there are up to 10 different XHTML pages that these could map to.
    Would something like the following work? From my understanding, every URL would be evaluated, if the current URL is found in the database, it is mapped to page1.hxml.
    I will have thousands of pages and don’t really want to create a massive configuration.

    @Override
    public Configuration getConfiguration( ServletContext context ) {

    ConfigurationBuilder builder = ConfigurationBuilder.begin();

    .addRule(Join.path(“{page}”).to(“/page1.xhtml”))
    .where(new HttpCondition() {
    public boolean evaluateHttp(HttpServletRewrite event, EvaluationContext context)
    {
    String page = How to I get the page URL here?

    // Perform database lookup of page URL.
    }
    })

    return builder;
    }
    `

    • This reply was modified 2 years, 9 months ago by  captainmorgan.
    #25241

    Try event.getAddress()

    #25246

    salviof
    Participant

    Yes! thats beautiful, thanks!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Comments are closed.