Apache Commons Text

repository·master·Indexed 18 days ago

https://github.com/apache/commons-text

A Java library providing a collection of utilities for text manipulation and processing. It includes features such as ConstantStringLookup for resolving static final fields and support for SBOM and VEX documents for dependency risk management.

Tokens
1.2K
Snippets
5
Records
6
Agent score
64%

What's inside Apache Commons Text

  1. Understand VEX (Vulnerability Exploitability eXchange) for Apache Commons Text

    master

    Apache Commons Text publishes an experimental VEX document to provide information regarding the exploitability of known vulnerabilities within its dependencies.

    Exploitability Criteria

    Because Apache Commons Text does not bundle its dependencies, a vulnerability in a dependency is only considered exploitable if:

    1. The vulnerable dependency is included in your consuming project.
    2. Apache Commons Text is explicitly listed as affected by the vulnerability.

    Important Limitations

    • Experimental Status: The VEX document is provided as-is and its semantics may change.
    • Absence of Data: The absence of a vulnerability entry does not guarantee that Text is unaffected.
    • Version Coverage: Only the latest major version of Text is currently assessed. If a version is not listed under the affects section, it may still be affected.
    • Formatting: The analysis field within the VEX file uses Markdown formatting.
    https://raw.githubusercontent.com/apache/commons-text/refs/heads/master/src/conf/security/VEX.cyclonedx.xml
  2. Install Apache Commons Text via Maven

    master

    To use Apache Commons Text in your Java project, add the following dependency to your pom.xml file. Ensure you use the version compatible with your project requirements (the current version shown is 1.15.0).

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-text</artifactId>
      <version>1.15.0</version>
    </dependency>
  3. Build Apache Commons Text from source

    master

    To build the project from source, you need a Java JDK and Apache Maven installed. The required Java version is specified in the pom.xml under the maven.compiler.source property.

    To run the default Maven goal, which executes all tests and checks, run the following command from a command shell:

    mvn
  4. Access SBOM (Software Bill of Materials) for Apache Commons Text

    master

    Starting from version 6.6.0, Apache Commons Text publishes SBOMs in both XML and JSON formats to Maven Central. These documents allow consumers to analyze the software supply chain and manage dependency risk by describing all components and dependencies used in the library.

    To locate the SBOM in a Maven repository, use the following coordinates:

    • Group ID: org.apache.commons
    • Artifact ID: commons-text
    • Classifier: cyclonedx
    • Type: xml or json

    Note: The dependency versions listed in the SBOM reflect those used during the build and test process for that specific release. Your own project may use different versions based on your dependency management configuration.

    Group ID: org.apache.commons
    Artifact ID: commons-text
    Classifier: cyclonedx
    Type: xml or json
  5. Use ConstantStringLookup to resolve static final fields

    master

    The ConstantStringLookup allows you to resolve the value of a static final member field of a class using its fully-qualified name. This is useful for injecting Java constants into configuration files or text templates.

    Key Requirements

    • The target field must be static and final.
    • The input key must follow the format: apackage.AClass.AFIELD.
    • The field must be accessible (public).

    Usage via StringLookupFactory

    You can access this lookup through the StringLookupFactory singleton:

    StringLookupFactory.INSTANCE.constantStringLookup().lookup("java.awt.event.KeyEvent.VK_ESCAPE");

    Usage via StringSubstitutor

    You can use it within a StringSubstitutor (specifically an interpolator) by using the const prefix in your substitution expressions:

    StringSubstitutor.createInterpolator().replace("... ${const:java.awt.event.KeyEvent.VK_ESCAPE} ...");

    In the examples above, the key java.awt.event.KeyEvent.VK_ESCAPE is resolved to its string representation, such as "27".

    // Using StringLookupFactory
    StringLookupFactory.INSTANCE.constantStringLookup().lookup("java.awt.event.KeyEvent.VK_ESCAPE");
    
    // Using StringSubstitutor
    StringSubstitutor.createInterpolator().replace("... ${const:java.awt.event.KeyEvent.VK_ESCAPE} ...");