diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..657905b
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,12 @@
+# These are supported funding model platforms
+
+github: [rbri] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
+patreon: # Replace with a single Patreon username
+open_collective: # Replace with a single Open Collective username
+ko_fi: # Replace with a single Ko-fi username
+tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
+community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
+liberapay: # Replace with a single Liberapay username
+issuehunt: # Replace with a single IssueHunt username
+otechie: # Replace with a single Otechie username
+custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index 08af732..e90d2e9 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -15,14 +15,13 @@ on:
push:
branches: [ "master" ]
pull_request:
- # The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '34 23 * * 1'
jobs:
analyze:
- name: Analyze
+ name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
@@ -31,28 +30,37 @@ jobs:
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
+ # required for all workflows
+ security-events: write
+
+ # only required for workflows in private repositories
actions: read
contents: read
- security-events: write
strategy:
fail-fast: false
matrix:
- language: [ 'java' ]
- # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
- # Use only 'java' to analyze code written in Java, Kotlin or both
- # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
- # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
-
+ include:
+ - language: java-kotlin
+ build-mode: none # This mode only analyzes Java. Set this to 'autobuild' or 'manual' to analyze Kotlin too.
+ # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
+ # Use `c-cpp` to analyze code written in C, C++ or both
+ # Use 'java-kotlin' to analyze code written in Java, Kotlin or both
+ # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
+ # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
+ # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
+ # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
+ # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
- uses: github/codeql-action/init@v2
+ uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
+ build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
@@ -60,23 +68,22 @@ jobs:
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
-
- # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
- # If this step fails, then you should remove it and run the build manually (see below)
- - name: Autobuild
- uses: github/codeql-action/autobuild@v2
-
+ # If the analyze step fails for one of the languages you are analyzing with
+ # "We were unable to automatically build your code", modify the matrix above
+ # to set the build mode to "manual" for that language. Then modify this step
+ # to build your code.
# âšī¸ Command-line programs to run using the OS shell.
# đ See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
-
- # If the Autobuild fails above, remove it and uncomment the following three lines.
- # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
-
- # - run: |
- # echo "Run, Build Application using script"
- # ./location_of_script_within_repo/buildscript.sh
+ - if: matrix.build-mode == 'manual'
+ run: |
+ echo 'If you are using a "manual" build mode for one or more of the' \
+ 'languages you are analyzing, replace this with the commands to build' \
+ 'your code, for example:'
+ echo ' make bootstrap'
+ echo ' make release'
+ exit 1
- name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v2
+ uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
diff --git a/.gitignore b/.gitignore
index 00bb005..d0c8148 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
/.checkstyle
/.classpath
/.project
+.idea/
+/.settings/org.eclipse.core.resources.prefs
diff --git a/AGENTS.md b/AGENTS.md
new file mode 100644
index 0000000..133be3e
--- /dev/null
+++ b/AGENTS.md
@@ -0,0 +1,259 @@
+# AGENTS.md â HtmlUnit-CSSParser
+
+## Project Overview
+
+HtmlUnit-CSSParser is a **CSS parser for Java** that reads CSS source text and produces a DOM-style object tree. It is the CSS parser powering [HtmlUnit](https://www.htmlunit.org/) since version 1.30. The project originated as a fork of [CSSParser 0.9.25](http://cssparser.sourceforge.net/), with the SAC (`org.w3c.css.sac`) dependency removed and a more flexible object model introduced.
+
+- **Group/Artifact:** `org.htmlunit:htmlunit-cssparser`
+- **License:** Apache License 2.0
+- **Default branch:** `master`
+- **Java version:** JDK 17+ (version 5.x, current development); JDK 8+ for 4.x releases
+- **Build system:** Maven
+
+## Repository Structure
+
+```
+htmlunit-cssparser/
+âââ pom.xml # Maven build configuration
+âââ checkstyle.xml # Checkstyle rules (enforced on build)
+âââ checkstyle_suppressions.xml # Checkstyle suppression rules
+âââ README.md
+âââ LICENSE # Apache 2.0
+âââ .github/
+â âââ workflows/
+â â âââ codeql.yml # CodeQL security scanning (Java)
+â âââ dependabot.yml # Dependabot dependency updates
+â âââ FUNDING.yml # Sponsorship info
+âââ src/
+â âââ main/
+â â âââ java/org/htmlunit/cssparser/
+â â â âââ dom/ # CSS DOM implementation classes
+â â â âââ parser/ # Core parser classes
+â â â â âââ condition/ # CSS selector conditions
+â â â â âââ selector/ # CSS selector model
+â â â â âââ media/ # Media query support
+â â â âââ util/ # Utility classes
+â â âââ javacc/
+â â âââ CSS3Parser.jj # JavaCC grammar file (generates the parser)
+â âââ test/
+â âââ java/ # JUnit 5 test classes
+â âââ resources/ # CSS test fixture files
+âââ target/ # Build output (not committed)
+```
+
+## Build and Test
+
+### Prerequisites
+
+- **Maven 3.6.3+**
+- **JDK 17+** (for current master / version 5.x)
+
+### Commands
+
+```bash
+# Compile (this also runs JavaCC to generate the parser from CSS3Parser.jj)
+mvn compile
+
+# Run all tests
+mvn test
+
+# Full build with checkstyle verification
+mvn -U clean test
+
+# Check for dependency/plugin updates
+mvn versions:display-plugin-updates
+mvn versions:display-dependency-updates
+```
+
+### Generated Code
+
+The CSS parser is generated from a **JavaCC grammar file** at `src/main/javacc/CSS3Parser.jj`. During the `generate-sources` phase, the `ph-javacc-maven-plugin` generates Java source files into `target/generated-sources/javacc/org/htmlunit/cssparser/parser/javacc/`. A post-processing step using the `maven-replacer-plugin` cleans up the generated code (removes dead code patterns produced by JavaCC).
+
+**Do not manually edit files in `target/generated-sources/`** â they are regenerated on every build. If parser behavior needs to change, edit `src/main/javacc/CSS3Parser.jj`.
+
+## Architecture and Key Packages
+
+### `org.htmlunit.cssparser.parser` â Core Parser
+
+The main entry point for users. Key classes:
+
+| Class | Purpose |
+|---|---|
+| `CSSOMParser` | High-level parser that produces a DOM-style tree from CSS input. Main public API. |
+| `AbstractCSSParser` | Base class with shared parsing logic; `CSS3Parser` (generated) extends this. |
+| `InputSource` | Wraps a `Reader` to feed CSS text to the parser. Replaces the old SAC `InputSource`. |
+| `LexicalUnit` / `LexicalUnitImpl` | Represents CSS values (lengths, colors, functions, etc.) as a linked list of lexical tokens. |
+| `CSSErrorHandler` | Interface for custom error handling during parsing. Replaces the old SAC `ErrorHandler`. |
+| `CSSException` / `CSSParseException` | Exception types for parse errors. |
+| `DocumentHandler` / `HandlerBase` | Event-based (SAX-like) callback interface for streaming CSS parsing. |
+| `Locator` / `Locatable` | Source location tracking (line/column numbers). |
+
+### `org.htmlunit.cssparser.parser.selector` â Selector Model
+
+Represents CSS selectors as an object model:
+
+- `Selector`, `SimpleSelector` â base types
+- `ElementSelector` â type selectors (`h1`, `div`, `*`)
+- `DescendantSelector`, `ChildSelector` â combinators (` `, `>`)
+- `DirectAdjacentSelector`, `GeneralAdjacentSelector` â combinators (`+`, `~`)
+- `PseudoElementSelector` â pseudo-elements (`::before`, `::after`)
+- `RelativeSelector` â for `:has()` relative selectors
+- `SelectorList` / `SelectorListImpl` â ordered list of selectors
+- `SelectorSpecificity` â calculates selector specificity
+- `Combinator` â enum of CSS combinator types
+
+### `org.htmlunit.cssparser.parser.condition` â Selector Conditions
+
+Conditions attached to selectors (class, id, attribute, pseudo-class matching):
+
+- `ClassCondition` (`.foo`), `IdCondition` (`#bar`)
+- `AttributeCondition` (`[attr=val]`), `PrefixAttributeCondition` (`[attr^=val]`), `SuffixAttributeCondition` (`[attr$=val]`), `SubstringAttributeCondition` (`[attr*=val]`), `OneOfAttributeCondition` (`[attr~=val]`), `BeginHyphenAttributeCondition` (`[attr|=val]`)
+- `PseudoClassCondition` (`:hover`, `:nth-child()`, etc.)
+- `NotPseudoClassCondition` (`:not()`), `IsPseudoClassCondition` (`:is()`), `HasPseudoClassCondition` (`:has()`), `WherePseudoClassCondition` (`:where()`)
+- `LangCondition` (`:lang()`)
+
+### `org.htmlunit.cssparser.parser.media` â Media Queries
+
+- `MediaQuery` â a single media query (`screen and (min-width: 768px)`)
+- `MediaQueryList` â a list of media queries
+
+### `org.htmlunit.cssparser.dom` â CSS DOM Implementation
+
+Implements a CSS object model (style sheets, rules, values):
+
+- `CSSStyleSheetImpl` â represents a complete stylesheet
+- `CSSStyleRuleImpl` â a style rule (`selector { declarations }`)
+- `CSSStyleDeclarationImpl` â a set of property declarations
+- `CSSMediaRuleImpl`, `CSSImportRuleImpl`, `CSSPageRuleImpl`, `CSSFontFaceRuleImpl`, `CSSCharsetRuleImpl`, `CSSUnknownRuleImpl` â at-rule implementations
+- `CSSRuleListImpl` â ordered list of rules
+- `CSSValueImpl` â wraps parsed CSS values
+- `Property` â a single CSS property with name, value, and priority
+- Color classes: `RGBColorImpl`, `HSLColorImpl`, `HWBColorImpl`, `LABColorImpl`, `LCHColorImpl` (plus `AbstractColor` base)
+- `RectImpl`, `CounterImpl` â CSS `rect()` and `counter()` value types
+- `MediaListImpl`, `CSSStyleSheetListImpl` â list types
+- `DOMExceptionImpl` â DOM exception handling
+
+### `org.htmlunit.cssparser.util` â Utilities
+
+- `ParserUtils` â string processing helpers used by the generated parser (trimming, unescaping)
+
+## Code Style and Quality
+
+### Checkstyle
+
+Checkstyle is **strictly enforced** via `checkstyle.xml` and runs during the build. Key rules:
+
+- **Line length:** 120 characters max
+- **Indentation:** 4-space tabs
+- **Braces:** opening brace on same line (`eol`), closing brace on its own line (`alone`)
+- **Naming conventions:**
+ - Member fields: `camelCase_` (trailing underscore)
+ - Static fields: `CamelCase_` (capital start, trailing underscore)
+ - Constants: `UPPER_SNAKE_CASE` (exception: `log`)
+ - Methods: `camelCase` (test methods may use underscores: `test[A-Z][a-zA-Z0-9_]+`)
+ - Catch parameters: `e`, `ex`, `ignored`, or `expected`
+- **Javadoc:** Required on all public/protected methods, types, and packages. Author tag format: `@author Firstname Lastname`
+- **Imports:** No star imports, no unused imports, no redundant imports
+- **License header:** Required on every source file:
+ ```
+ /*
+ * Copyright (c) 2019-2026 Ronald Brill.
+ *
+ * Licensed under the Apache License, Version 2.0 ...
+ */
+ ```
+- **No `serialVersionUID`** fields
+- **No `@version`** tags
+- **No `System.out`/`System.err`** in production code
+- **Final local variables** and parameters are enforced
+- **No trailing whitespace**, no tab characters, no double blank lines
+- Single empty line after package declaration, none before it
+
+Checkstyle suppressions (`checkstyle_suppressions.xml`):
+- Test files are exempt from `JavadocPackage`, `JavadocMethod`, and `LineLength`
+- Generated files in `target/generated-sources/javacc` are fully exempt
+- `CssCharStream.java` is fully exempt (special character stream handling)
+
+### Testing
+
+- **Framework:** JUnit Jupiter (JUnit 5), version 6.x
+- **Test dependency:** `commons-io` (test scope only)
+- **Test resources:** CSS fixture files in `src/test/resources/`
+- **Run tests:** `mvn test` (uses `maven-surefire-plugin`)
+
+## CI/CD
+
+- **CodeQL:** GitHub Actions workflow (`.github/workflows/codeql.yml`) runs security analysis on pushes/PRs to `master` and weekly (Mondays 23:34 UTC). Analyzes Java code only.
+- **Dependabot:** Configured via `.github/dependabot.yml` for automated dependency update PRs.
+- **Jenkins:** Primary CI runs on an external Jenkins server at `https://jenkins.wetator.org/job/HtmlUnit%20-%20CSS%20Parser/`.
+
+## Making Changes
+
+### Modifying Parser Behavior
+
+1. Edit the JavaCC grammar: `src/main/javacc/CSS3Parser.jj`
+2. Run `mvn compile` to regenerate and compile
+3. Add/update tests to cover the change
+4. Run `mvn test` to verify
+
+### Adding Support for New CSS Features
+
+New CSS features typically require changes in multiple layers:
+
+1. **Grammar** (`CSS3Parser.jj`) â add token definitions and production rules
+2. **Lexical units** (`LexicalUnit.java`, `LexicalUnitImpl.java`) â add new `LexicalUnitType` enum values if needed
+3. **Conditions** (`parser/condition/`) â for new pseudo-classes or attribute selectors
+4. **Selectors** (`parser/selector/`) â for new selector types or combinators
+5. **DOM** (`dom/`) â for new at-rule types or value types
+6. **Tests** â comprehensive tests for parsing, serialization, and error handling
+
+### Code Conventions for PRs
+
+- Run `mvn -U clean test` and ensure all tests pass
+- Run checkstyle: it's part of the build; fix all violations
+- Follow the naming conventions (especially trailing underscores on fields)
+- Add Javadoc to all new public/protected API
+- Keep the license header on all new files
+- Do not modify generated files in `target/`
+
+## Versioning and Releases
+
+- **Current development:** 5.0.0-SNAPSHOT (requires JDK 17+)
+- **Latest stable:** 4.21.0 (December 2025, JDK 8+)
+- **Artifacts:** Published to Maven Central via Sonatype Central Publishing
+- **Release process:** (from README)
+ 1. Ensure all tests pass
+ 2. Update version in `pom.xml` and `README.md`
+ 3. Commit, build, and deploy: `mvn -up clean deploy`
+ 4. Publish on Maven Central Portal
+ 5. Create GitHub release with signed JARs
+ 6. Bump to next SNAPSHOT version
+
+## Dependencies
+
+### Runtime
+
+**None.** The library has zero runtime dependencies â it is completely self-contained.
+
+### Test Only
+
+- `org.junit.jupiter:junit-jupiter-engine`
+- `org.junit.platform:junit-platform-launcher`
+- `commons-io:commons-io`
+
+## Key Design Decisions
+
+1. **No SAC dependency:** The `org.w3c.css.sac` API (stalled since 2008) was removed. All interfaces are built-in, giving the project full control over the object model.
+2. **JavaCC-based parser:** The CSS grammar is defined in `CSS3Parser.jj` and compiled by JavaCC. This provides robust, specification-aligned tokenization and parsing.
+3. **Event-based + DOM-based API:** The parser supports both SAX-like streaming (`DocumentHandler`) and tree-building (`CSSOMParser`) usage patterns.
+4. **Zero runtime dependencies:** Makes the library safe to embed anywhere without dependency conflicts.
+
+## Links
+
+- **Repository:** https://github.com/HtmlUnit/htmlunit-cssparser
+- **Maven Central:** https://central.sonatype.com/artifact/org.htmlunit/htmlunit-cssparser
+- **HtmlUnit:** https://www.htmlunit.org/
+- **Developer Blog:** https://htmlunit.github.io/htmlunit-blog/
+- **CI:** https://jenkins.wetator.org/job/HtmlUnit%20-%20CSS%20Parser/
+- **Sponsor:** https://github.com/sponsors/rbri
+- **Predecessor:** http://cssparser.sourceforge.net/
\ No newline at end of file
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 0000000..eef4bd2
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1 @@
+@AGENTS.md
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index 261eeb9..b447376 100644
--- a/LICENSE
+++ b/LICENSE
@@ -192,7 +192,7 @@
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/README.md b/README.md
index 0cd060f..f6b5e3e 100644
--- a/README.md
+++ b/README.md
@@ -8,26 +8,65 @@ This implementation starts based on CSSParser 0.9.25; we removed the sac depende
We will try to stay in sync with CSSParser regarding the features in the future.
-[](https://maven-badges.herokuapp.com/maven-central/net.sourceforge.htmlunit/htmlunit-cssparser)
+[](https://central.sonatype.com/artifact/org.htmlunit/htmlunit-cssparser)
:heart: [Sponsor](https://github.com/sponsors/rbri)
### Project News
-[HtmlUnit@Twitter][3]
-### Latest release Version 3.6.0 / October 3, 2023
+**[Developer Blog](https://htmlunit.github.io/htmlunit-blog/)**
-For maven, you would add:
+[HtmlUnit@mastodon](https://fosstodon.org/@HtmlUnit) | [HtmlUnit@bsky](https://bsky.app/profile/htmlunit.bsky.social) | [HtmlUnit@Twitter](https://twitter.com/HtmlUnit)
-
- org.htmlunit
- htmlunit-cssparser
- 3.6.0
-
+#### Version 5
+
+Work on HtmlUnit-CSSParser 5.0 has started. This new major version will require **JDK 17 or higher**.
+
+
+#### Legacy Support (JDK 8)
+
+If you need to continue using **JDK 8**, please note that versions 4.x will remain available as-is. However,
+**ongoing maintenance and fixes for JDK 8 compatibility are only available through sponsorship**.
+
+Maintaining separate fix versions for JDK 8 requires significant additional effort for __backporting__, testing, and release management.
+
+**To enable continued JDK 8 support**, please contact me via email to discuss sponsorship options. Sponsorship provides:
+
+- __Backporting__ security and bug fixes to the 4.x branch
+- Maintaining compatibility with older Java versions
+- Timely releases for critical issues
+
+Without sponsorship, the 4.x branch will not receive updates. Your support ensures the long-term __sustainability__ of this project across multiple Java versions.
+
+### Latest release Version 4.21.0 / December 28, 2025
+
+## Get it!
+
+### Maven
+
+Add to your `pom.xml`:
-### Latst CI build
+```xml
+
+ org.htmlunit
+ htmlunit-cssparser
+ 4.21.0
+
+```
+
+### Gradle
+
+Add to your `build.gradle`:
+
+```groovy
+implementation group: 'org.htmlunit', name: 'htmlunit-cssparser', version: '4.21.0'
+```
+
+
+
+### Latest CI build
The latest builds are available from our
-[Jenkins CI build server][2]
+[Jenkins CI build server](https://jenkins.wetator.org/job/HtmlUnit%20-%20CSS%20Parser/ "HtmlUnit - CSS Parser CI")
[](https://jenkins.wetator.org/job/HtmlUnit%20-%20CSS%20Parser/)
@@ -36,22 +75,24 @@ If you use maven please add:
org.htmlunithtmlunit-cssparser
- 3.7.0-SNAPSHOT
+ 4.22.0-SNAPSHOT
-You have to add the sonatype snapshot repository to your pom `repositories` section also:
+You have to add the sonatype-central snapshot repository to your pom `repositories` section also:
-
- OSS Sonatype snapshots
- https://s01.oss.sonatype.org/content/repositories/snapshots/
-
- true
- always
-
-
- false
-
-
+
+
+ Central Portal Snapshots
+ central-portal-snapshots
+ https://central.sonatype.com/repository/maven-snapshots/
+
+ false
+
+
+ true
+
+
+
## Start HtmlUnit - CSSParser Development
@@ -89,7 +130,14 @@ Every contribution - from bug reports to feature requests, typos to full new fea
This part is intended for committer who are packaging a release.
* Check all your files are checked in
-* Execute "mvn -U clean test" to be sure all tests are passing
+* Execute these mvn commands to be sure all tests are passing and everything is up to data
+
+```
+ mvn versions:display-plugin-updates
+ mvn versions:display-dependency-updates
+ mvn -U clean test
+```
+
* Update the version number in pom.xml and README.md
* Commit the changes
@@ -100,19 +148,22 @@ This part is intended for committer who are packaging a release.
mvn -up clean deploy
```
-* Go to [Sonatype staging repositories](https://s01.oss.sonatype.org/index.html#stagingRepositories) and process the deploy
- - select the repository and close it - wait until the close is processed
- - release the package and wait until it is processed
+* Go to [Maven Central Portal](https://central.sonatype.com/) and process the deploy
+ - publish the package and wait until it is processed
* Create the version on Github
* login to Github and open project https://github.com/HtmlUnit/htmlunit-cssparser
* click Releases > Draft new release
- * fill the tag and title field with the release number (e.g. 3.0.0)
+ * fill the tag and title field with the release number (e.g. 4.0.0)
* append
- * htmlunit-cssparser-3.x.x.jar
- * htmlunit-cssparser-3.x.x.jar.asc
- * htmlunit-cssparser-3.x.x-javadoc.jar
- * htmlunit-cssparser-3.x.x-javadoc.jar.asc
+ * htmlunit-cssparser-4.x.x.jar
+ * htmlunit-cssparser-4.x.x.jar.asc
+ * htmlunit-cssparser-4.x.x.pom
+ * htmlunit-cssparser-4.x.x.pom.asc
+ * htmlunit-cssparser-4.x.x-javadoc.jar
+ * htmlunit-cssparser-4.x.x-javadoc.jar.asc
+ * htmlunit-cssparser-4.x.x-sources.jar
+ * htmlunit-cssparser-4.x.x-sources.jar.asc
* and publish the release
* Update the version number in pom.xml to start next snapshot development
@@ -131,6 +182,16 @@ This project is licensed under the Apache 2.0 License
Many thanks to all of you contributing to HtmlUnit/CSSParser/Rhino in the past.
+## Development Tools
+
+Special thanks to:
+
+
+
+**[JetBrains](https://www.jetbrains.com/)** for providing IntelliJ IDEA under their [open source development license](https://www.jetbrains.com/community/opensource/) and
+
+
+Eclipse Foundation for their Eclipse IDE
-[2]: https://jenkins.wetator.org/job/HtmlUnit%20-%20CSS%20Parser/ "HtmlUnit - CSS Parser CI"
-[3]: https://twitter.com/HtmlUnit "https://twitter.com/HtmlUnit"
+
+to **[Syntevo](https://www.syntevo.com/)** for their excellent [SmartGit](https://www.smartgit.dev/)!
diff --git a/checkstyle.xml b/checkstyle.xml
index 8293c9d..9e90772 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -24,7 +24,7 @@
-
+
@@ -33,6 +33,7 @@
+
@@ -99,15 +100,15 @@
-
+
+
+
+
@@ -123,12 +124,12 @@
-
-
-
-
+
+
+
+
@@ -137,7 +138,7 @@
-
+
@@ -145,9 +146,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -162,6 +176,9 @@
+
+
+
@@ -198,7 +215,9 @@
-
+
+
+
@@ -251,7 +270,6 @@
-
\ No newline at end of file
diff --git a/checkstyle_suppressions.xml b/checkstyle_suppressions.xml
index fe8dbbf..a87ce46 100644
--- a/checkstyle_suppressions.xml
+++ b/checkstyle_suppressions.xml
@@ -12,4 +12,8 @@
+
+
+
+
diff --git a/pom.xml b/pom.xml
index eaa85cc..0793c04 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0org.htmlunithtmlunit-cssparser
- 3.7.0-SNAPSHOT
+ 5.0.0-SNAPSHOTHtmlUnit CSS ParserHtmlUnit
@@ -17,19 +17,60 @@
UTF-8yyyy-MM-dd HH:mm
- 8
- 8
+ 17
+ 17
+ 17
- 8.4.2
- 9.3
+ (?i).*-(alpha|beta|m|rc)([\.-]?\d+)?
+
+
+ 6.0.2
+ 2.21.0
+
+
+ 12.3.1
+ 10.0.4
+
+
+ 0.10.0
+ 3.6.1
+ 3.6.0
+ 3.2.8
+ 3.6.2
+ 3.14.1
+ 3.5.0
+ 3.3.1
+ 3.4.0
+ 3.12.0
+ 3.5.4
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ ${build-helper-plugin.version}
+
+
+ add-module-source
+ generate-sources
+
+ add-source
+
+
+
+ src/main/module-info
+
+
+
+
+
+
org.apache.maven.pluginsmaven-enforcer-plugin
- 3.4.1
+ ${enforcer-plugin.version}enforce-maven
@@ -42,19 +83,31 @@
3.6.3
- 1.8.0
+ 17
-
+
- org.owasp
- dependency-check-maven
- ${dependencycheck.version}
+ org.sonatype.central
+ central-publishing-maven-plugin
+ ${central-publishing-plugin.version}
+ true
+
+ central
+
+
+
org.apache.maven.pluginsmaven-surefire-plugin
- 3.2.1
+ ${surefire-plugin.version}org.apache.maven.pluginsmaven-compiler-plugin
- 3.11.0
+ ${compiler-plugin.version}
@@ -141,13 +195,17 @@
\s*throw new IllegalStateException \("Missing return statement in function"\);
+
+ ;\s*;
+ ;
+ org.apache.maven.pluginsmaven-checkstyle-plugin
- 3.3.1
+ ${checkstyle-plugin.version}checkstyle.xmlcheckstyle_suppressions.xml
@@ -166,7 +224,7 @@
org.apache.maven.pluginsmaven-jar-plugin
- 3.3.0
+ ${jar-plugin.version}
@@ -184,7 +242,7 @@
org.apache.maven.pluginsmaven-source-plugin
- 3.3.0
+ ${source-plugin.version}
@@ -196,9 +254,13 @@
org.apache.maven.pluginsmaven-javadoc-plugin
- 3.6.0
+ ${javadoc-plugin.version}
- --allow-script-in-comments
+ true
+ protected
+ html,reference,syntax
+ true
+ trueorg.htmlunit.cssparser.parser.javacc
@@ -212,7 +274,7 @@
org.apache.maven.pluginsmaven-gpg-plugin
- 3.1.0
+ ${gpg-plugin.version}verify
@@ -259,48 +321,15 @@
org.apache.maven.pluginsmaven-release-plugin
- 3.0.1
+ ${release-plugin.version}
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 3.6.0
-
- --allow-script-in-comments
-
- http://docs.oracle.com/javase/8/docs/api/
-
- org.htmlunit.cssparser.parser.javacc
-
-
-
- org.apache.maven.plugins
- maven-changes-plugin
- 2.12.1
-
-
-
- changes-report
-
-
-
-
-
- http://sourceforge.net/p/htmlunit/feature-requests/%ISSUE%
-
-
-
-
- Apache License, Version 2.0
- http://www.apache.org/licenses/LICENSE-2.0.txt
+ https://www.apache.org/licenses/LICENSE-2.0.txtrepo
@@ -344,43 +373,30 @@
Paul Selormey
+
+ Ivan Di Francesco
+ org.junit.jupiterjunit-jupiter-engine
- 5.10.0
+ ${junit.version}
+ test
+
+
+ org.junit.platform
+ junit-platform-launcher
+ ${junit.version}testcommons-iocommons-io
- 2.15.0
+ ${commons-io.version}test
-
-
- sonatype-nexus-snapshots
- https://s01.oss.sonatype.org/content/repositories/snapshots
-
-
- sonatype-nexus-staging
- https://s01.oss.sonatype.org/service/local/staging/deploy/maven2
-
-
-
-
-
- true
- always
-
-
- false
-
- OSS Sonatype snapshots
- https://s01.oss.sonatype.org/content/repositories/snapshots/
-
-
+
diff --git a/src/main/java/org/htmlunit/cssparser/dom/AbstractCSSRuleImpl.java b/src/main/java/org/htmlunit/cssparser/dom/AbstractCSSRuleImpl.java
index a19bf13..4435439 100644
--- a/src/main/java/org/htmlunit/cssparser/dom/AbstractCSSRuleImpl.java
+++ b/src/main/java/org/htmlunit/cssparser/dom/AbstractCSSRuleImpl.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,10 @@
import org.htmlunit.cssparser.parser.AbstractLocatable;
/**
+ *
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..23134e8
--- /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 final String function_;
+ private final 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..aa77a78 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 {
@@ -64,13 +63,7 @@ public void setCssText(final String cssText) throws DOMException {
DOMExceptionImpl.EXPECTING_CHARSET_RULE);
}
}
- catch (final CSSException e) {
- throw new DOMExceptionImpl(
- DOMException.SYNTAX_ERR,
- DOMExceptionImpl.SYNTAX_ERROR,
- e.getMessage());
- }
- catch (final IOException e) {
+ catch (final CSSException | IOException e) {
throw new DOMExceptionImpl(
DOMException.SYNTAX_ERR,
DOMExceptionImpl.SYNTAX_ERROR,
@@ -79,25 +72,28 @@ 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) {
return true;
}
- if (!(obj instanceof CSSCharsetRuleImpl)) {
+ if (!(obj instanceof CSSCharsetRuleImpl ccr)) {
return false;
}
- final CSSCharsetRuleImpl ccr = (CSSCharsetRuleImpl) obj;
return super.equals(obj)
&& ParserUtils.equals(getEncoding(), ccr.getEncoding());
}
+ /** {@inheritDoc} */
@Override
public int hashCode() {
int hash = super.hashCode();
@@ -105,14 +101,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..d6ec60d 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 {
@@ -77,13 +75,7 @@ public void setCssText(final String cssText) throws DOMException {
DOMExceptionImpl.EXPECTING_FONT_FACE_RULE);
}
}
- catch (final CSSException e) {
- throw new DOMExceptionImpl(
- DOMException.SYNTAX_ERR,
- DOMExceptionImpl.SYNTAX_ERROR,
- e.getMessage());
- }
- catch (final IOException e) {
+ catch (final CSSException | IOException e) {
throw new DOMExceptionImpl(
DOMException.SYNTAX_ERR,
DOMExceptionImpl.SYNTAX_ERROR,
@@ -92,6 +84,8 @@ public void setCssText(final String cssText) throws DOMException {
}
/**
+ *
getStyle.
+ *
* @return the style
*/
public CSSStyleDeclarationImpl getStyle() {
@@ -100,25 +94,27 @@ 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) {
return true;
}
- if (!(obj instanceof CSSFontFaceRuleImpl)) {
+ if (!(obj instanceof CSSFontFaceRuleImpl cffr)) {
return false;
}
- final CSSFontFaceRuleImpl cffr = (CSSFontFaceRuleImpl) obj;
return super.equals(obj)
&& ParserUtils.equals(getStyle(), cffr.getStyle());
}
+ /** {@inheritDoc} */
@Override
public int hashCode() {
int hash = super.hashCode();
@@ -126,6 +122,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..2fe35a6 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 {
@@ -90,13 +87,7 @@ public void setCssText(final String cssText) throws DOMException {
DOMExceptionImpl.EXPECTING_IMPORT_RULE);
}
}
- catch (final CSSException e) {
- throw new DOMExceptionImpl(
- DOMException.SYNTAX_ERR,
- DOMExceptionImpl.SYNTAX_ERROR,
- e.getMessage());
- }
- catch (final IOException e) {
+ catch (final CSSException | IOException e) {
throw new DOMExceptionImpl(
DOMException.SYNTAX_ERR,
DOMExceptionImpl.SYNTAX_ERROR,
@@ -105,6 +96,8 @@ public void setCssText(final String cssText) throws DOMException {
}
/**
+ *
getHref.
+ *
* @return the href
*/
public String getHref() {
@@ -112,6 +105,8 @@ public String getHref() {
}
/**
+ *
getMedia.
+ *
* @return the media lsit
*/
public MediaListImpl getMedia() {
@@ -119,31 +114,35 @@ 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) {
return true;
}
- if (!(obj instanceof CSSImportRuleImpl)) {
+ if (!(obj instanceof CSSImportRuleImpl cir)) {
return false;
}
- final CSSImportRuleImpl cir = (CSSImportRuleImpl) obj;
return super.equals(obj)
&& ParserUtils.equals(getHref(), cir.getHref())
&& 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..6a13a84 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 {
@@ -85,13 +83,7 @@ public void setCssText(final String cssText) throws DOMException {
DOMExceptionImpl.EXPECTING_MEDIA_RULE);
}
}
- catch (final CSSException e) {
- throw new DOMExceptionImpl(
- DOMException.SYNTAX_ERR,
- DOMExceptionImpl.SYNTAX_ERROR,
- e.getMessage());
- }
- catch (final IOException e) {
+ catch (final CSSException | IOException e) {
throw new DOMExceptionImpl(
DOMException.SYNTAX_ERR,
DOMExceptionImpl.SYNTAX_ERROR,
@@ -100,6 +92,8 @@ public void setCssText(final String cssText) throws DOMException {
}
/**
+ *
getMediaList.
+ *
* @return the media list
*/
public MediaListImpl getMediaList() {
@@ -107,6 +101,8 @@ public MediaListImpl getMediaList() {
}
/**
+ *
getCssRules.
+ *
* @return the css rules
*/
public CSSRuleListImpl getCssRules() {
@@ -118,6 +114,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
@@ -142,13 +139,7 @@ public void insertRule(final String rule, final int index) throws DOMException {
DOMExceptionImpl.INDEX_OUT_OF_BOUNDS,
e.getMessage());
}
- catch (final CSSException e) {
- throw new DOMExceptionImpl(
- DOMException.SYNTAX_ERR,
- DOMExceptionImpl.SYNTAX_ERROR,
- e.getMessage());
- }
- catch (final IOException e) {
+ catch (final CSSException | IOException e) {
throw new DOMExceptionImpl(
DOMException.SYNTAX_ERR,
DOMExceptionImpl.SYNTAX_ERROR,
@@ -181,20 +172,21 @@ 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) {
return true;
}
- if (!(obj instanceof CSSMediaRuleImpl)) {
+ if (!(obj instanceof CSSMediaRuleImpl cmr)) {
return false;
}
- final CSSMediaRuleImpl cmr = (CSSMediaRuleImpl) obj;
return super.equals(obj)
&& ParserUtils.equals(getMediaList(), cmr.getMediaList())
&& ParserUtils.equals(getCssRules(), cmr.getCssRules());
diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSPageRuleImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSPageRuleImpl.java
index ab835f4..19a91af 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,
@@ -94,13 +94,7 @@ public void setCssText(final String cssText) throws DOMException {
DOMExceptionImpl.EXPECTING_PAGE_RULE);
}
}
- catch (final CSSException e) {
- throw new DOMExceptionImpl(
- DOMException.SYNTAX_ERR,
- DOMExceptionImpl.SYNTAX_ERROR,
- e.getMessage());
- }
- catch (final IOException e) {
+ catch (final CSSException | IOException e) {
throw new DOMExceptionImpl(
DOMException.SYNTAX_ERR,
DOMExceptionImpl.SYNTAX_ERROR,
@@ -109,7 +103,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_) {
@@ -138,13 +134,7 @@ public void setSelectorText(final String selectorText) throws DOMException {
DOMExceptionImpl.EXPECTING_PAGE_RULE);
}
}
- catch (final CSSException e) {
- throw new DOMExceptionImpl(
- DOMException.SYNTAX_ERR,
- DOMExceptionImpl.SYNTAX_ERROR,
- e.getMessage());
- }
- catch (final IOException e) {
+ catch (final CSSException | IOException e) {
throw new DOMExceptionImpl(
DOMException.SYNTAX_ERR,
DOMExceptionImpl.SYNTAX_ERROR,
@@ -172,10 +162,9 @@ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof CSSPageRuleImpl)) {
+ if (!(obj instanceof CSSPageRuleImpl cpr)) {
return false;
}
- final CSSPageRuleImpl cpr = (CSSPageRuleImpl) obj;
return super.equals(obj)
&& ParserUtils.equals(getSelectorText(), cpr.getSelectorText())
&& ParserUtils.equals(getStyle(), cpr.getStyle());
diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSRuleListImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSRuleListImpl.java
index 90459b9..4e4101c 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 List rules_ = new ArrayList<>();
/**
+ *
getRules.
+ *
* @return the rules
*/
public List getRules() {
@@ -44,6 +46,8 @@ public CSSRuleListImpl() {
}
/**
+ *
getLength.
+ *
* @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,15 +92,15 @@ public String toString() {
return sb.toString();
}
+ /** {@inheritDoc} */
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof CSSRuleListImpl)) {
+ if (!(obj instanceof CSSRuleListImpl crl)) {
return false;
}
- final CSSRuleListImpl crl = (CSSRuleListImpl) obj;
return equalsRules(crl);
}
diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSStyleDeclarationImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSStyleDeclarationImpl.java
index 1b0558c..1252363 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 List getProperties() {
@@ -113,6 +115,8 @@ public String getPropertyValue(final String propertyName) {
}
/**
+ *
getPropertyCSSValue.
+ *
* @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
*/
@@ -245,10 +257,9 @@ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof CSSStyleDeclarationImpl)) {
+ if (!(obj instanceof CSSStyleDeclarationImpl csd)) {
return false;
}
- final CSSStyleDeclarationImpl csd = (CSSStyleDeclarationImpl) obj;
// don't use parentRule in equals()
// recursive loop -> stack overflow!
diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSStyleRuleImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSStyleRuleImpl.java
index 6ca0473..c144e66 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,
@@ -99,13 +99,7 @@ public void setCssText(final String cssText) throws DOMException {
DOMExceptionImpl.EXPECTING_STYLE_RULE);
}
}
- catch (final CSSException e) {
- throw new DOMExceptionImpl(
- DOMException.SYNTAX_ERR,
- DOMExceptionImpl.SYNTAX_ERROR,
- e.getMessage());
- }
- catch (final IOException e) {
+ catch (final CSSException | IOException e) {
throw new DOMExceptionImpl(
DOMException.SYNTAX_ERR,
DOMExceptionImpl.SYNTAX_ERROR,
@@ -130,13 +124,7 @@ public void setSelectorText(final String selectorText) throws DOMException {
final CSSOMParser parser = new CSSOMParser();
selectors_ = parser.parseSelectors(selectorText);
}
- catch (final CSSException e) {
- throw new DOMExceptionImpl(
- DOMException.SYNTAX_ERR,
- DOMExceptionImpl.SYNTAX_ERROR,
- e.getMessage());
- }
- catch (final IOException e) {
+ catch (final CSSException | IOException e) {
throw new DOMExceptionImpl(
DOMException.SYNTAX_ERR,
DOMExceptionImpl.SYNTAX_ERROR,
@@ -169,10 +157,9 @@ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof CSSStyleRuleImpl)) {
+ if (!(obj instanceof CSSStyleRuleImpl csr)) {
return false;
}
- final CSSStyleRuleImpl csr = (CSSStyleRuleImpl) obj;
return super.equals(obj)
&& ParserUtils.equals(getSelectorText(), csr.getSelectorText())
&& ParserUtils.equals(getStyle(), csr.getStyle());
diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSStyleSheetImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSStyleSheetImpl.java
index c5855dd..1235d36 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() {
}
/**
+ *
+ *
* @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..6a612a1 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,
@@ -15,7 +15,6 @@
package org.htmlunit.cssparser.dom;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.htmlunit.cssparser.util.ParserUtils;
@@ -29,6 +28,8 @@ public class CSSStyleSheetListImpl {
private List cssStyleSheets_;
/**
+ *
getCSSStyleSheets.
+ *
* @return the list of style sheets
*/
public List getCSSStyleSheets() {
@@ -39,6 +40,8 @@ public List getCSSStyleSheets() {
}
/**
+ *
getLength.
+ *
* @return the number of style sheets
*/
public int getLength() {
@@ -63,9 +66,7 @@ public void add(final CSSStyleSheetImpl cssStyleSheet) {
public CSSStyleSheetImpl merge() {
final CSSStyleSheetImpl merged = new CSSStyleSheetImpl();
final CSSRuleListImpl cssRuleList = new CSSRuleListImpl();
- final Iterator it = getCSSStyleSheets().iterator();
- while (it.hasNext()) {
- final CSSStyleSheetImpl cssStyleSheet = it.next();
+ for (final CSSStyleSheetImpl cssStyleSheet : getCSSStyleSheets()) {
final CSSMediaRuleImpl cssMediaRule = new CSSMediaRuleImpl(merged, null, cssStyleSheet.getMedia());
cssMediaRule.setRuleList(cssStyleSheet.getCssRules());
cssRuleList.add(cssMediaRule);
@@ -75,15 +76,15 @@ public CSSStyleSheetImpl merge() {
return merged;
}
+ /** {@inheritDoc} */
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof CSSStyleSheetListImpl)) {
+ if (!(obj instanceof CSSStyleSheetListImpl ssl)) {
return false;
}
- final CSSStyleSheetListImpl ssl = (CSSStyleSheetListImpl) obj;
return equalsStyleSheets(ssl);
}
diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSUnknownRuleImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSUnknownRuleImpl.java
index a9c49df..be965dc 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 {
@@ -74,13 +70,7 @@ public void setCssText(final String cssText) throws DOMException {
DOMExceptionImpl.EXPECTING_FONT_FACE_RULE);
}
}
- catch (final CSSException e) {
- throw new DOMExceptionImpl(
- DOMException.SYNTAX_ERR,
- DOMExceptionImpl.SYNTAX_ERROR,
- e.getMessage());
- }
- catch (final IOException e) {
+ catch (final CSSException | IOException e) {
throw new DOMExceptionImpl(
DOMException.SYNTAX_ERR,
DOMExceptionImpl.SYNTAX_ERROR,
@@ -88,20 +78,21 @@ 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) {
return true;
}
- if (!(obj instanceof CSSUnknownRuleImpl)) {
+ if (!(obj instanceof CSSUnknownRuleImpl cur)) {
return false;
}
- final CSSUnknownRuleImpl cur = (CSSUnknownRuleImpl) obj;
return super.equals(obj)
&& ParserUtils.equals(getCssText(), cur.getCssText());
}
diff --git a/src/main/java/org/htmlunit/cssparser/dom/CSSValueImpl.java b/src/main/java/org/htmlunit/cssparser/dom/CSSValueImpl.java
index d5d80d6..8e35074 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;
/**
@@ -85,6 +85,42 @@ public enum CSSPrimitiveValueType {
/** CSS_VMAX. */
CSS_VMAX,
+ /** CSS_DVW. */
+ CSS_DVW,
+
+ /** CSS_DVH. */
+ CSS_DVH,
+
+ /** CSS_DVMIN. */
+ CSS_DVMIN,
+
+ /** CSS_DVMAX. */
+ CSS_DVMAX,
+
+ /** CSS_LVW. */
+ CSS_LVW,
+
+ /** CSS_LVH. */
+ CSS_LVH,
+
+ /** CSS_LVMIN. */
+ CSS_LVMIN,
+
+ /** CSS_LVMAX. */
+ CSS_LVMAX,
+
+ /** CSS_SVW. */
+ CSS_SVW,
+
+ /** CSS_SVH. */
+ CSS_SVH,
+
+ /** CSS_SVMIN. */
+ CSS_SVMIN,
+
+ /** CSS_SVMAX. */
+ CSS_SVMAX,
+
/** CSS_PX. */
CSS_PX,
@@ -164,6 +200,8 @@ public enum CSSPrimitiveValueType {
private Object value_;
/**
+ *
getValue.
+ *
* @return the value
*/
public Object getValue() {
@@ -197,6 +235,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 +288,8 @@ public CSSValueImpl(final LexicalUnit value) {
}
/**
+ *
getCssText.
+ *
* @return the css text
*/
public String getCssText() {
@@ -255,8 +307,7 @@ public String getCssText() {
final CSSValueImpl cssValue = (CSSValueImpl) o;
if (separate) {
- if (cssValue.value_ instanceof LexicalUnit) {
- final LexicalUnit lu = (LexicalUnit) cssValue.value_;
+ if (cssValue.value_ instanceof LexicalUnit lu) {
if (lu.getLexicalUnitType() != LexicalUnitType.OPERATOR_COMMA) {
sb.append(" ");
}
@@ -294,6 +345,8 @@ public void setCssText(final String cssText) throws DOMException {
}
/**
+ *
getCssValueType.
+ *
* @return the css value type
*/
public CSSValueType getCssValueType() {
@@ -308,89 +361,64 @@ public CSSValueType getCssValueType() {
}
/**
+ *
getPrimitiveType.
+ *
* @return the primitive type
*/
public CSSPrimitiveValueType getPrimitiveType() {
- if (value_ instanceof LexicalUnit) {
- final LexicalUnit lu = (LexicalUnit) value_;
- switch (lu.getLexicalUnitType()) {
- case INHERIT:
- return CSSPrimitiveValueType.CSS_IDENT;
- case INTEGER:
- case REAL:
- return CSSPrimitiveValueType.CSS_NUMBER;
- case EM:
- return CSSPrimitiveValueType.CSS_EMS;
- case REM:
- return CSSPrimitiveValueType.CSS_REM;
- case EX:
- return CSSPrimitiveValueType.CSS_EXS;
- case CH:
- return CSSPrimitiveValueType.CSS_CH;
- case VW:
- return CSSPrimitiveValueType.CSS_VW;
- case VH:
- return CSSPrimitiveValueType.CSS_VH;
- case VMIN:
- return CSSPrimitiveValueType.CSS_VMIN;
- case VMAX:
- return CSSPrimitiveValueType.CSS_VMAX;
- case PIXEL:
- return CSSPrimitiveValueType.CSS_PX;
- case INCH:
- return CSSPrimitiveValueType.CSS_IN;
- case CENTIMETER:
- return CSSPrimitiveValueType.CSS_CM;
- case MILLIMETER:
- return CSSPrimitiveValueType.CSS_MM;
- case POINT:
- return CSSPrimitiveValueType.CSS_PT;
- case PICA:
- return CSSPrimitiveValueType.CSS_PC;
- case QUATER:
- return CSSPrimitiveValueType.CSS_Q;
- case PERCENTAGE:
- return CSSPrimitiveValueType.CSS_PERCENTAGE;
- case URI:
- return CSSPrimitiveValueType.CSS_URI;
- case COUNTER_FUNCTION:
- // case COUNTERS_FUNCTION:
- return CSSPrimitiveValueType.CSS_COUNTER;
- // case RGBCOLOR:
- // return CSS_RGBCOLOR;
- case DEGREE:
- return CSSPrimitiveValueType.CSS_DEG;
- case GRADIAN:
- return CSSPrimitiveValueType.CSS_GRAD;
- case RADIAN:
- return CSSPrimitiveValueType.CSS_RAD;
- case TURN:
- return CSSPrimitiveValueType.CSS_TURN;
- case MILLISECOND:
- return CSSPrimitiveValueType.CSS_MS;
- case SECOND:
- return CSSPrimitiveValueType.CSS_S;
- case HERTZ:
- return CSSPrimitiveValueType.CSS_HZ;
- case KILOHERTZ:
- return CSSPrimitiveValueType.CSS_KHZ;
- case IDENT:
- return CSSPrimitiveValueType.CSS_IDENT;
- case STRING_VALUE:
- return CSSPrimitiveValueType.CSS_STRING;
- case ATTR:
- return CSSPrimitiveValueType.CSS_ATTR;
- // case RECT_FUNCTION:
- // return CSSPrimitiveValueType.CSS_RECT;
- case UNICODERANGE:
- case FUNCTION:
- case FUNCTION_CALC:
- return CSSPrimitiveValueType.CSS_STRING;
- case DIMENSION:
- return CSSPrimitiveValueType.CSS_DIMENSION;
- default:
- return CSSPrimitiveValueType.CSS_UNKNOWN;
- }
+ if (value_ instanceof LexicalUnit lu) {
+ return switch (lu.getLexicalUnitType()) {
+ case INHERIT -> CSSPrimitiveValueType.CSS_IDENT;
+ case INTEGER, REAL -> CSSPrimitiveValueType.CSS_NUMBER;
+ case EM -> CSSPrimitiveValueType.CSS_EMS;
+ case REM -> CSSPrimitiveValueType.CSS_REM;
+ case EX -> CSSPrimitiveValueType.CSS_EXS;
+ case CH -> CSSPrimitiveValueType.CSS_CH;
+ case VW -> CSSPrimitiveValueType.CSS_VW;
+ case VH -> CSSPrimitiveValueType.CSS_VH;
+ case VMIN -> CSSPrimitiveValueType.CSS_VMIN;
+ case VMAX -> CSSPrimitiveValueType.CSS_VMAX;
+ case DVW -> CSSPrimitiveValueType.CSS_DVW;
+ case DVH -> CSSPrimitiveValueType.CSS_DVH;
+ case DVMIN -> CSSPrimitiveValueType.CSS_DVMIN;
+ case DVMAX -> CSSPrimitiveValueType.CSS_DVMAX;
+ case LVW -> CSSPrimitiveValueType.CSS_LVW;
+ case LVH -> CSSPrimitiveValueType.CSS_LVH;
+ case LVMIN -> CSSPrimitiveValueType.CSS_LVMIN;
+ case LVMAX -> CSSPrimitiveValueType.CSS_LVMAX;
+ case SVW -> CSSPrimitiveValueType.CSS_SVW;
+ case SVH -> CSSPrimitiveValueType.CSS_SVH;
+ case SVMIN -> CSSPrimitiveValueType.CSS_SVMIN;
+ case SVMAX -> CSSPrimitiveValueType.CSS_SVMAX;
+ case PIXEL -> CSSPrimitiveValueType.CSS_PX;
+ case INCH -> CSSPrimitiveValueType.CSS_IN;
+ case CENTIMETER -> CSSPrimitiveValueType.CSS_CM;
+ case MILLIMETER -> CSSPrimitiveValueType.CSS_MM;
+ case POINT -> CSSPrimitiveValueType.CSS_PT;
+ case PICA -> CSSPrimitiveValueType.CSS_PC;
+ case QUATER -> CSSPrimitiveValueType.CSS_Q;
+ case PERCENTAGE -> CSSPrimitiveValueType.CSS_PERCENTAGE;
+ case URI -> CSSPrimitiveValueType.CSS_URI;
+ case COUNTER_FUNCTION -> CSSPrimitiveValueType.CSS_COUNTER;
+ // case COUNTERS_FUNCTION
+ // case RGBCOLOR -> CSS_RGBCOLOR;
+ case DEGREE -> CSSPrimitiveValueType.CSS_DEG;
+ case GRADIAN -> CSSPrimitiveValueType.CSS_GRAD;
+ case RADIAN -> CSSPrimitiveValueType.CSS_RAD;
+ case TURN -> CSSPrimitiveValueType.CSS_TURN;
+ case MILLISECOND -> CSSPrimitiveValueType.CSS_MS;
+ case SECOND -> CSSPrimitiveValueType.CSS_S;
+ case HERTZ -> CSSPrimitiveValueType.CSS_HZ;
+ case KILOHERTZ -> CSSPrimitiveValueType.CSS_KHZ;
+ case IDENT -> CSSPrimitiveValueType.CSS_IDENT;
+ case NONE -> CSSPrimitiveValueType.CSS_IDENT;
+ case STRING_VALUE -> CSSPrimitiveValueType.CSS_STRING;
+ case ATTR -> CSSPrimitiveValueType.CSS_ATTR;
+ // case RECT_FUNCTION-> CSSPrimitiveValueType.CSS_RECT;
+ case UNICODERANGE, FUNCTION, FUNCTION_CALC -> CSSPrimitiveValueType.CSS_STRING;
+ case DIMENSION -> CSSPrimitiveValueType.CSS_DIMENSION;
+ default -> CSSPrimitiveValueType.CSS_UNKNOWN;
+ };
}
else if (value_ instanceof RectImpl) {
return CSSPrimitiveValueType.CSS_RECT;
@@ -405,6 +433,8 @@ else if (value_ instanceof CounterImpl) {
}
/**
+ *
getLexicalUnitType.
+ *
* @return the lexical unit type
*/
public LexicalUnit.LexicalUnitType getLexicalUnitType() {
@@ -425,13 +455,13 @@ 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 {
- if (value_ instanceof LexicalUnit) {
- final LexicalUnit lu = (LexicalUnit) value_;
+ if (value_ instanceof LexicalUnit lu) {
return lu.getDoubleValue();
}
throw new DOMExceptionImpl(
@@ -443,20 +473,28 @@ public double getDoubleValue() throws DOMException {
}
/**
+ *
getStringValue.
+ *
* @return the string value.
* @throws DOMException case of error
*/
public String getStringValue() throws DOMException {
- if (value_ instanceof LexicalUnit) {
- final LexicalUnit lu = (LexicalUnit) value_;
+ if (value_ instanceof LexicalUnit lu) {
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 +523,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,20 +537,21 @@ 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) {
return true;
}
- if (!(obj instanceof CSSValueImpl)) {
+ if (!(obj instanceof CSSValueImpl cv)) {
return false;
}
- final CSSValueImpl cv = (CSSValueImpl) obj;
// TODO to be improved!
return super.equals(obj)
&& (getCssValueType() == cv.getCssValueType())
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..b6986ac 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,18 +152,19 @@ private boolean equalsMedia(final MediaListImpl ml) {
return true;
}
+ /** {@inheritDoc} */
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof MediaListImpl)) {
+ if (!(obj instanceof MediaListImpl ml)) {
return false;
}
- final MediaListImpl ml = (MediaListImpl) 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..7d82f95 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,18 +105,15 @@ public String toString() {
return sb.toString();
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
- if (!(obj instanceof Property)) {
+ if (!(obj instanceof Property p)) {
return false;
}
- final Property p = (Property) obj;
return super.equals(obj)
&& (important_ == p.important_)
&& ParserUtils.equals(name_, p.name_)
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 5d21e65..4950dda 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,
@@ -39,60 +39,63 @@ public abstract class AbstractCSSParser {
private CSSErrorHandler errorHandler_;
private InputSource source_;
- private static final HashMap parserMessages_ = new HashMap<>();
+ private static final HashMap PARSER_MESSAGES_ = new HashMap<>();
static {
- parserMessages_.put("invalidExpectingOne", "Invalid token \"{0}\". Was expecting: {1}.");
- parserMessages_.put("invalidExpectingMore", "Invalid token \"{0}\". Was expecting one of: {1}.");
- parserMessages_.put("invalidColor", "Invalid color \"{0}\".");
- parserMessages_.put("invalidStyleSheet", "Error in style sheet.");
- parserMessages_.put("invalidRule", "Error in rule.");
- parserMessages_.put("invalidUnknownRule", "Error in unknown at-rule.");
- parserMessages_.put("invalidCharsetRule", "Error in @charset rule.");
- parserMessages_.put("misplacedCharsetRule", "The @charset must be the first element in the style sheet.");
- parserMessages_.put("invalidImportRule", "Error in @import rule.");
- parserMessages_.put("invalidImportRuleIgnored", "@import rule must occur before all other rules.");
- parserMessages_.put("invalidImportRuleIgnored2",
+ PARSER_MESSAGES_.put("invalidExpectingOne", "Invalid token \"{0}\". Was expecting: {1}.");
+ PARSER_MESSAGES_.put("invalidExpectingMore", "Invalid token \"{0}\". Was expecting one of: {1}.");
+ PARSER_MESSAGES_.put("invalidColor", "Invalid color \"{0}\".");
+ PARSER_MESSAGES_.put("invalidStyleSheet", "Error in style sheet.");
+ PARSER_MESSAGES_.put("invalidRule", "Error in rule.");
+ PARSER_MESSAGES_.put("invalidUnknownRule", "Error in unknown at-rule.");
+ PARSER_MESSAGES_.put("invalidCharsetRule", "Error in @charset rule.");
+ PARSER_MESSAGES_.put("misplacedCharsetRule", "The @charset must be the first element in the style sheet.");
+ PARSER_MESSAGES_.put("invalidImportRule", "Error in @import rule.");
+ PARSER_MESSAGES_.put("invalidImportRuleIgnored", "@import rule must occur before all other rules.");
+ PARSER_MESSAGES_.put("invalidImportRuleIgnored2",
"@import rule must occur before all other rules, except the @charset rule.");
- parserMessages_.put("invalidPageRule", "Error in @page rule.");
- parserMessages_.put("invalidFontFaceRule", "Error in @font-face rule.");
- parserMessages_.put("invalidMediaList", "Error in media list.");
- parserMessages_.put("invalidMediaRule", "Error in @media rule.");
- parserMessages_.put("invalidStyleRule", "Error in style rule.");
- parserMessages_.put("invalidStyleDeclaration", "Error in style declaration.");
- parserMessages_.put("invalidDeclaration", "Error in declaration.");
- parserMessages_.put("invalidDeclarationInvalidChar", "Error in declaration; invalid character \"{0}\" found.");
- parserMessages_.put("invalidDeclarationStarHack",
+ PARSER_MESSAGES_.put("invalidPageRule", "Error in @page rule.");
+ PARSER_MESSAGES_.put("invalidFontFaceRule", "Error in @font-face rule.");
+ PARSER_MESSAGES_.put("invalidMediaList", "Error in media list.");
+ PARSER_MESSAGES_.put("invalidMediaRule", "Error in @media rule.");
+ PARSER_MESSAGES_.put("invalidStyleRule", "Error in style rule.");
+ PARSER_MESSAGES_.put("invalidStyleDeclaration", "Error in style declaration.");
+ PARSER_MESSAGES_.put("invalidDeclaration", "Error in declaration.");
+ PARSER_MESSAGES_.put("invalidDeclarationInvalidChar", "Error in declaration; invalid character \"{0}\" found.");
+ PARSER_MESSAGES_.put("invalidDeclarationStarHack",
"Error in declaration. ''*'' is not allowed as first char of a property.");
- parserMessages_.put("invalidSelectorList", "Error in selector list.");
- parserMessages_.put("invalidSelector", "Error in selector.");
- parserMessages_.put("invalidSimpleSelector", "Error in simple selector.");
- parserMessages_.put("invalidClassSelector", "Error in class selector.");
- parserMessages_.put("invalidElementName", "Error in element name.");
- parserMessages_.put("invalidAttrib", "Error in attribute selector.");
- parserMessages_.put("invalidPseudo", "Error in pseudo class or element.");
- parserMessages_.put("duplicatePseudo", "Duplicate pseudo class \":{0}\" or pseudo class \":{0}\" not at end.");
- parserMessages_.put("invalidHash", "Error in hash.");
- parserMessages_.put("invalidExpr", "Error in expression.");
- parserMessages_.put("invalidExprColon", "Error in expression; '':'' found after identifier \"{0}\".");
- parserMessages_.put("invalidPrio", "Error in priority.");
-
- parserMessages_.put("invalidPagePseudoClass",
+ PARSER_MESSAGES_.put("invalidSelectorList", "Error in selector list.");
+ PARSER_MESSAGES_.put("invalidSelector", "Error in selector.");
+ PARSER_MESSAGES_.put("invalidSimpleSelector", "Error in simple selector.");
+ PARSER_MESSAGES_.put("invalidClassSelector", "Error in class selector.");
+ PARSER_MESSAGES_.put("invalidElementName", "Error in element name.");
+ PARSER_MESSAGES_.put("invalidAttrib", "Error in attribute selector.");
+ PARSER_MESSAGES_.put("invalidPseudo", "Error in pseudo class or element.");
+ PARSER_MESSAGES_.put("invalidPseudoColon", "\":{0}\" is not a valid selector.");
+ PARSER_MESSAGES_.put("duplicatePseudo", "Duplicate pseudo class \":{0}\" or pseudo class \":{0}\" not at end.");
+ PARSER_MESSAGES_.put("invalidHash", "Error in hash.");
+ PARSER_MESSAGES_.put("invalidExpr", "Error in expression.");
+ PARSER_MESSAGES_.put("invalidExprColon", "Error in expression; '':'' found after identifier \"{0}\".");
+ PARSER_MESSAGES_.put("invalidPrio", "Error in priority.");
+
+ PARSER_MESSAGES_.put("invalidPagePseudoClass",
"Invalid page pseudo class \"{0}\"; valid values are \"blank\", \"first\", \"left\", and \"right\".");
- parserMessages_.put("invalidCaseInSensitivelyIdentifier",
+ PARSER_MESSAGES_.put("invalidCaseInSensitivelyIdentifier",
"Invalid case-insensitively identifier \"{0}\" found; valid values are \"i\", and \"s\".");
- parserMessages_.put("ignoringRule", "Ignoring the whole rule.");
- parserMessages_.put("ignoringFollowingDeclarations", "Ignoring the following declarations in this rule.");
+ PARSER_MESSAGES_.put("ignoringRule", "Ignoring the whole rule.");
+ PARSER_MESSAGES_.put("ignoringFollowingDeclarations", "Ignoring the following declarations in this rule.");
- parserMessages_.put("tokenMgrError", "Lexical error.");
- parserMessages_.put("domException", "DOM exception: ''{0}''");
+ PARSER_MESSAGES_.put("tokenMgrError", "Lexical error.");
+ PARSER_MESSAGES_.put("domException", "DOM exception: ''{0}''");
}
private static final String NUM_CHARS = "0123456789.";
/**
+ *
If the application does not register a document handler, all
* document events reported by the CSS parser will be silently
- * ignored (this is the default behaviour implemented by
+ * ignored (this is the default behavior implemented by
* HandlerBase).
*
*
Applications may register a new or different handler in the
@@ -122,6 +125,8 @@ public void setDocumentHandler(final DocumentHandler handler) {
}
/**
+ *
If the application does not register an error event handler,
* all error events reported by the CSS parser will be silently
* ignored, except for fatalError, which will throw a CSSException
- * (this is the default behaviour implemented by HandlerBase).
+ * (this is the default behavior implemented by HandlerBase).
*
*
Applications may register a new or different handler in the
* middle of a parse, and the CSS parser must begin using the new
@@ -152,6 +157,8 @@ public void setErrorHandler(final CSSErrorHandler handler) {
}
/**
+ *
*
* @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,6 +302,8 @@ protected CSSParseException toCSSParseException(final DOMException e) {
}
/**
+ *
toCSSParseException.
+ *
* @param e the TokenMgrException
* @return a new CSSParseException
*/
@@ -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.
*
@@ -884,7 +911,7 @@ protected int intValue(final char op, final String s) {
}
/**
- * Parses the sting into an double.
+ * Parses the sting into a double.
*
* @param op the sign char
* @param s the string to parse
@@ -917,7 +944,7 @@ protected int getLastNumPos(final String s) {
/**
* Unescapes escaped characters in the specified string, according to the
* CSS specification.
- *
+ *
* This could be done directly in the parser, but portions of the lexer would have to be moved
* to the parser, meaning that the grammar would no longer match the standard grammar specified
* by the W3C. This would make the parser and lexer much less maintainable.
@@ -1048,49 +1075,25 @@ public String unescape(final String s, final boolean unescapeDoubleQuotes) {
}
private static int hexval(final char c) {
- switch (c) {
- case '0' :
- return 0;
- case '1' :
- return 1;
- case '2' :
- return 2;
- case '3' :
- return 3;
- case '4' :
- return 4;
- case '5' :
- return 5;
- case '6' :
- return 6;
- case '7' :
- return 7;
- case '8' :
- return 8;
- case '9' :
- return 9;
-
- case 'a' :
- case 'A' :
- return 10;
- case 'b' :
- case 'B' :
- return 11;
- case 'c' :
- case 'C' :
- return 12;
- case 'd' :
- case 'D' :
- return 13;
- case 'e' :
- case 'E' :
- return 14;
- case 'f' :
- case 'F' :
- return 15;
- default :
- return -1;
- }
+ return switch (c) {
+ case '0' -> 0;
+ case '1' -> 1;
+ case '2' -> 2;
+ case '3' -> 3;
+ case '4' -> 4;
+ case '5' -> 5;
+ case '6' -> 6;
+ case '7' -> 7;
+ case '8' -> 8;
+ case '9' -> 9;
+ case 'a', 'A' -> 10;
+ case 'b', 'B' -> 11;
+ case 'c', 'C' -> 12;
+ case 'd', 'D' -> 13;
+ case 'e', 'E' -> 14;
+ case 'f', 'F' -> 15;
+ default -> -1;
+ };
}
protected String normalizeAndValidatePagePseudoClass(final Token t) {
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