<commit_before>link:../index.asciidoc[&larr; Docs Index] link:./index.asciidoc[ &larr; Configuration]

== Install Rewrite

Installation requirements:

* A Servlet 2.5 or 3.0+ compatible Servlet Container.
* Java 1.6+

== 1. Include Rewrite in your Project

The first step to installing link:../index.asciidoc[Rewrite] is to add the required Maven dependencies to your pom.xml file. If you are not using Maven, you may also http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.ocpsoft.rewrite%22%20AND%20a%3A%22rewrite-distribution%22[download the Rewrite distribution]
 from the Maven central repository - a list of all available versions is available http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.ocpsoft.rewrite%22%20AND%20a%3A%22rewrite-distribution%22[here]:

[source,xml]
.Add Rewrite to your maven pom.xml
----
<dependency>
   <groupId>org.ocpsoft.rewrite</groupId>
   <artifactId>rewrite-servlet</artifactId>
   <version>${rewrite.version}</version>
</dependency>

<!-- To use snapshots, you must also use the Sonatype Snapshots respository -->
<repository>
   <id>sonatype-snapshots</id>
   <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
   <releases>
      <enabled>false</enabled>
   </releases>
   <snapshots>
      <enabled>true</enabled>
   </snapshots>
</repository>
----

If you are not using maven, copy +rewrite-servlet.jar+ into the +/WEB-INF/lib+ folder of your web application. You do not need any other JARs unless you are using Rewrite link:../integration/index.asciidoc[extensions]. In the case of an EAR, ensure that you do not include Rewrite twice (once in the EAR/lib, and again in the WAR/lib), this will cause deployment errors; Rewrite dependencies should be marked as "provided" in the WAR POM.


Additionally, if you are using Servlet 2.5, or are deploying an EAR with link:http://maven.apache.org/plugins/maven-ear-plugin/examples/skinny-wars.html[skinny WARs], you will need to add the Rewrite Servlet configuration to the `WEB-INF/web.xml` file in each WAR. 

[source,xml]
.Configure Rewrite for Servlet 2.5 or EAR deployments by adding the following to `WEB-INF/web.xml`
----
<listener>
   <listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletRequestListener</listener-class>
</listener>

<listener>
   <listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletContextListener</listener-class>
</listener>

<filter>
   <filter-name>OCPsoft Rewrite Filter</filter-name>
   <filter-class>org.ocpsoft.rewrite.servlet.RewriteFilter</filter-class>
   <async-supported>true</async-supported>
</filter>
<filter-mapping>
   <filter-name>OCPsoft Rewrite Filter</filter-name>
   <url-pattern>/*</url-pattern>
   <dispatcher>FORWARD</dispatcher>
   <dispatcher>REQUEST</dispatcher>
   <dispatcher>INCLUDE</dispatcher>
   <dispatcher>ASYNC</dispatcher>
   <dispatcher>ERROR</dispatcher>
</filter-mapping>
----
You are now ready to configure your application.

=== 2. Create your first ConfigurationProvider

Once Rewrite is installed, you will need to describe how you would like it to 
handle events; this is done by implementing the +org.ocpsoft.rewrite.config.ConfigurationProvider+ interface.  Typically, when using Rewrite in a Servlet environment, you will want to extend from
the provided base class +org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider+.

[source,java]
.org.example.ApplicationConfigurationProvider
----
import org.ocpsoft.logging.Logger.Level;
import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.config.Log;
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;

@RewriteConfiguration
public class ApplicationConfigurationProvider extends HttpConfigurationProvider
{
   @Override
   public Configuration getConfiguration(ServletContext context)
   {
      return ConfigurationBuilder.begin()
         .addRule()
         .perform(Log.message(Log.message(Level.INFO, "Rewrite is active.")))
      ; 
   }

   @Override
   public int priority()
   {
      return 0;<commit_msg>Fixed bad code in install.asciidoc (#237)<commit_after>link:../index.asciidoc[&larr; Docs Index] link:./index.asciidoc[ &larr; Configuration]

== Install Rewrite

Installation requirements:

* A Servlet 2.5 or 3.0+ compatible Servlet Container.
* Java 1.6+

== 1. Include Rewrite in your Project

The first step to installing link:../index.asciidoc[Rewrite] is to add the required Maven dependencies to your pom.xml file. If you are not using Maven, you may also http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.ocpsoft.rewrite%22%20AND%20a%3A%22rewrite-distribution%22[download the Rewrite distribution]
 from the Maven central repository - a list of all available versions is available http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.ocpsoft.rewrite%22%20AND%20a%3A%22rewrite-distribution%22[here]:

[source,xml]
.Add Rewrite to your maven pom.xml
----
<dependency>
   <groupId>org.ocpsoft.rewrite</groupId>
   <artifactId>rewrite-servlet</artifactId>
   <version>${rewrite.version}</version>
</dependency>

<!-- To use snapshots, you must also use the Sonatype Snapshots respository -->
<repository>
   <id>sonatype-snapshots</id>
   <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
   <releases>
      <enabled>false</enabled>
   </releases>
   <snapshots>
      <enabled>true</enabled>
   </snapshots>
</repository>
----

If you are not using maven, copy +rewrite-servlet.jar+ into the +/WEB-INF/lib+ folder of your web application. You do not need any other JARs unless you are using Rewrite link:../integration/index.asciidoc[extensions]. In the case of an EAR, ensure that you do not include Rewrite twice (once in the EAR/lib, and again in the WAR/lib), this will cause deployment errors; Rewrite dependencies should be marked as "provided" in the WAR POM.


Additionally, if you are using Servlet 2.5, or are deploying an EAR with link:http://maven.apache.org/plugins/maven-ear-plugin/examples/skinny-wars.html[skinny WARs], you will need to add the Rewrite Servlet configuration to the `WEB-INF/web.xml` file in each WAR. 

[source,xml]
.Configure Rewrite for Servlet 2.5 or EAR deployments by adding the following to `WEB-INF/web.xml`
----
<listener>
   <listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletRequestListener</listener-class>
</listener>

<listener>
   <listener-class>org.ocpsoft.rewrite.servlet.impl.RewriteServletContextListener</listener-class>
</listener>

<filter>
   <filter-name>OCPsoft Rewrite Filter</filter-name>
   <filter-class>org.ocpsoft.rewrite.servlet.RewriteFilter</filter-class>
   <async-supported>true</async-supported>
</filter>
<filter-mapping>
   <filter-name>OCPsoft Rewrite Filter</filter-name>
   <url-pattern>/*</url-pattern>
   <dispatcher>FORWARD</dispatcher>
   <dispatcher>REQUEST</dispatcher>
   <dispatcher>INCLUDE</dispatcher>
   <dispatcher>ASYNC</dispatcher>
   <dispatcher>ERROR</dispatcher>
</filter-mapping>
----
You are now ready to configure your application.

=== 2. Create your first ConfigurationProvider

Once Rewrite is installed, you will need to describe how you would like it to 
handle events; this is done by implementing the +org.ocpsoft.rewrite.config.ConfigurationProvider+ interface.  Typically, when using Rewrite in a Servlet environment, you will want to extend from
the provided base class +org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider+.

[source,java]
.org.example.ApplicationConfigurationProvider
----
import org.ocpsoft.logging.Logger.Level;
import org.ocpsoft.rewrite.annotation.RewriteConfiguration;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.config.Log;
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;

@RewriteConfiguration
public class ApplicationConfigurationProvider extends HttpConfigurationProvider
{
   @Override
   public Configuration getConfiguration(ServletContext context)
   {
      return ConfigurationBuilder.begin()
         .addRule()
         .perform(Log.message(Level.INFO, "Rewrite is active."))
      ; 
   }

   @Override
   public int priority()
   {
      return 0;
{'fraction_non_alphanumeric': 0.1135787567893784, 'fraction_numerical': 0.012190706095353047, 'mean_word_length': 4.690934065934066, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 113, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4152655', 'n_tokens_mistral': 2681, 'n_tokens_neox': 2524, 'n_words': 676}