jeters.components
Class RegExReplacer

java.lang.Object
  extended by jeters.components.RegExReplacer
All Implemented Interfaces:
Component, Configurable, ReplacerComponent<EditableText,MediaWikiText>
Direct Known Subclasses:
ComillaReplacer, RegExReplacer_User

public abstract class RegExReplacer
extends java.lang.Object
implements ReplacerComponent<EditableText,MediaWikiText>, Configurable

an abstract replacer class for JETERS based on regular expressions; for using it, you only have to create an extended class setting the "replacements"-attribute. Have a look at the existing subclasses!
Note: This class uses the classes from java.util.regex.*; therefore, if you wonder about how regex strings have to be formatted, read through the Java API's explanation for java.util.regex.Pattern.


Nested Class Summary
protected static class RegExReplacer.DescriptionEntry
          an internally used class containing the necessary information for description lists.
protected static class RegExReplacer.DescriptionList
          an internally used class representing a description list.
static class RegExReplacer.Replacement
          a class that represents a single regex-pair together with other necessary information for performing replacements
static interface RegExReplacer.ReplacementElement
          one element in a list of replacements.
static class RegExReplacer.ReplacementGroup
          a group of replacements.
 
Field Summary
protected  java.lang.Integer conf_minRatingDescription
          minimum single rating for a relevant description.
protected  java.lang.Integer conf_minRatingSummary
          equivalent of conf_minRatingDescription for the final summary.
protected  java.lang.Integer conf_minTotalRatingDescription
          minimum total rating for a relevant description.
protected  java.lang.Integer conf_minTotalRatingSummary
          equivalent of conf_minTotalRatingDescription for the final summary.
protected  java.lang.Integer conf_summaryEntryLimit
          maximum number of descriptions in the summary.
protected  java.lang.Integer conf_summaryEntryLimitBrackets
          maximum number of descriptions in each bracket in the summary.
protected  RegExReplacer.DescriptionList confirmationDescriptionList
          description list for the next confirmation request.
protected  java.util.ArrayList<RegExReplacer.ReplacementElement> replacements
          the list of regex replacements that will be applied to the text.
protected  RegExReplacer.DescriptionList summaryDescriptionList
          description list for the summary.
 
Constructor Summary
RegExReplacer()
          parameterless constructor, creates an empty ArrayList of ReplacementElement for the "replacements"-attribute.
 
Method Summary
protected  java.lang.String applyReplacementGroup(RegExReplacer.ReplacementGroup replacementGroup, java.lang.String text, RegExReplacer.DescriptionList descriptionList)
          applies a group of replacements on a given string and returns the result.
protected  java.lang.String applyReplacementList(java.util.ArrayList<RegExReplacer.ReplacementElement> replacementList, java.lang.String text, RegExReplacer.DescriptionList descriptionList)
          applies a list of replacements on a given string and returns the result.
protected  java.lang.String applySingleReplacement(RegExReplacer.Replacement replacement, java.lang.String text, RegExReplacer.DescriptionList descriptionList)
          applies a single replacement on a given string and returns the result.
 MediaWikiText edit(EditableText text, UIComponent uiForRequests)
          applies the regular expressions to a text.
 NamedDataSet getConfiguration()
          this method is called to retrieve the current configuration for this component.
 void setConfiguration(NamedDataSet configurationSet)
          sets the configuration for this object.
protected static java.lang.String[] split(java.lang.String text)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

replacements

protected java.util.ArrayList<RegExReplacer.ReplacementElement> replacements
the list of regex replacements that will be applied to the text.


conf_minRatingDescription

protected java.lang.Integer conf_minRatingDescription
minimum single rating for a relevant description. A description string will only be shown to the user if it has at least once been assigned a rating equal to or higher than conf_minRatingDescription.


conf_minTotalRatingDescription

protected java.lang.Integer conf_minTotalRatingDescription
minimum total rating for a relevant description. A description string will only be shown to the user if the sum of all ratings it has been assigned is equal to or higher than conf_minTotalRatingDescription.


conf_minRatingSummary

protected java.lang.Integer conf_minRatingSummary
equivalent of conf_minRatingDescription for the final summary.


conf_minTotalRatingSummary

protected java.lang.Integer conf_minTotalRatingSummary
equivalent of conf_minTotalRatingDescription for the final summary.


conf_summaryEntryLimit

protected java.lang.Integer conf_summaryEntryLimit
maximum number of descriptions in the summary. If there are more descriptions than conf_summaryLimitNumberActions, those with the highest rating will be shown and three dots will be added to indicate that the list of replacement descriptions is not complete.


conf_summaryEntryLimitBrackets

protected java.lang.Integer conf_summaryEntryLimitBrackets
maximum number of descriptions in each bracket in the summary. The behavior is similar to conf_summaryEntryLimit.


confirmationDescriptionList

protected RegExReplacer.DescriptionList confirmationDescriptionList
description list for the next confirmation request.


summaryDescriptionList

protected RegExReplacer.DescriptionList summaryDescriptionList
description list for the summary.

Constructor Detail

RegExReplacer

public RegExReplacer()
parameterless constructor, creates an empty ArrayList of ReplacementElement for the "replacements"-attribute.

Method Detail

applySingleReplacement

protected java.lang.String applySingleReplacement(RegExReplacer.Replacement replacement,
                                                  java.lang.String text,
                                                  RegExReplacer.DescriptionList descriptionList)
applies a single replacement on a given string and returns the result. The description of the replacement will be added to a given description list.

Parameters:
replacement - the replacement that will be applied.
text - the string the replacements will be applied on.
descriptionList - the list for the description of the replacement.
Returns:
the string resulting from applying replacement on text.

applyReplacementGroup

protected java.lang.String applyReplacementGroup(RegExReplacer.ReplacementGroup replacementGroup,
                                                 java.lang.String text,
                                                 RegExReplacer.DescriptionList descriptionList)
applies a group of replacements on a given string and returns the result. The descriptions of the replacements will be added to a given description list.

Parameters:
replacementList - the list of replacements that will be applied.
text - the string the replacements will be applied on.
descriptionList - the list for the descriptions of the replacements.
Returns:
the string resulting from applying replacementGroup on text.

applyReplacementList

protected java.lang.String applyReplacementList(java.util.ArrayList<RegExReplacer.ReplacementElement> replacementList,
                                                java.lang.String text,
                                                RegExReplacer.DescriptionList descriptionList)
applies a list of replacements on a given string and returns the result. The descriptions of the replacements will be added to a given description list. Note that a ReplacementGroup can also be used for the parameter replacementList, since it extends ArrayList<ReplacementElement>. The attributes times and description are ignored then, of course.

Parameters:
replacementList - the list of replacements that will be applied.
text - the string the replacements will be applied on.
descriptionList - the list for the descriptions of the replacements.
Returns:
the string resulting from applying replacementList on text.

setConfiguration

public void setConfiguration(NamedDataSet configurationSet)
Description copied from interface: Configurable
sets the configuration for this object. If setConfiguration is not called, the component must work properly nevertheless, using default settings.

Specified by:
setConfiguration in interface Configurable
Parameters:
configurationSet - the configuration data to be used by the component if null, the object has to use default settings

getConfiguration

public NamedDataSet getConfiguration()
Description copied from interface: Configurable
this method is called to retrieve the current configuration for this component. It will e.g. be used for generating the configuration file.

Specified by:
getConfiguration in interface Configurable
Returns:
configuration data, null is allowed (doesn't make much sense however)

split

protected static java.lang.String[] split(java.lang.String text)

edit

public MediaWikiText edit(EditableText text,
                          UIComponent uiForRequests)
applies the regular expressions to a text.

Specified by:
edit in interface ReplacerComponent<EditableText,MediaWikiText>
Parameters:
uiForRequests - UI-component for communication with the user.
text - the input text that is supposed to be edited
Returns:
the text resulting from the edit, together with information for MediaWiki. Most importantly, it contains a description of the edit by listing the descriptions (the order is determined by the ratings).