@@ -56,7 +56,7 @@ public HSLColorImpl(final String function, final LexicalUnit lu) throws DOMExcep
5656 if (next == null ) {
5757 throw new DOMException (DOMException .SYNTAX_ERR , function_ + " requires at least three values." );
5858 }
59- hue_ = new CSSValueImpl (next , true );
59+ hue_ = getHuePart (next );
6060
6161 next = next .getNextLexicalUnit ();
6262 if (next == null ) {
@@ -79,10 +79,8 @@ public HSLColorImpl(final String function, final LexicalUnit lu) throws DOMExcep
7979 throw new DOMException (DOMException .SYNTAX_ERR ,
8080 function_ + " has to use blank as separator if none is used." );
8181 }
82- else {
83- if (LexicalUnitType .PERCENTAGE != next .getLexicalUnitType ()) {
84- throw new DOMException (DOMException .SYNTAX_ERR , "Saturation part has to be percentage." );
85- }
82+ if (LexicalUnitType .PERCENTAGE != next .getLexicalUnitType ()) {
83+ throw new DOMException (DOMException .SYNTAX_ERR , "Saturation part has to be percentage." );
8684 }
8785 saturation_ = new CSSValueImpl (next , true );
8886
@@ -127,12 +125,7 @@ public HSLColorImpl(final String function, final LexicalUnit lu) throws DOMExcep
127125 throw new DOMException (DOMException .SYNTAX_ERR ,
128126 function_ + " has to use blank as separator if none is used." );
129127 }
130- if (LexicalUnitType .INTEGER != next .getLexicalUnitType ()
131- && LexicalUnitType .REAL != next .getLexicalUnitType ()
132- && LexicalUnitType .PERCENTAGE != next .getLexicalUnitType ()) {
133- throw new DOMException (DOMException .SYNTAX_ERR , "Alpha part has to be numeric or percentage." );
134- }
135- alpha_ = new CSSValueImpl (next , true );
128+ alpha_ = getAlphaPart (next );
136129 next = next .getNextLexicalUnit ();
137130 if (next != null ) {
138131 throw new DOMException (DOMException .SYNTAX_ERR , "Too many parameters for " + function_ + " function." );
@@ -173,19 +166,43 @@ public HSLColorImpl(final String function, final LexicalUnit lu) throws DOMExcep
173166 throw new DOMException (DOMException .SYNTAX_ERR , "Missing alpha value." );
174167 }
175168
176- if (LexicalUnitType .INTEGER != next .getLexicalUnitType ()
177- && LexicalUnitType .REAL != next .getLexicalUnitType ()
178- && LexicalUnitType .PERCENTAGE != next .getLexicalUnitType ()) {
179- throw new DOMException (DOMException .SYNTAX_ERR , "Alpha part has to be numeric or percentage." );
180- }
181- alpha_ = new CSSValueImpl (next , true );
169+ alpha_ = getAlphaPart (next );
182170
183171 next = next .getNextLexicalUnit ();
184172 if (next != null ) {
185173 throw new DOMException (DOMException .SYNTAX_ERR , "Too many parameters for " + function_ + " function." );
186174 }
187175 }
188176
177+ private static CSSValueImpl getHuePart (final LexicalUnit next ) {
178+ if (LexicalUnitType .DEGREE == next .getLexicalUnitType ()
179+ || LexicalUnitType .RADIAN == next .getLexicalUnitType ()
180+ || LexicalUnitType .GRADIAN == next .getLexicalUnitType ()
181+ || LexicalUnitType .TURN == next .getLexicalUnitType ()
182+
183+ || LexicalUnitType .INTEGER == next .getLexicalUnitType ()
184+ || LexicalUnitType .REAL == next .getLexicalUnitType ()
185+
186+ || LexicalUnitType .NONE == next .getLexicalUnitType ()) {
187+ return new CSSValueImpl (next , true );
188+ }
189+
190+ throw new DOMException (DOMException .SYNTAX_ERR , "Color hue part has to be numeric or an angle." );
191+ }
192+
193+ private static CSSValueImpl getAlphaPart (final LexicalUnit next ) {
194+ if (LexicalUnitType .PERCENTAGE == next .getLexicalUnitType ()
195+
196+ || LexicalUnitType .INTEGER == next .getLexicalUnitType ()
197+ || LexicalUnitType .REAL == next .getLexicalUnitType ()
198+
199+ || LexicalUnitType .NONE == next .getLexicalUnitType ()) {
200+ return new CSSValueImpl (next , true );
201+ }
202+
203+ throw new DOMException (DOMException .SYNTAX_ERR , "Color alpha part has to be numeric or percentage." );
204+ }
205+
189206 /**
190207 * @return the hue part.
191208 */
0 commit comments