Abstract AbstractCSSRuleImpl class.
+ * * @author Ronald Brill + * */ public abstract class AbstractCSSRuleImpl extends AbstractLocatable implements Serializable { @@ -28,6 +31,7 @@ public abstract class AbstractCSSRuleImpl extends AbstractLocatable implements S /** * Ctor. + * * @param parentStyleSheet the parent style sheet * @param parentRule the parent rule */ @@ -38,6 +42,8 @@ public AbstractCSSRuleImpl(final CSSStyleSheetImpl parentStyleSheet, final Abstr } /** + *getCssText.
+ * * @return the current css text */ public abstract String getCssText(); @@ -65,6 +71,8 @@ public void setParentRule(final AbstractCSSRuleImpl parentRule) { } /** + *getParentStyleSheet.
+ * * @return the parent style sheet */ public CSSStyleSheetImpl getParentStyleSheet() { @@ -72,12 +80,15 @@ public CSSStyleSheetImpl getParentStyleSheet() { } /** + *getParentRule.
+ * * @return the parent rule */ public AbstractCSSRuleImpl getParentRule() { return parentRule_; } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { @@ -91,6 +102,7 @@ public boolean equals(final Object obj) { // recursive loop -> stack overflow! } + /** {@inheritDoc} */ @Override public int hashCode() { final int hash = super.hashCode(); diff --git a/src/main/java/org/htmlunit/cssparser/dom/AbstractColor.java b/src/main/java/org/htmlunit/cssparser/dom/AbstractColor.java new file mode 100644 index 0000000..082da53 --- /dev/null +++ b/src/main/java/org/htmlunit/cssparser/dom/AbstractColor.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2019-2024 Ronald Brill. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.htmlunit.cssparser.dom; + +import java.io.Serializable; +import java.util.Locale; + +import org.htmlunit.cssparser.parser.LexicalUnit; +import org.w3c.dom.DOMException; + +/** + * Color base class. + * + * @author Ronald Brill + */ +public class AbstractColor implements Serializable { + + private String function_; + private CSSValueImpl cssValue_; + + /** + * Constructor that reads the values from the given + * chain of LexicalUnits. + * @param function the name of the function; rgb or rgba + * @param lu the values + * @throws DOMException in case of error + */ + public AbstractColor(final String function, final LexicalUnit lu) throws DOMException { + function_ = function.toLowerCase(Locale.ROOT); + cssValue_ = new CSSValueImpl(lu); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + + sb + .append(function_) + .append("(") + .append(cssValue_) + .append(")"); + + return sb.toString(); + } +} diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSCharsetRuleImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSCharsetRuleImpl.java index 96c6d41..8954cf1 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSCharsetRuleImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSCharsetRuleImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,6 +25,7 @@ * Implementation of CSSCharsetRule. * * @author Ronald Brill + * */ public class CSSCharsetRuleImpl extends AbstractCSSRuleImpl { @@ -45,9 +46,7 @@ public CSSCharsetRuleImpl( encoding_ = encoding; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public void setCssText(final String cssText) throws DOMException { try { @@ -79,12 +78,15 @@ public void setCssText(final String cssText) throws DOMException { } /** + *getEncoding.
+ * * @return the encoding */ public String getEncoding() { return encoding_; } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { @@ -98,6 +100,7 @@ public boolean equals(final Object obj) { && ParserUtils.equals(getEncoding(), ccr.getEncoding()); } + /** {@inheritDoc} */ @Override public int hashCode() { int hash = super.hashCode(); @@ -105,14 +108,13 @@ public int hashCode() { return hash; } + /** {@inheritDoc} */ @Override public String toString() { return getCssText(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public String getCssText() { final StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSFontFaceRuleImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSFontFaceRuleImpl.java index 811e76f..f326793 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSFontFaceRuleImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSFontFaceRuleImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,6 +25,7 @@ * Implementation of CSSFontFaceRule. * * @author Ronald Brill + * */ public class CSSFontFaceRuleImpl extends AbstractCSSRuleImpl { @@ -32,6 +33,7 @@ public class CSSFontFaceRuleImpl extends AbstractCSSRuleImpl { /** * Ctor. + * * @param parentStyleSheet the parent style sheet * @param parentRule the parent rule */ @@ -39,9 +41,7 @@ public CSSFontFaceRuleImpl(final CSSStyleSheetImpl parentStyleSheet, final Abstr super(parentStyleSheet, parentRule); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public String getCssText() { final StringBuilder sb = new StringBuilder(); @@ -58,9 +58,7 @@ public String getCssText() { return sb.toString(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public void setCssText(final String cssText) throws DOMException { try { @@ -92,6 +90,8 @@ public void setCssText(final String cssText) throws DOMException { } /** + *getStyle.
+ * * @return the style */ public CSSStyleDeclarationImpl getStyle() { @@ -100,12 +100,14 @@ public CSSStyleDeclarationImpl getStyle() { /** * Sets the style to a new one. + * * @param style the new style */ public void setStyle(final CSSStyleDeclarationImpl style) { style_ = style; } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { @@ -119,6 +121,7 @@ public boolean equals(final Object obj) { && ParserUtils.equals(getStyle(), cffr.getStyle()); } + /** {@inheritDoc} */ @Override public int hashCode() { int hash = super.hashCode(); @@ -126,6 +129,7 @@ public int hashCode() { return hash; } + /** {@inheritDoc} */ @Override public String toString() { return getCssText(); diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSImportRuleImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSImportRuleImpl.java index c001abc..bc8b04b 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSImportRuleImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSImportRuleImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -25,6 +25,7 @@ * Implementation of CSSImportRule. * * @author Ronald Brill + * */ public class CSSImportRuleImpl extends AbstractCSSRuleImpl { @@ -49,9 +50,7 @@ public CSSImportRuleImpl( media_ = media; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public String getCssText() { final StringBuilder sb = new StringBuilder(); @@ -70,9 +69,7 @@ public String getCssText() { return sb.toString(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public void setCssText(final String cssText) throws DOMException { try { @@ -105,6 +102,8 @@ public void setCssText(final String cssText) throws DOMException { } /** + *getHref.
+ * * @return the href */ public String getHref() { @@ -112,6 +111,8 @@ public String getHref() { } /** + *getMedia.
+ * * @return the media lsit */ public MediaListImpl getMedia() { @@ -119,17 +120,21 @@ public MediaListImpl getMedia() { } /** + *getStyleSheet.
+ * * @return the parent style sheet */ public CSSStyleSheetImpl getStyleSheet() { return getParentStyleSheet(); } + /** {@inheritDoc} */ @Override public String toString() { return getCssText(); } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { @@ -144,6 +149,7 @@ public boolean equals(final Object obj) { && ParserUtils.equals(getMedia(), cir.getMedia()); } + /** {@inheritDoc} */ @Override public int hashCode() { int hash = super.hashCode(); diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSMediaRuleImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSMediaRuleImpl.java index e466bfc..0a1ef2b 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSMediaRuleImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSMediaRuleImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -28,6 +28,7 @@ * Implementation of CSSMediaRule. * * @author Ronald Brill + * */ public class CSSMediaRuleImpl extends AbstractCSSRuleImpl { @@ -36,6 +37,7 @@ public class CSSMediaRuleImpl extends AbstractCSSRuleImpl { /** * Ctor. + * * @param parentStyleSheet the parent style sheet * @param parentRule the parent rule * @param media the media @@ -48,9 +50,7 @@ public CSSMediaRuleImpl( mediaList_ = media; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public String getCssText() { final StringBuilder sb = new StringBuilder("@media "); @@ -65,9 +65,7 @@ public String getCssText() { return sb.toString(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public void setCssText(final String cssText) throws DOMException { try { @@ -100,6 +98,8 @@ public void setCssText(final String cssText) throws DOMException { } /** + *getMediaList.
+ * * @return the media list */ public MediaListImpl getMediaList() { @@ -107,6 +107,8 @@ public MediaListImpl getMediaList() { } /** + *getCssRules.
+ * * @return the css rules */ public CSSRuleListImpl getCssRules() { @@ -118,6 +120,7 @@ public CSSRuleListImpl getCssRules() { /** * Insert a new rule at the given index. + * * @param rule the rule to be inserted * @param index the insert pos * @throws DOMException in case of error @@ -181,11 +184,13 @@ public void setRuleList(final CSSRuleListImpl rules) { cssRules_ = rules; } + /** {@inheritDoc} */ @Override public String toString() { return getCssText(); } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSPageRuleImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSPageRuleImpl.java index ab835f4..0c0d0a4 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSPageRuleImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSPageRuleImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -109,7 +109,9 @@ public void setCssText(final String cssText) throws DOMException { } /** - * @return the current selector text + *getSelectorText.
+ * + * @return the selector text */ public String getSelectorText() { if (null == pseudoPage_) { diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSRuleListImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSRuleListImpl.java index 90459b9..4dec9ff 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSRuleListImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSRuleListImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -30,6 +30,8 @@ public class CSSRuleListImpl implements Serializable { private final ListgetRules.
+ * * @return the rules */ public ListgetLength.
+ * * @return the number of rules */ public int getLength() { @@ -75,6 +79,7 @@ public void delete(final int index) { getRules().remove(index); } + /** {@inheritDoc} */ @Override public String toString() { final StringBuilder sb = new StringBuilder(); @@ -87,6 +92,7 @@ public String toString() { return sb.toString(); } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSStyleDeclarationImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSStyleDeclarationImpl.java index 1b0558c..e253d3f 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSStyleDeclarationImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSStyleDeclarationImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -46,6 +46,8 @@ public CSSStyleDeclarationImpl(final AbstractCSSRuleImpl parentRule) { } /** + *getProperties.
+ * * @return the properties */ public ListgetPropertyCSSValue.
+ * * @param propertyName the property name * @return the property value */ @@ -146,6 +150,8 @@ public String removeProperty(final String propertyName) throws DOMException { } /** + *getPropertyPriority.
+ * * @param propertyName the name of the property * @return the priority */ @@ -194,6 +200,8 @@ public void setProperty( } /** + *getLength.
+ * * @return the properties count */ public int getLength() { @@ -201,6 +209,8 @@ public int getLength() { } /** + *getParentRule.
+ * * @return the parent rule */ public AbstractCSSRuleImpl getParentRule() { @@ -219,6 +229,8 @@ public void addProperty(final Property p) { } /** + *getPropertyDeclaration.
+ * * @param propertyName the name of the propery * @return the property */ diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSStyleRuleImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSStyleRuleImpl.java index 6ca0473..8feaea0 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSStyleRuleImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSStyleRuleImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSStyleSheetImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSStyleSheetImpl.java index c5855dd..310dbe8 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSStyleSheetImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSStyleSheetImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -61,6 +61,8 @@ public CSSStyleSheetImpl() { } /** + *getDisabled.
+ * * @return the disable state */ public boolean getDisabled() { @@ -77,6 +79,8 @@ public void setDisabled(final boolean disabled) { } /** + *getOwnerNode.
+ * * @return the owner node */ public Node getOwnerNode() { @@ -84,6 +88,8 @@ public Node getOwnerNode() { } /** + *getHref.
+ * * @return the href */ public String getHref() { @@ -91,6 +97,8 @@ public String getHref() { } /** + *getTitle.
+ * * @return the title */ public String getTitle() { @@ -98,6 +106,8 @@ public String getTitle() { } /** + *getMedia.
+ * * @return the media list */ public MediaListImpl getMedia() { @@ -105,6 +115,8 @@ public MediaListImpl getMedia() { } /** + *getOwnerRule.
+ * * @return the owner rule */ public AbstractCSSRuleImpl getOwnerRule() { @@ -112,6 +124,8 @@ public AbstractCSSRuleImpl getOwnerRule() { } /** + *getCssRules.
+ * * @return the css rules */ public CSSRuleListImpl getCssRules() { @@ -275,6 +289,8 @@ public void setMediaText(final String mediaText) { } /** + *setOwnerRule.
+ * * @param ownerRule the new ownerRule */ public void setOwnerRule(final AbstractCSSRuleImpl ownerRule) { @@ -282,17 +298,25 @@ public void setOwnerRule(final AbstractCSSRuleImpl ownerRule) { } /** + *setCssRules.
+ * * @param rules the new rules */ public void setCssRules(final CSSRuleListImpl rules) { cssRules_ = rules; } + /** + * {@inheritDoc} + */ @Override public String toString() { return getCssRules().toString(); } + /** + * {@inheritDoc} + */ @Override public boolean equals(final Object obj) { if (this == obj) { @@ -345,6 +369,8 @@ private void readObject(final ObjectInputStream in) throws IOException, ClassNot } /** + *getRuleIndex.
+ * * @return the CSSStyleSheetRuleIndex */ public CSSStyleSheetRuleIndex getRuleIndex() { diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSStyleSheetListImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSStyleSheetListImpl.java index 9305621..b38fb14 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSStyleSheetListImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSStyleSheetListImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -29,6 +29,8 @@ public class CSSStyleSheetListImpl { private ListgetCSSStyleSheets.
+ * * @return the list of style sheets */ public ListgetLength.
+ * * @return the number of style sheets */ public int getLength() { @@ -75,6 +79,7 @@ public CSSStyleSheetImpl merge() { return merged; } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSUnknownRuleImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSUnknownRuleImpl.java index a9c49df..5b72017 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSUnknownRuleImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSUnknownRuleImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -44,9 +44,7 @@ public CSSUnknownRuleImpl( text_ = text; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public String getCssText() { if (null == text_) { @@ -55,9 +53,7 @@ public String getCssText() { return text_; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public void setCssText(final String cssText) throws DOMException { try { @@ -88,11 +84,13 @@ public void setCssText(final String cssText) throws DOMException { } } + /** {@inheritDoc} */ @Override public String toString() { return getCssText(); } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSValueImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSValueImpl.java index d5d80d6..f53ea22 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CSSValueImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CSSValueImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,8 +23,8 @@ import org.htmlunit.cssparser.parser.CSSOMParser; import org.htmlunit.cssparser.parser.LexicalUnit; import org.htmlunit.cssparser.parser.LexicalUnit.LexicalUnitType; -import org.htmlunit.cssparser.util.ParserUtils; import org.htmlunit.cssparser.parser.LexicalUnitImpl; +import org.htmlunit.cssparser.util.ParserUtils; import org.w3c.dom.DOMException; /** @@ -164,6 +164,8 @@ public enum CSSPrimitiveValueType { private Object value_; /** + *getValue.
+ * * @return the value */ public Object getValue() { @@ -197,6 +199,18 @@ else if (value.getLexicalUnitType() == LexicalUnitType.HSLCOLOR) { // HSLColor value_ = new HSLColorImpl(value.getFunctionName(), value.getParameters()); } + else if (value.getLexicalUnitType() == LexicalUnitType.HWBCOLOR) { + // HWBColor + value_ = new HWBColorImpl(value.getFunctionName(), value.getParameters()); + } + else if (value.getLexicalUnitType() == LexicalUnitType.LABCOLOR) { + // LABColor + value_ = new LABColorImpl(value.getFunctionName(), value.getParameters()); + } + else if (value.getLexicalUnitType() == LexicalUnitType.LCHCOLOR) { + // LCHColor + value_ = new LCHColorImpl(value.getFunctionName(), value.getParameters()); + } else if (value.getLexicalUnitType() == LexicalUnitType.COUNTER_FUNCTION) { // Counter value_ = new CounterImpl(false, value.getParameters()); @@ -238,6 +252,8 @@ public CSSValueImpl(final LexicalUnit value) { } /** + *getCssText.
+ * * @return the css text */ public String getCssText() { @@ -294,6 +310,8 @@ public void setCssText(final String cssText) throws DOMException { } /** + *getCssValueType.
+ * * @return the css value type */ public CSSValueType getCssValueType() { @@ -308,6 +326,8 @@ public CSSValueType getCssValueType() { } /** + *getPrimitiveType.
+ * * @return the primitive type */ public CSSPrimitiveValueType getPrimitiveType() { @@ -376,6 +396,8 @@ public CSSPrimitiveValueType getPrimitiveType() { return CSSPrimitiveValueType.CSS_KHZ; case IDENT: return CSSPrimitiveValueType.CSS_IDENT; + case NONE: + return CSSPrimitiveValueType.CSS_IDENT; case STRING_VALUE: return CSSPrimitiveValueType.CSS_STRING; case ATTR: @@ -405,6 +427,8 @@ else if (value_ instanceof CounterImpl) { } /** + *getLexicalUnitType.
+ * * @return the lexical unit type */ public LexicalUnit.LexicalUnitType getLexicalUnitType() { @@ -425,8 +449,9 @@ public void setDoubleValue(final double doubleValue) throws DOMException { } /** - * @return the double value. + *getDoubleValue.
* + * @return the double value. * @throws DOMException in case of error */ public double getDoubleValue() throws DOMException { @@ -443,6 +468,8 @@ public double getDoubleValue() throws DOMException { } /** + *getStringValue.
+ * * @return the string value. * @throws DOMException case of error */ @@ -452,11 +479,18 @@ public String getStringValue() throws DOMException { if ((lu.getLexicalUnitType() == LexicalUnitType.IDENT) || (lu.getLexicalUnitType() == LexicalUnitType.STRING_VALUE) || (lu.getLexicalUnitType() == LexicalUnitType.URI) - || (lu.getLexicalUnitType() == LexicalUnitType.INHERIT) || (lu.getLexicalUnitType() == LexicalUnitType.ATTR)) { return lu.getStringValue(); } + if (lu.getLexicalUnitType() == LexicalUnitType.INHERIT) { + return "inherit"; + } + + if (lu.getLexicalUnitType() == LexicalUnitType.NONE) { + return "none"; + } + // for rgba values we are using this type if (lu.getLexicalUnitType() == LexicalUnitType.FUNCTION || lu.getLexicalUnitType() == LexicalUnitType.FUNCTION_CALC) { @@ -485,9 +519,10 @@ public int getLength() { } /** + *item.
+ * * @param index the position * @return the value at the position - * @throws DOMException in case of error */ @SuppressWarnings("unchecked") public CSSValueImpl item(final int index) { @@ -498,11 +533,13 @@ public CSSValueImpl item(final int index) { return null; } + /** {@inheritDoc} */ @Override public String toString() { return getCssText(); } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { diff --git a/src/main/java/org/htmlunit/cssparser/dom/CounterImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CounterImpl.java index 1da9fcd..4a31054 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/CounterImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/CounterImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -33,6 +33,7 @@ public class CounterImpl implements Serializable { /** * Creates new CounterImpl. + * * @param separatorSpecified true if the separator is specified * @param lu the lexical unit * @throws DOMException in case of error @@ -73,6 +74,8 @@ public CounterImpl(final boolean separatorSpecified, final LexicalUnit lu) throw } /** + *getIdentifier.
+ * * @return the identifier */ public String getIdentifier() { @@ -80,6 +83,8 @@ public String getIdentifier() { } /** + *getListStyle.
+ * * @return the list style */ public String getListStyle() { @@ -87,12 +92,15 @@ public String getListStyle() { } /** + *getSeparator.
+ * * @return the separator */ public String getSeparator() { return separator_; } + /** {@inheritDoc} */ @Override public String toString() { final StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/org/htmlunit/cssparser/dom/DOMExceptionImpl.java b/src/main/java/org/htmlunit/cssparser/dom/DOMExceptionImpl.java index 9ee3330..4f3395d 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/DOMExceptionImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/DOMExceptionImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -58,7 +58,7 @@ public class DOMExceptionImpl extends DOMException { /** INSERT_BEFORE_IMPORT = 16. */ public static final int INSERT_BEFORE_IMPORT = 16; - static final String[] messages = { + static final String[] MESSAGES_ = { "Syntax error", "Index out of bounds error", "This style sheet is read only", @@ -103,6 +103,6 @@ public DOMExceptionImpl(final int code, final int messageKey) { * @param info additional info */ public DOMExceptionImpl(final int code, final int messageKey, final String info) { - super((short) code, messages[messageKey] + " (" + info + ")"); + super((short) code, MESSAGES_[messageKey] + " (" + info + ")"); } } diff --git a/src/main/java/org/htmlunit/cssparser/dom/HSLColorImpl.java b/src/main/java/org/htmlunit/cssparser/dom/HSLColorImpl.java index 3df29f6..304611f 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/HSLColorImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/HSLColorImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,11 +14,7 @@ */ package org.htmlunit.cssparser.dom; -import java.io.Serializable; -import java.util.Locale; - import org.htmlunit.cssparser.parser.LexicalUnit; -import org.htmlunit.cssparser.parser.LexicalUnit.LexicalUnitType; import org.w3c.dom.DOMException; /** @@ -26,14 +22,7 @@ * * @author Ronald Brill */ -public class HSLColorImpl implements Serializable { - private final String function_; - - private CSSValueImpl hue_; - private CSSValueImpl saturation_; - private CSSValueImpl lightness_; - private CSSValueImpl alpha_; - private final boolean commaSeparated_; +public class HSLColorImpl extends AbstractColor { /** * Constructor that reads the values from the given @@ -43,220 +32,6 @@ public class HSLColorImpl implements Serializable { * @throws DOMException in case of error */ public HSLColorImpl(final String function, final LexicalUnit lu) throws DOMException { - if (function == null) { - throw new DOMException(DOMException.SYNTAX_ERR, "Color space hsl or hsla is required."); - } - final String functionLC = function.toLowerCase(Locale.ROOT); - if (!"hsl".equals(functionLC) && !"hsla".equals(functionLC)) { - throw new DOMException(DOMException.SYNTAX_ERR, "Color space '" + functionLC + "' not supported."); - } - function_ = functionLC; - - LexicalUnit next = lu; - hue_ = new CSSValueImpl(next, true); - - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " requires at least three values."); - } - - commaSeparated_ = next.getLexicalUnitType() == LexicalUnitType.OPERATOR_COMMA; - if (commaSeparated_) { - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " requires at least three values."); - } - - if (LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, "Saturation part has to be percentage."); - } - saturation_ = new CSSValueImpl(next, true); - - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " requires at least three values."); - } - - if (next.getLexicalUnitType() != LexicalUnitType.OPERATOR_COMMA) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " parameters must be separated by ','."); - } - - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + "b requires at least three values."); - } - - if (LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, "Lightness part has to be percentage."); - } - lightness_ = new CSSValueImpl(next, true); - - next = next.getNextLexicalUnit(); - if (next == null) { - return; - } - - if (next.getLexicalUnitType() != LexicalUnitType.OPERATOR_COMMA) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " parameters must be separated by ','."); - } - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, "Missing alpha value."); - } - - if (LexicalUnitType.INTEGER != next.getLexicalUnitType() - && LexicalUnitType.REAL != next.getLexicalUnitType() - && LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, "Alpha part has to be numeric or percentage."); - } - alpha_ = new CSSValueImpl(next, true); - next = next.getNextLexicalUnit(); - if (next != null) { - throw new DOMException(DOMException.SYNTAX_ERR, "Too many parameters for " + function_ + " function."); - } - return; - } - - if (LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, "Saturation part has to be percentage."); - } - saturation_ = new CSSValueImpl(next, true); - - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " requires at least three values."); - } - if (next.getLexicalUnitType() == LexicalUnitType.OPERATOR_COMMA) { - throw new DOMException(DOMException.SYNTAX_ERR, - function_ + " requires consitent separators (blank or comma)."); - } - - if (LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, "Lightness part has to be percentage."); - } - lightness_ = new CSSValueImpl(next, true); - next = next.getNextLexicalUnit(); - if (next == null) { - return; - } - - if (next.getLexicalUnitType() != LexicalUnitType.OPERATOR_SLASH) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " alpha value must be separated by '/'."); - } - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, "Missing alpha value."); - } - - if (LexicalUnitType.INTEGER != next.getLexicalUnitType() - && LexicalUnitType.REAL != next.getLexicalUnitType() - && LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, "Alpha part has to be numeric or percentage."); - } - alpha_ = new CSSValueImpl(next, true); - - next = next.getNextLexicalUnit(); - if (next != null) { - throw new DOMException(DOMException.SYNTAX_ERR, "Too many parameters for " + function_ + " function."); - } - } - - /** - * @return the hue part. - */ - public CSSValueImpl getHue() { - return hue_; - } - - /** - * Sets the hue part to a new value. - * @param hue the new CSSValueImpl - */ - public void setHue(final CSSValueImpl hue) { - hue_ = hue; - } - - /** - * @return the saturation part. - */ - public CSSValueImpl getSaturation() { - return saturation_; - } - - /** - * Sets the saturation part to a new value. - * @param saturation the new CSSValueImpl - */ - public void setSaturation(final CSSValueImpl saturation) { - saturation_ = saturation; - } - - /** - * @return the lightness part. - */ - public CSSValueImpl getLightness() { - return lightness_; - } - - /** - * Sets the lightness part to a new value. - * @param lightness the new CSSValueImpl - */ - public void setLightness(final CSSValueImpl lightness) { - lightness_ = lightness; - } - - /** - * @return the alpha part. - */ - public CSSValueImpl getAlpha() { - return alpha_; - } - - /** - * Sets the alpha part to a new value. - * @param alpha the new CSSValueImpl - */ - public void setAlpha(final CSSValueImpl alpha) { - alpha_ = alpha; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - - sb - .append(function_) - .append("(") - .append(hue_); - if (commaSeparated_) { - sb - .append(", ") - .append(saturation_) - .append(", ") - .append(lightness_); - - if (null != alpha_) { - sb.append(", ").append(alpha_); - } - } - else { - sb - .append(" ") - .append(saturation_) - .append(" ") - .append(lightness_); - - if (null != alpha_) { - sb.append(" / ").append(alpha_); - } - } - - sb.append(")"); - - return sb.toString(); + super(function, lu); } } diff --git a/src/main/java/org/htmlunit/cssparser/dom/HWBColorImpl.java b/src/main/java/org/htmlunit/cssparser/dom/HWBColorImpl.java new file mode 100644 index 0000000..e2c708b --- /dev/null +++ b/src/main/java/org/htmlunit/cssparser/dom/HWBColorImpl.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019-2024 Ronald Brill. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.htmlunit.cssparser.dom; + +import org.htmlunit.cssparser.parser.LexicalUnit; +import org.w3c.dom.DOMException; + +/** + * Implementation of HWBColor. + * + * @author Ronald Brill + */ +public class HWBColorImpl extends AbstractColor { + + /** + * Constructor that reads the values from the given + * chain of LexicalUnits. + * @param function the name of the function; hwb + * @param lu the values + * @throws DOMException in case of error + */ + public HWBColorImpl(final String function, final LexicalUnit lu) throws DOMException { + super(function, lu); + } +} diff --git a/src/main/java/org/htmlunit/cssparser/dom/LABColorImpl.java b/src/main/java/org/htmlunit/cssparser/dom/LABColorImpl.java new file mode 100644 index 0000000..34e0775 --- /dev/null +++ b/src/main/java/org/htmlunit/cssparser/dom/LABColorImpl.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019-2024 Ronald Brill. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.htmlunit.cssparser.dom; + +import org.htmlunit.cssparser.parser.LexicalUnit; +import org.w3c.dom.DOMException; + +/** + * Implementation of LABColor and OKLABColor. + * + * @author Ronald Brill + */ +public class LABColorImpl extends AbstractColor { + + /** + * Constructor that reads the values from the given + * chain of LexicalUnits. + * @param function the name of the function; lab or oklab + * @param lu the values + * @throws DOMException in case of error + */ + public LABColorImpl(final String function, final LexicalUnit lu) throws DOMException { + super(function, lu); + } +} diff --git a/src/main/java/org/htmlunit/cssparser/dom/LCHColorImpl.java b/src/main/java/org/htmlunit/cssparser/dom/LCHColorImpl.java new file mode 100644 index 0000000..d38bd63 --- /dev/null +++ b/src/main/java/org/htmlunit/cssparser/dom/LCHColorImpl.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019-2024 Ronald Brill. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.htmlunit.cssparser.dom; + +import org.htmlunit.cssparser.parser.LexicalUnit; +import org.w3c.dom.DOMException; + +/** + * Implementation of LCHColor and OKLCHColor. + * + * @author Ronald Brill + */ +public class LCHColorImpl extends AbstractColor { + + /** + * Constructor that reads the values from the given + * chain of LexicalUnits. + * @param function the name of the function; lch or oklch + * @param lu the values + * @throws DOMException in case of error + */ + public LCHColorImpl(final String function, final LexicalUnit lu) throws DOMException { + super(function, lu); + } +} diff --git a/src/main/java/org/htmlunit/cssparser/dom/MediaListImpl.java b/src/main/java/org/htmlunit/cssparser/dom/MediaListImpl.java index 29f1149..8da6c54 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/MediaListImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/MediaListImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -51,6 +51,8 @@ public MediaListImpl(final MediaQueryList mediaList) { } /** + *getMediaText.
+ * * @return the media text */ public String getMediaText() { @@ -89,6 +91,8 @@ public void setMediaText(final String mediaText) throws DOMException { } /** + *getLength.
+ * * @return the media query count */ public int getLength() { @@ -96,6 +100,8 @@ public int getLength() { } /** + *mediaQuery.
+ * * @param index the position of the media query * @return the media query at the given pos */ @@ -106,6 +112,7 @@ public MediaQuery mediaQuery(final int index) { return mediaQueries_.get(index); } + /** {@inheritDoc} */ @Override public String toString() { return getMediaText(); @@ -145,6 +152,7 @@ private boolean equalsMedia(final MediaListImpl ml) { return true; } + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { @@ -157,6 +165,7 @@ public boolean equals(final Object obj) { return super.equals(obj) && equalsMedia(ml); } + /** {@inheritDoc} */ @Override public int hashCode() { int hash = super.hashCode(); diff --git a/src/main/java/org/htmlunit/cssparser/dom/Property.java b/src/main/java/org/htmlunit/cssparser/dom/Property.java index 16901be..c24bb14 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/Property.java +++ b/src/main/java/org/htmlunit/cssparser/dom/Property.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -20,6 +20,8 @@ import org.htmlunit.cssparser.util.ParserUtils; /** + *Property class.
+ * * @author Ronald Brill */ public class Property extends AbstractLocatable implements Serializable { @@ -88,9 +90,7 @@ public void setImportant(final boolean important) { important_ = important; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public String toString() { final StringBuilder sb = new StringBuilder(); @@ -105,9 +105,7 @@ public String toString() { return sb.toString(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public boolean equals(final Object obj) { if (this == obj) { diff --git a/src/main/java/org/htmlunit/cssparser/dom/RGBColorImpl.java b/src/main/java/org/htmlunit/cssparser/dom/RGBColorImpl.java index 021c803..25fd9ee 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/RGBColorImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/RGBColorImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -14,11 +14,7 @@ */ package org.htmlunit.cssparser.dom; -import java.io.Serializable; -import java.util.Locale; - import org.htmlunit.cssparser.parser.LexicalUnit; -import org.htmlunit.cssparser.parser.LexicalUnit.LexicalUnitType; import org.w3c.dom.DOMException; /** @@ -26,14 +22,7 @@ * * @author Ronald Brill */ -public class RGBColorImpl implements Serializable { - private final String function_; - - private CSSValueImpl red_; - private CSSValueImpl green_; - private CSSValueImpl blue_; - private CSSValueImpl alpha_; - private final boolean commaSeparated_; +public class RGBColorImpl extends AbstractColor { /** * Constructor that reads the values from the given @@ -43,231 +32,6 @@ public class RGBColorImpl implements Serializable { * @throws DOMException in case of error */ public RGBColorImpl(final String function, final LexicalUnit lu) throws DOMException { - if (function == null) { - throw new DOMException(DOMException.SYNTAX_ERR, "Color space rgb or rgba is required."); - } - final String functionLC = function.toLowerCase(Locale.ROOT); - if (!"rgb".equals(functionLC) && !"rgba".equals(functionLC)) { - throw new DOMException(DOMException.SYNTAX_ERR, "Color space '" + functionLC + "' not supported."); - } - function_ = functionLC; - - LexicalUnit next = lu; - - final boolean percentage = LexicalUnitType.PERCENTAGE == next.getLexicalUnitType(); - red_ = getPart(next); - - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " requires at least three values."); - } - - commaSeparated_ = next.getLexicalUnitType() == LexicalUnitType.OPERATOR_COMMA; - if (commaSeparated_) { - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " requires at least three values."); - } - - if (percentage && LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages."); - } - if (!percentage && LexicalUnitType.PERCENTAGE == next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages."); - } - green_ = getPart(next); - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " requires at least three values."); - } - - if (next.getLexicalUnitType() != LexicalUnitType.OPERATOR_COMMA) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " parameters must be separated by ','."); - } - - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + "b requires at least three values."); - } - - if (percentage && LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages."); - } - if (!percentage && LexicalUnitType.PERCENTAGE == next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages."); - } - blue_ = getPart(next); - - next = next.getNextLexicalUnit(); - if (next == null) { - return; - } - - if (next.getLexicalUnitType() != LexicalUnitType.OPERATOR_COMMA) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " parameters must be separated by ','."); - } - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, "Missing alpha value"); - } - - alpha_ = getPart(next); - next = next.getNextLexicalUnit(); - if (next != null) { - throw new DOMException(DOMException.SYNTAX_ERR, "Too many parameters for " + function_ + " function."); - } - return; - } - - if (percentage && LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages."); - } - if (!percentage && LexicalUnitType.PERCENTAGE == next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages."); - } - green_ = getPart(next); - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " requires at least three values."); - } - if (next.getLexicalUnitType() == LexicalUnitType.OPERATOR_COMMA) { - throw new DOMException(DOMException.SYNTAX_ERR, - function_ + " requires consitent separators (blank or comma)."); - } - - if (percentage && LexicalUnitType.PERCENTAGE != next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages."); - } - if (!percentage && LexicalUnitType.PERCENTAGE == next.getLexicalUnitType()) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " mixing numbers and percentages."); - } - blue_ = getPart(next); - next = next.getNextLexicalUnit(); - if (next == null) { - return; - } - - if (next.getLexicalUnitType() != LexicalUnitType.OPERATOR_SLASH) { - throw new DOMException(DOMException.SYNTAX_ERR, function_ + " alpha value must be separated by '/'."); - } - next = next.getNextLexicalUnit(); - if (next == null) { - throw new DOMException(DOMException.SYNTAX_ERR, "Missing alpha value."); - } - - alpha_ = getPart(next); - next = next.getNextLexicalUnit(); - if (next != null) { - throw new DOMException(DOMException.SYNTAX_ERR, "Too many parameters for " + function_ + " function."); - } - } - - private static CSSValueImpl getPart(final LexicalUnit next) { - if (LexicalUnitType.PERCENTAGE == next.getLexicalUnitType() - || LexicalUnitType.INTEGER == next.getLexicalUnitType() - || LexicalUnitType.REAL == next.getLexicalUnitType()) { - return new CSSValueImpl(next, true); - } - - throw new DOMException(DOMException.SYNTAX_ERR, "Color part has to be numeric or percentage."); - } - - /** - * @return the red part. - */ - public CSSValueImpl getRed() { - return red_; - } - - /** - * Sets the red part to a new value. - * @param red the new CSSValueImpl - */ - public void setRed(final CSSValueImpl red) { - red_ = red; - } - - /** - * @return the green part. - */ - public CSSValueImpl getGreen() { - return green_; - } - - /** - * Sets the green part to a new value. - * @param green the new CSSValueImpl - */ - public void setGreen(final CSSValueImpl green) { - green_ = green; - } - - /** - * @return the blue part. - */ - public CSSValueImpl getBlue() { - return blue_; - } - - /** - * Sets the blue part to a new value. - * @param blue the new CSSValueImpl - */ - public void setBlue(final CSSValueImpl blue) { - blue_ = blue; - } - - /** - * @return the alpha part. - */ - public CSSValueImpl getAlpha() { - return alpha_; - } - - /** - * Sets the alpha part to a new value. - * @param alpha the new CSSValueImpl - */ - public void setAlpha(final CSSValueImpl alpha) { - alpha_ = alpha; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - - sb - .append(function_) - .append("(") - .append(red_); - if (commaSeparated_) { - sb - .append(", ") - .append(green_) - .append(", ") - .append(blue_); - - if (null != alpha_) { - sb.append(", ").append(alpha_); - } - } - else { - sb - .append(" ") - .append(green_) - .append(" ") - .append(blue_); - - if (null != alpha_) { - sb.append(" / ").append(alpha_); - } - } - - sb.append(")"); - - return sb.toString(); + super(function, lu); } } diff --git a/src/main/java/org/htmlunit/cssparser/dom/RectImpl.java b/src/main/java/org/htmlunit/cssparser/dom/RectImpl.java index 3df98ea..1b046c9 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/RectImpl.java +++ b/src/main/java/org/htmlunit/cssparser/dom/RectImpl.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -115,6 +115,8 @@ public RectImpl(final LexicalUnit lu) throws DOMException { } /** + *getTop.
+ * * @return the top part. */ public CSSValueImpl getTop() { @@ -130,6 +132,8 @@ public void setTop(final CSSValueImpl top) { } /** + *getRight.
+ * * @return the right part. */ public CSSValueImpl getRight() { @@ -145,6 +149,8 @@ public void setRight(final CSSValueImpl right) { } /** + *getBottom.
+ * * @return the bottom part. */ public CSSValueImpl getBottom() { @@ -160,6 +166,8 @@ public void setBottom(final CSSValueImpl bottom) { } /** + *getLeft.
+ * * @return the left part. */ public CSSValueImpl getLeft() { @@ -174,9 +182,7 @@ public void setLeft(final CSSValueImpl left) { left_ = left; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public String toString() { return new StringBuilder("rect(") diff --git a/src/main/java/org/htmlunit/cssparser/dom/package-info.java b/src/main/java/org/htmlunit/cssparser/dom/package-info.java index fe8a6e6..bafbd64 100644 --- a/src/main/java/org/htmlunit/cssparser/dom/package-info.java +++ b/src/main/java/org/htmlunit/cssparser/dom/package-info.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/org/htmlunit/cssparser/parser/AbstractCSSParser.java b/src/main/java/org/htmlunit/cssparser/parser/AbstractCSSParser.java index 46a24ef..b152df0 100644 --- a/src/main/java/org/htmlunit/cssparser/parser/AbstractCSSParser.java +++ b/src/main/java/org/htmlunit/cssparser/parser/AbstractCSSParser.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -24,7 +24,7 @@ import org.htmlunit.cssparser.parser.javacc.CharStream; import org.htmlunit.cssparser.parser.javacc.ParseException; import org.htmlunit.cssparser.parser.javacc.Token; -import org.htmlunit.cssparser.parser.javacc.TokenMgrError; +import org.htmlunit.cssparser.parser.javacc.TokenMgrException; import org.htmlunit.cssparser.parser.media.MediaQueryList; import org.htmlunit.cssparser.parser.selector.SelectorList; import org.w3c.dom.DOMException; @@ -39,60 +39,63 @@ public abstract class AbstractCSSParser { private CSSErrorHandler errorHandler_; private InputSource source_; - private static final HashMapgetDocumentHandler.
+ * * @return the document handler */ protected DocumentHandler getDocumentHandler() { @@ -122,6 +125,8 @@ public void setDocumentHandler(final DocumentHandler handler) { } /** + *getErrorHandler.
+ * * @return the error handler */ protected CSSErrorHandler getErrorHandler() { @@ -152,6 +157,8 @@ public void setErrorHandler(final CSSErrorHandler handler) { } /** + *getInputSource.
+ * * @return the input source */ protected InputSource getInputSource() { @@ -163,7 +170,7 @@ protected InputSource getInputSource() { * @return the parser message */ protected String getParserMessage(final String key) { - final String msg = parserMessages_.get(key); + final String msg = PARSER_MESSAGES_.get(key); if (msg == null) { return "[[" + key + "]]"; } @@ -233,6 +240,7 @@ protected String addEscapes(final String str) { } /** + *toCSSParseException.
* * @param key the message lookup key * @param e the parse exception @@ -282,6 +290,8 @@ protected CSSParseException toCSSParseException(final String key, final ParseExc } /** + *toCSSParseException.
+ * * @param e the DOMException * @return a new CSSParseException */ @@ -292,10 +302,12 @@ protected CSSParseException toCSSParseException(final DOMException e) { } /** - * @param e the TokenMgrError + *toCSSParseException.
+ * + * @param e the TokenMgrException * @return a new CSSParseException */ - protected CSSParseException toCSSParseException(final TokenMgrError e) { + protected CSSParseException toCSSParseException(final TokenMgrException e) { final String messagePattern = getParserMessage("tokenMgrError"); return new CSSParseException(messagePattern, getInputSource().getURI(), 1, 1); } @@ -354,7 +366,7 @@ public void parseStyleSheet(final InputSource source) throws IOException { catch (final ParseException e) { getErrorHandler().error(toCSSParseException("invalidStyleSheet", e)); } - catch (final TokenMgrError e) { + catch (final TokenMgrException e) { getErrorHandler().error(toCSSParseException(e)); } catch (final CSSParseException e) { @@ -381,7 +393,7 @@ public void parseStyleDeclaration(final InputSource source) throws IOException { catch (final ParseException e) { getErrorHandler().error(toCSSParseException("invalidStyleDeclaration", e)); } - catch (final TokenMgrError e) { + catch (final TokenMgrException e) { getErrorHandler().error(toCSSParseException(e)); } catch (final CSSParseException e) { @@ -408,7 +420,7 @@ public void parseRule(final InputSource source) throws IOException { catch (final ParseException e) { getErrorHandler().error(toCSSParseException("invalidRule", e)); } - catch (final TokenMgrError e) { + catch (final TokenMgrException e) { getErrorHandler().error(toCSSParseException(e)); } catch (final CSSParseException e) { @@ -437,7 +449,7 @@ public SelectorList parseSelectors(final InputSource source) throws IOException catch (final ParseException e) { getErrorHandler().error(toCSSParseException("invalidSelectorList", e)); } - catch (final TokenMgrError e) { + catch (final TokenMgrException e) { getErrorHandler().error(toCSSParseException(e)); } catch (final CSSParseException e) { @@ -467,7 +479,7 @@ public LexicalUnit parsePropertyValue(final InputSource source) throws IOExcepti catch (final ParseException e) { getErrorHandler().error(toCSSParseException("invalidExpr", e)); } - catch (final TokenMgrError e) { + catch (final TokenMgrException e) { getErrorHandler().error(toCSSParseException(e)); } catch (final CSSParseException e) { @@ -497,7 +509,7 @@ public boolean parsePriority(final InputSource source) throws IOException { catch (final ParseException e) { getErrorHandler().error(toCSSParseException("invalidPrio", e)); } - catch (final TokenMgrError e) { + catch (final TokenMgrException e) { getErrorHandler().error(toCSSParseException(e)); } catch (final CSSParseException e) { @@ -522,7 +534,7 @@ public MediaQueryList parseMedia(final InputSource source) throws IOException { catch (final ParseException e) { getErrorHandler().error(toCSSParseException("invalidMediaList", e)); } - catch (final TokenMgrError e) { + catch (final TokenMgrException e) { getErrorHandler().error(toCSSParseException(e)); } catch (final CSSParseException e) { @@ -544,10 +556,10 @@ private static CharStream getCharStream(final InputSource source) throws IOExcep /** * @return a string about which CSS language is supported by this - * parser. For CSS Level 1, it returns "http://www.w3.org/TR/REC-CSS1", for - * CSS Level 2, it returns "http://www.w3.org/TR/REC-CSS2". Note that a - * "CSSx" parser can return lexical unit other than those allowed by CSS - * Level x but this usage is not recommended. + * parser. For CSS Level 1, it returns "http://www.w3.org/TR/REC-CSS1", for + * CSS Level 2, it returns "http://www.w3.org/TR/REC-CSS2". Note that a + * "CSSx" parser can return lexical unit other than those allowed by CSS + * Level x but this usage is not recommended. */ public abstract String getParserVersion(); @@ -788,6 +800,21 @@ protected LexicalUnit hslColorInternal(final LexicalUnit prev, final String func return LexicalUnitImpl.createHslColor(prev, funct, param); } + protected LexicalUnit hwbColorInternal(final LexicalUnit prev, final String funct, + final LexicalUnit param) { + return LexicalUnitImpl.createHwbColor(prev, funct, param); + } + + protected LexicalUnit labColorInternal(final LexicalUnit prev, final String funct, + final LexicalUnit param) { + return LexicalUnitImpl.createLabColor(prev, funct, param); + } + + protected LexicalUnit lchColorInternal(final LexicalUnit prev, final String funct, + final LexicalUnit param) { + return LexicalUnitImpl.createLchColor(prev, funct, param); + } + /** * Processes a hexadecimal color definition. * diff --git a/src/main/java/org/htmlunit/cssparser/parser/AbstractLocatable.java b/src/main/java/org/htmlunit/cssparser/parser/AbstractLocatable.java index 004c795..496a325 100644 --- a/src/main/java/org/htmlunit/cssparser/parser/AbstractLocatable.java +++ b/src/main/java/org/htmlunit/cssparser/parser/AbstractLocatable.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -23,11 +23,13 @@ public class AbstractLocatable implements Locatable { private Locator locator_; + /** {@inheritDoc} */ @Override public Locator getLocator() { return locator_; } + /** {@inheritDoc} */ @Override public void setLocator(final Locator locator) { locator_ = locator; diff --git a/src/main/java/org/htmlunit/cssparser/parser/CSSErrorHandler.java b/src/main/java/org/htmlunit/cssparser/parser/CSSErrorHandler.java index 2b7af57..f74e5a5 100644 --- a/src/main/java/org/htmlunit/cssparser/parser/CSSErrorHandler.java +++ b/src/main/java/org/htmlunit/cssparser/parser/CSSErrorHandler.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -15,9 +15,9 @@ package org.htmlunit.cssparser.parser; /** - * Interface for CSS parser error handlers. - * @author Ronald Brill - */ + * Interface for CSS parser error handlers. + * @author Ronald Brill + */ public interface CSSErrorHandler { /** @@ -25,6 +25,7 @@ public interface CSSErrorHandler { * * @param exception the {@link CSSParseException} that is the reason for the warning. * @exception CSSException in case of error + * @throws CSSException if any. */ void warning(CSSParseException exception) throws CSSException; @@ -33,6 +34,7 @@ public interface CSSErrorHandler { * * @param exception the {@link CSSParseException} that is the reason for the error. * @exception CSSException in case of error + * @throws CSSException if any. */ void error(CSSParseException exception) throws CSSException; @@ -41,6 +43,7 @@ public interface CSSErrorHandler { * * @param exception the {@link CSSParseException} that is the reason for the error. * @exception CSSException in case of error + * @throws CSSException if any. */ void fatalError(CSSParseException exception) throws CSSException; } diff --git a/src/main/java/org/htmlunit/cssparser/parser/CSSException.java b/src/main/java/org/htmlunit/cssparser/parser/CSSException.java index e0f0307..32e985d 100644 --- a/src/main/java/org/htmlunit/cssparser/parser/CSSException.java +++ b/src/main/java/org/htmlunit/cssparser/parser/CSSException.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -19,7 +19,12 @@ */ public class CSSException extends RuntimeException { - /** Enum for error codes. */ + /** + * Enum for error codes. + * + * @deprecated as of version 4.4.0 + */ + @Deprecated protected enum ErrorCode { /** Unspecified. */ UNSPECIFIED_ERR, @@ -34,14 +39,20 @@ protected enum ErrorCode { /** * Creates a new CSSException. + * + * @deprecated as of version 4.4.0; use {@link CSSException#CSSException(String, Exception)} instead */ + @Deprecated public CSSException() { } /** * Creates a new CSSException. * @param message the message + * + * @deprecated as of version 4.4.0; use {@link CSSException#CSSException(String, Exception)} instead */ + @Deprecated public CSSException(final String message) { code_ = ErrorCode.UNSPECIFIED_ERR; message_ = message; @@ -50,7 +61,10 @@ public CSSException(final String message) { /** * Creates a new CSSException with an embeded exception. * @param e the embeded exception. + * + * @deprecated as of version 4.4.0; use {@link CSSException#CSSException(String, Exception)} instead */ + @Deprecated public CSSException(final Exception e) { code_ = ErrorCode.UNSPECIFIED_ERR; initCause(e); @@ -59,7 +73,10 @@ public CSSException(final Exception e) { /** * Creates a new CSSException with a specific code. * @param code a the embeded exception. + * + * @deprecated as of version 4.4.0; use {@link CSSException#CSSException(String, Exception)} instead */ + @Deprecated public CSSException(final ErrorCode code) { code_ = code; } @@ -70,7 +87,10 @@ public CSSException(final ErrorCode code) { * @param code the specified code * @param message the message * @param e the embeded exception + * + * @deprecated as of version 4.4.0; use {@link CSSException#CSSException(String, Exception)} instead */ + @Deprecated public CSSException(final ErrorCode code, final String message, final Exception e) { code_ = code; message_ = message; @@ -78,6 +98,19 @@ public CSSException(final ErrorCode code, final String message, final Exception } /** + * Creates a new CSSException with an embeded exception and a specified + * message. + * @param message the message + * @param e the cause + */ + public CSSException(final String message, final Exception e) { + message_ = message; + initCause(e); + } + + /** + * {@inheritDoc} + * * Returns the detail message of this throwable object. * * @return the detail message of this Throwable, or null if this Throwable @@ -93,22 +126,6 @@ public String getMessage() { return getCause().getMessage(); } - switch (code_) { - case UNSPECIFIED_ERR: - return "unknown error"; - case NOT_SUPPORTED_ERR: - return "not supported"; - case SYNTAX_ERR: - return "syntax error"; - default: - return null; - } - } - - /** - * @return the error code for this exception. - */ - public ErrorCode getCode() { - return code_; + return "syntax error"; } } diff --git a/src/main/java/org/htmlunit/cssparser/parser/CSSOMParser.java b/src/main/java/org/htmlunit/cssparser/parser/CSSOMParser.java index aad7cd8..faa8f07 100644 --- a/src/main/java/org/htmlunit/cssparser/parser/CSSOMParser.java +++ b/src/main/java/org/htmlunit/cssparser/parser/CSSOMParser.java @@ -1,10 +1,10 @@ /* - * Copyright (c) 2019-2023 Ronald Brill. + * Copyright (c) 2019-2024 Ronald Brill. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,9 @@ import java.io.IOException; import java.io.StringReader; -import java.util.Stack; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.Iterator; import org.htmlunit.cssparser.dom.AbstractCSSRuleImpl; import org.htmlunit.cssparser.dom.CSSCharsetRuleImpl; @@ -61,6 +63,8 @@ public CSSOMParser() { } /** + *setErrorHandler.
+ * * @param eh the error handler to be used */ public void setErrorHandler(final CSSErrorHandler eh) { @@ -109,7 +113,7 @@ public CSSStyleDeclarationImpl parseStyleDeclaration(final String styleDecl) thr */ public void parseStyleDeclaration(final CSSStyleDeclarationImpl sd, final String styleDecl) throws IOException { try (InputSource source = new InputSource(new StringReader(styleDecl))) { - final Stack