Reply To: Create One Rule For All Supported Extensions

Splash Forums Rewrite Users Create One Rule For All Supported Extensions Reply To: Create One Rule For All Supported Extensions

#27461

RB
Participant

Thanks again. It works.

import java.util.Arrays;

import javax.servlet.ServletContext;

import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
import org.ocpsoft.rewrite.servlet.config.rule.Join;

@RewriteConfiguration
public class ApplicationConfigurationProvider extends HttpConfigurationProvider
{
   @Override
   public Configuration getConfiguration(ServletContext context) {
	   ConfigurationBuilder builder = ConfigurationBuilder.begin();
	   
	   for(String extension : Arrays.asList("xhtml", "jsf", "jsp")) {
		   builder.addRule(Join.path("/recommended/id/{id}").to("/Recommended."+extension)
				   .withInboundCorrection()).where("id").matches("[0-9]+").withPriority(20);
	   }
	   
	   for(String extension : Arrays.asList("xhtml", "jsf", "jsp")) {
		   builder.addRule(Join.path("/recommended/{recd}").to("/Recommended."+extension)
				   .withInboundCorrection()).where("recd").matches("[\\p{L}\\p{Punct}0-9\\s]+").withPriority(30);
	   }
	   
	   return builder;
   }

   @Override
   public int priority()
   {
      return 10;
   }
   
}