Ignore:
Timestamp:
2003-05-27T15:57:37+12:00 (21 years ago)
Author:
kjdon
Message:

re-tabbed the code for java

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/Subcollection.java

    r4293 r4366  
    5353import org.w3c.dom.Element;
    5454/** This class encapsulates one subcollection entry in the collection configuration file.
    55 * @author John Thompson, Greenstone Digital Library, University of Waikato
    56 * @version 2.3
    57 */
     55 * @author John Thompson, Greenstone Digital Library, University of Waikato
     56 * @version 2.3
     57 */
    5858public class Subcollection
    59     implements Comparable {
    60     /** A <i>boolean</i> which is <i>true</i> if the condition is an include one, <i>false</i> otherwise. */
    61     private boolean include = true;
    62     /** Either the fully qualified name of the metadata whose value should be matched against the given expression, or <i>null</i> if you wish to match against the file name. */
    63     private String element = null;
    64     /** A String containing a Perl expression which is used as the filter for this subcollection. */
    65     private String exp = null;
    66     /** A series of flags to be used when matching the expression. */
    67     private String flags = null;
    68     /** A String which is a unique identifier of a subcollection. */
    69     private String name = null;
    70     /** Constructor.
    71       * @param name A <strong>String</strong> which is a unique identifier of a subcollection.
    72       * @param pattern A <strong>String</strong> containing the inclusion, the element to filter, a Perl expression which is used as the filter for this subcollection, and a series of argument flags.
    73       */
    74     public Subcollection(String name, String pattern) {
    75           this.name = name;
    76           // Have to do some work on pattern.
    77           // Remove quote marks.
    78           if(pattern.startsWith("\"") || pattern.startsWith("'")) {
    79                 pattern = pattern.substring(1, pattern.length() - 1);
    80           }
    81           // Test for exclusion
    82           if(pattern.startsWith("!")) {
    83                 this.include = false;
    84                 pattern = pattern.substring(1, pattern.length());
    85           }
    86           else {
    87                 this.include = true;
    88           }
    89           if(pattern.indexOf("/") != -1) {
     59    implements Comparable {
     60    /** A <i>boolean</i> which is <i>true</i> if the condition is an include one, <i>false</i> otherwise. */
     61    private boolean include = true;
     62    /** Either the fully qualified name of the metadata whose value should be matched against the given expression, or <i>null</i> if you wish to match against the file name. */
     63    private String element = null;
     64    /** A String containing a Perl expression which is used as the filter for this subcollection. */
     65    private String exp = null;
     66    /** A series of flags to be used when matching the expression. */
     67    private String flags = null;
     68    /** A String which is a unique identifier of a subcollection. */
     69    private String name = null;
     70    /** Constructor.
     71     * @param name A <strong>String</strong> which is a unique identifier of a subcollection.
     72     * @param pattern A <strong>String</strong> containing the inclusion, the element to filter, a Perl expression which is used as the filter for this subcollection, and a series of argument flags.
     73     */
     74    public Subcollection(String name, String pattern) {
     75    this.name = name;
     76    // Have to do some work on pattern.
     77    // Remove quote marks.
     78    if(pattern.startsWith("\"") || pattern.startsWith("'")) {
     79        pattern = pattern.substring(1, pattern.length() - 1);
     80    }
     81    // Test for exclusion
     82    if(pattern.startsWith("!")) {
     83        this.include = false;
     84        pattern = pattern.substring(1, pattern.length());
     85    }
     86    else {
     87        this.include = true;
     88    }
     89    if(pattern.indexOf("/") != -1) {
    9090                // Now element (which may be Filename)
    91                 this.element = pattern.substring(0, pattern.indexOf("/"));
    92                 if(this.element.toLowerCase().equals("filename")) {
    93                      this.element = null;
    94                 }
     91        this.element = pattern.substring(0, pattern.indexOf("/"));
     92        if(this.element.toLowerCase().equals("filename")) {
     93        this.element = null;
     94        }
    9595                // Extract Perl expression
    96                 if(pattern.indexOf("/") != pattern.lastIndexOf("/")) {
    97                      this.exp = pattern.substring(pattern.indexOf("/") + 1,
    98                                                             pattern.lastIndexOf("/"));
    99                      this.flags = pattern.substring(pattern.lastIndexOf("/") + 1);
    100                 }
    101                 else {
    102                      this.exp = pattern.substring(pattern.indexOf("/") + 1);
    103                 }
    104           }
    105           else {
     96        if(pattern.indexOf("/") != pattern.lastIndexOf("/")) {
     97        this.exp = pattern.substring(pattern.indexOf("/") + 1,
     98                         pattern.lastIndexOf("/"));
     99        this.flags = pattern.substring(pattern.lastIndexOf("/") + 1);
     100        }
     101        else {
     102        this.exp = pattern.substring(pattern.indexOf("/") + 1);
     103        }
     104    }
     105    else {
    106106                // Hmmm. Well I don't know what this is but it isn't a proper subcollection definition. Can't really 'return null' or something. So I'll just not set include, element, exp and flag expressions.
    107           }
    108     }
    109     /** Constructor.
     107    }
     108    }
     109    /** Constructor.
    110110      * @param name A <strong>String</strong> which is a unique identifier of a subcollection.
    111111      * @param include A <i>boolean</i> which is <i>true</i> if the condition is an include one, <i>false</i> otherwise.
    112112      * @param exp A <strong>String</strong> containing a Perl expression which is used as the filter for this subcollection.
    113113      */
    114     public Subcollection(String name, boolean include, String exp, String flags) {
    115           this.element = null;
    116           this.exp = exp;
    117           this.flags = flags;
    118           this.include = include;
    119           this.name = name;
    120     }
    121     /** Constructor.
     114    public Subcollection(String name, boolean include, String exp, String flags) {
     115    this.element = null;
     116    this.exp = exp;
     117    this.flags = flags;
     118    this.include = include;
     119    this.name = name;
     120    }
     121    /** Constructor.
    122122      * @param name A <strong>String</strong> which is a unique identifier of a subcollection.
    123123      * @param include A <i>boolean</i> which is <i>true</i> if the condition is an include one, <i>false</i> otherwise.
     
    126126      * @param flags A <strong>String</strong> of flags to be taken into account when matching the expression.
    127127      */
    128     public Subcollection(String name, boolean include, String element, String exp, String flags) {
    129           this.element = element;
    130           this.exp = exp;
    131           this.flags = flags;
    132           this.include = include;
    133           this.name = name;
    134     }
    135     /** Method to compare two subcollections.
     128    public Subcollection(String name, boolean include, String element, String exp, String flags) {
     129    this.element = element;
     130    this.exp = exp;
     131    this.flags = flags;
     132    this.include = include;
     133    this.name = name;
     134    }
     135    /** Method to compare two subcollections.
    136136      * @param object The other subcollection to compare to, as an <strong>Object</strong>.
    137137      * @return An <i>int</i> which is greater than, equal to or less than zero if the this object is before, equal to, or after the target object respectively.
    138138      */
    139     public int compareTo(Object object) {
    140           Subcollection sub = (Subcollection) object;
    141           return getName().compareTo(sub.getName());
    142     }
    143     /** Method to check two subcollections for equality.
     139    public int compareTo(Object object) {
     140    Subcollection sub = (Subcollection) object;
     141    return getName().compareTo(sub.getName());
     142    }
     143    /** Method to check two subcollections for equality.
    144144      * @param object The other subcollection to compare to, as an <strong>Object</strong>.
    145145      * @return A <i>boolean</i> which is <i>true</i> if the subcollections are equal, <i>false</i> otherwise.
    146146      */
    147     public boolean equals(Object object) {
    148           if(compareTo(object) == 0) {
    149                 return true;
    150           }
    151           return false;
    152     }
    153     /** Method to get the value of element.
     147    public boolean equals(Object object) {
     148    if(compareTo(object) == 0) {
     149        return true;
     150    }
     151    return false;
     152    }
     153    /** Method to get the value of element.
    154154      * @return The value of element as an <strong>String</strong>.
    155155      */
    156     public String getElement() {
    157           return element;
    158     }
    159     /** Method to get the value of expression.
     156    public String getElement() {
     157    return element;
     158    }
     159    /** Method to get the value of expression.
    160160      * @return The value of exp as a <strong>String</strong>.
    161161      */
    162     public String getExpression() {
    163           return exp;
    164     }
    165     /** Method to get the value of flags.
     162    public String getExpression() {
     163    return exp;
     164    }
     165    /** Method to get the value of flags.
    166166      * @return The value of flags as a <strong>String</strong>.
    167167      */
    168     public String getFlags() {
    169           return flags;
    170     }
    171     /** Method to get the value of include.
     168    public String getFlags() {
     169    return flags;
     170    }
     171    /** Method to get the value of include.
    172172      * @param boolean The value of include as a <i>boolean</i>.
    173173      */
    174     public boolean getInclude() {
    175           return include;
    176     }
    177     /** Method to get the value of name.
     174    public boolean getInclude() {
     175    return include;
     176    }
     177    /** Method to get the value of name.
    178178      * @param String The value of name as a <strong>String</string>.
    179179      */
    180     public String getName() {
    181           return name;
    182     }
    183     /** Method to get the name of the source of the strings used in pattern matching.
     180    public String getName() {
     181    return name;
     182    }
     183    /** Method to get the name of the source of the strings used in pattern matching.
    184184      * @return A <strong>String</strong> which is either the fully qualified name of a metadata element, or "Filename".
    185185      */
    186     public String getSource() {
    187           if(element != null) {
    188                 return element;
    189           }
    190           return "Filename";
    191     }
    192     /** Method to display the contents of this class as it would appear in the collection configuration file.
     186    public String getSource() {
     187    if(element != null) {
     188        return element;
     189    }
     190    return "Filename";
     191    }
     192    /** Method to display the contents of this class as it would appear in the collection configuration file.
    193193      * @return A <strong>String</strong> which could be used as a subcollection entry in collect.cfg.
    194194      */
    195     public String toString() {
    196           String text = "subcollection        ";
    197           text = text + name + " ";
    198           text = text + "\"";
    199           if(!include) {
    200                 text = text + "!";
    201           }
    202           if(element != null) {
    203                 text = text + element;
    204           }
    205           else {
    206                 text = text + "Filename";
    207           }
    208           text = text + "/";
    209           text = text + exp;
    210           text = text + "/";
    211           if(flags != null) {
    212                 text = text + flags;
    213           }
    214           text = text + "\"\n";
    215           return text;
    216     }
    217 
    218     /** Update certain fields of this subcollection.
     195    public String toString() {
     196    String text = "subcollection        ";
     197    text = text + name + " ";
     198    text = text + "\"";
     199    if(!include) {
     200        text = text + "!";
     201    }
     202    if(element != null) {
     203        text = text + element;
     204    }
     205    else {
     206        text = text + "Filename";
     207    }
     208    text = text + "/";
     209    text = text + exp;
     210    text = text + "/";
     211    if(flags != null) {
     212        text = text + flags;
     213    }
     214    text = text + "\"\n";
     215    return text;
     216    }
     217
     218    /** Update certain fields of this subcollection.
    219219      * @param name A <strong>String</strong> which is a unique identifier of a subcollection.
    220220      * @param source Either the fully qualified name of the metadata whose value should be matched against the given expression, or <i>null</i> if you wish to match against the file name.
     
    223223      * @param flags A <strong>String</strong> of flags to be taken into account when matching the expression.
    224224        */
    225     public void update(String name, String source, String exp, boolean include, String flags) {
    226           this.name = name;
    227           this.element = source;
    228           this.exp = exp;
    229           this.include = include;
    230           this.flags = flags;
    231     }
    232 
    233     /** Method to update the name of a metadata element, if it changes.
     225    public void update(String name, String source, String exp, boolean include, String flags) {
     226    this.name = name;
     227    this.element = source;
     228    this.exp = exp;
     229    this.include = include;
     230    this.flags = flags;
     231    }
     232
     233    /** Method to update the name of a metadata element, if it changes.
    234234      * @param old_name The current name of the element as a <strong>String</strong>.
    235235      * @param new_name The new name of the element as a <strong>String</strong>.
    236236      */
    237     public void updateElement(String old_name, String new_name) {
    238           if(element.equals(old_name)) {
    239                 element = new_name;
    240           }
    241     }
     237    public void updateElement(String old_name, String new_name) {
     238    if(element.equals(old_name)) {
     239        element = new_name;
     240    }
     241    }
    242242}
    243243
Note: See TracChangeset for help on using the changeset viewer.