1 /*
2 * dpkg - Debian Package library and the Debian Package Maven plugin
3 * (c) Copyright 2016 Gerrit Hohl
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 package net.sourceforge.javadpkg.impl;
20
21 import java.util.Map;
22 import java.util.TreeMap;
23
24 import net.sourceforge.javadpkg.ChangeLogUrgency;
25 import net.sourceforge.javadpkg.ChangeLogUrgencyParser;
26 import net.sourceforge.javadpkg.Context;
27 import net.sourceforge.javadpkg.ParseException;
28
29
30 /**
31 * <p>
32 * A {@link ChangeLogUrgencyParser} implementation.
33 * </p>
34 *
35 * @author Gerrit Hohl (gerrit-hohl@users.sourceforge.net)
36 * @version <b>1.0</b>, 04.05.2016 by Gerrit Hohl
37 */
38 public class ChangeLogUrgencyParserImpl implements ChangeLogUrgencyParser {
39
40
41 /** The urgency. */
42 private Map<String, ChangeLogUrgency> urgency;
43
44
45 /**
46 * <p>
47 * Creates a parser.
48 * </p>
49 */
50 public ChangeLogUrgencyParserImpl() {
51 super();
52
53 this.urgency = new TreeMap<>();
54 this.addUrgency("low");
55 this.addUrgency("medium");
56 this.addUrgency("high");
57 this.addUrgency("emergency");
58 this.addUrgency("critical");
59 }
60
61
62 /**
63 * <p>
64 * Adds an urgency.
65 * </p>
66 *
67 * @param text
68 * The text.
69 */
70 private void addUrgency(String text) {
71 this.urgency.put(text.toLowerCase(), new ChangeLogUrgencyImpl(text));
72 }
73
74
75 @Override
76 public ChangeLogUrgency parseChangeLogUrgency(String value, Context context) throws ParseException {
77 ChangeLogUrgency urgency;
78
79
80 if (value == null)
81 throw new IllegalArgumentException("Argument value is null.");
82 if (context == null)
83 throw new IllegalArgumentException("Argument context is null.");
84
85 urgency = this.urgency.get(value.toLowerCase());
86 if (urgency == null) {
87 urgency = new ChangeLogUrgencyImpl(value);
88 context.addWarning(new ChangeLogUrgencyUnsupportedWarning(value));
89 }
90
91 return urgency;
92 }
93
94
95 /* **********************************************************************
96 * **********************************************************************
97 * **********************************************************************
98 * **********************************************************************
99 * **********************************************************************
100 */
101
102
103 /**
104 * <p>
105 * The {@link ChangeLogUrgency} implementation of this clas.
106 * </p>
107 *
108 * @author Gerrit Hohl (gerrit-hohl@users.sourceforge.net)
109 * @version <b>1.0</b>, 06.05.2016 by Gerrit Hohl
110 */
111 private class ChangeLogUrgencyImpl implements ChangeLogUrgency {
112
113
114 /** The text. */
115 private String text;
116
117
118 /**
119 * <p>
120 * Creates an urgency.
121 * </p>
122 *
123 * @param text
124 * The text.
125 */
126 public ChangeLogUrgencyImpl(String text) {
127 super();
128
129 this.text = text;
130 }
131
132
133 @Override
134 public String getText() {
135 return this.text;
136 }
137
138
139 }
140
141
142 }