Class GenderAwareMarkupRenderer


  • public class GenderAwareMarkupRenderer
    extends MarkupRenderer
    This class overrides the handleUnknownTag method of MarkupRenderer to allow arbitrary tags that vary with the gender of some object.

    More generally, it allows tags of the form <left/right> which will generate either the left text or the right text depending on the "gender" the renderer has been set to.

    To prevent confusion with closing tags, if no text should be produced for a given gender, the tag should indicate this with a hyphen, e.g., <-/something> would produce either "" or "something".

    Some examples of how the tags can be used:

    • <Jack/Diane> was a great scholar of old.
    • The priest<-/ess> is angry.
    • You bite <his/her/its/their> hand<-/-/-/s>.
    • The <orange/yellow/red/green> key fits this lock.
    Author:
    Chris Jennings
    • Constructor Detail

      • GenderAwareMarkupRenderer

        public GenderAwareMarkupRenderer()
      • GenderAwareMarkupRenderer

        public GenderAwareMarkupRenderer​(double dpi)
    • Method Detail

      • setGender

        public void setGender​(boolean female)
        Sets the "gender" using a simple male/female rule. If female is true, the second segment of a gender tag is used. If false, the first segment is used.
        Parameters:
        female - if the second segment should be used
      • setGender

        public void setGender​(int segmentToUse)
        Set the segment of gender tags to be used. A gender tag may have any number of segments/separated/by/slashes. This index indicates which segment to use. A common mapping is 0 = male, 1 = female, 2 = plural ("they"), and 3 = neuter ("it").
      • getGender

        public int getGender()
        Return the current gender setting as a boolean; true indicates that the right side of gender-sensitive tags will be selected.
      • handleUnknownTag

        protected java.lang.String handleUnknownTag​(java.lang.String tagnameLowercase,
                                                    java.lang.String tagnameOriginalCase)
        Checks for tags of the form <m/f> or <capital m/f>and returns replacement text based on the current gender setting.
        Overrides:
        handleUnknownTag in class MarkupRenderer
      • capitalize

        public static java.lang.String capitalize​(java.lang.String s)
        Returns a string identical to s except that the first character, if any and if it has a capital version, is capitalized.