View Javadoc

1   /*
2   The MIT License
3   
4   Copyright (c) 2004, The Codehaus
5   
6   Permission is hereby granted, free of charge, to any person obtaining a copy of
7   this software and associated documentation files (the "Software"), to deal in
8   the Software without restriction, including without limitation the rights to
9   use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10  of the Software, and to permit persons to whom the Software is furnished to do
11  so, subject to the following conditions:
12  
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15  
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23   */
24  package org.codehaus.mojo.scmchangelog.changelog.log.grammar;
25  
26  import org.codehaus.mojo.scmchangelog.changelog.log.Message;
27  import org.codehaus.mojo.scmchangelog.changelog.log.ScmGrammar;
28  
29  
30  /**
31   * The currently supported grammars.
32   * @author ehsavoie
33   * @version $Id: GrammarEnum.java 10667 2009-09-11 08:26:43Z ehsavoie $
34   */
35  public class GrammarEnum
36  {
37    /**
38     * The MANU grammar @operatio:issue#;comment
39     */
40    public static final GrammarEnum MANU = new GrammarEnum( new ManuScmGrammar(),
41        "MANU" );
42    /**
43     * The REMY grammar.
44     */
45    public static final GrammarEnum REMY = new GrammarEnum( new RemyScmGrammar(),
46        "REMY" );
47    /**
48     * The BUGZILLA grammar.
49     */
50    public static final GrammarEnum BUGZILLA = new GrammarEnum(
51            new BugzillaScmGrammar(), "BUGZILLA" );
52    /**
53     * The ALL grammar.
54     */
55    public static final GrammarEnum ALL = new GrammarEnum(
56            new AcceptAllScmGrammar(), "ALL" );
57  
58    /**
59     * The grammar of the enum element.
60     */
61    private ScmGrammar grammar;
62    /**
63     * The name of the enum element.
64     */
65    private String name;
66  
67    /**
68     * Instatiate a new enum element.
69     * @param grammar the grammar of the element.
70     * @param name the name of the grammar element.
71     */
72    private GrammarEnum( ScmGrammar grammar, String name )
73    {
74      this.grammar = grammar;
75      this.name = name;
76    }
77  
78    /**
79     * Extract a Message from the specified String content.
80     * @param content the String to be parsed.
81     * @return the corresponding Message.
82     * @see org.codehaus.mojo.scmchangelog.changelog.log.Message
83     */
84    public Message extractMessage( final String content )
85    {
86      String realContent = this.grammar.removeComments( content );
87      return this.grammar.extractMessage( realContent );
88    }
89  
90    /**
91     * Indicates if the content String matches the grammar.
92     * @param content the String to be tested against the grammar.
93     * @return true if the content matches the grammar - false otherwise.
94     */
95    public boolean hasMessage( final String content )
96    {
97      return this.grammar.hasMessage( content );
98    }
99  
100   /**
101    * Returns the String to be inserted between each issue comment. It may be replaced
102    * when generating the report.
103    * @return the String to be inserted between each issue comment.
104    */
105   public String getIssueSeparator()
106   {
107     return this.grammar.getIssueSeparator();
108   }
109 
110   /**
111    * Return the enum element matching the specified name. MANU if no match is found.
112    * @param name the name of the required enum element.
113    * @return the enum element matching the specified name. MANU if no match is found.
114    */
115   public static GrammarEnum valueOf( String name )
116   {
117     if ( REMY.name.equalsIgnoreCase( name ) )
118     {
119       return REMY;
120     }
121     else if ( BUGZILLA.name.equalsIgnoreCase( name ) )
122     {
123       return BUGZILLA;
124     }
125     else if ( ALL.name.equalsIgnoreCase( name ) )
126     {
127       return ALL;
128     }
129     return MANU;
130   }
131 }