net.sf.jeters.components
Class RegExReplacer

java.lang.Object
  extended by net.sf.jeters.util.AssistedComponent
      extended by net.sf.jeters.components.RegExReplacer
All Implemented Interfaces:
Component, ReplacerComponent<net.sf.jeters.componentInterface.editables.EditableText,net.sf.jeters.componentInterface.editables.MediaWikiText>, Configurable, Translatable
Direct Known Subclasses:
RegExReplacer_User

public abstract class RegExReplacer
extends AssistedComponent
implements ReplacerComponent<net.sf.jeters.componentInterface.editables.EditableText,net.sf.jeters.componentInterface.editables.MediaWikiText>

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.

Author:
Tobias Knerr

Nested Class Summary
static class RegExReplacer.CustomReplacement
          a class that represents a single replacement which is not based on regex, but on a custom method
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.RegExReplacement
          a class that represents a single regex-pair together with other necessary information for performing replacements
static class RegExReplacer.Replacement
          a single replacement
static interface RegExReplacer.ReplacementElement
          one element in a list of replacements.
static class RegExReplacer.ReplacementGroup
          a group of replacements.
protected  class RegExReplacer.Splitter
          splitter-class, extending this can modify the splitting behavior.
 
Field Summary
protected  java.lang.Boolean conf_debug
          if true, debug information will be generated.
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.Splitter splitter
          the splitter class that will be used; not null.
protected  RegExReplacer.DescriptionList summaryDescriptionList
          description list for the summary.
 
Constructor Summary
RegExReplacer()
          parameterless constructor, creates an empty ArrayList of ReplacementElement for the "replacements"-attribute and a default Splitter.
 
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.
 net.sf.jeters.componentInterface.editables.MediaWikiText[] edit(net.sf.jeters.componentInterface.editables.EditableText text, UIComponent uiForRequests)
          applies the regular expressions to a text.
 
Methods inherited from class net.sf.jeters.util.AssistedComponent
getConfiguration, setConfiguration, setLanguageResourceBundle, str, str
 
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_debug

protected java.lang.Boolean conf_debug
if true, debug information will be generated.


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.


splitter

protected RegExReplacer.Splitter splitter
the splitter class that will be used; not null. In the constructor, this is set to a default Splitter which does not split the text at all.

Constructor Detail

RegExReplacer

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

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:
replacementGroup - the group 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.

edit

public net.sf.jeters.componentInterface.editables.MediaWikiText[] edit(net.sf.jeters.componentInterface.editables.EditableText text,
                                                                       UIComponent uiForRequests)
applies the regular expressions to a text.

Specified by:
edit in interface ReplacerComponent<net.sf.jeters.componentInterface.editables.EditableText,net.sf.jeters.componentInterface.editables.MediaWikiText>
Parameters:
uiForRequests - UI-component for communication with the user.
text - the input text that is supposed to be edited
Returns:
array of size 1 with 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).