001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package gov.nist.secauto.oscal.lib.profile.resolver.policy; 007 008import gov.nist.secauto.oscal.lib.profile.resolver.ProfileResolutionEvaluationException; 009 010import edu.umd.cs.findbugs.annotations.NonNull; 011import edu.umd.cs.findbugs.annotations.Nullable; 012 013public interface IIdentifierParser { 014 @NonNull 015 IIdentifierParser FRAGMENT_PARSER = new PatternIdentifierParser("^#([^#]+)(?:#.*)?$", 1); 016 @NonNull 017 IIdentifierParser IDENTITY_PARSER = new IIdentifierParser() { 018 019 @Override 020 public String parse(@NonNull String reference) { 021 return reference; 022 } 023 024 @Override 025 public String update(@NonNull String reference, @NonNull String newIdentifier) { 026 return newIdentifier; 027 } 028 }; 029 030 /** 031 * Parse the {@code referenceText} for the identifier. 032 * 033 * @param referenceText 034 * the reference text containing the identifier 035 * @return the identifier, or {@code null} if the identifier could not be parsed 036 */ 037 @Nullable 038 String parse(@NonNull String referenceText); 039 040 /** 041 * Substitute the provided {@code newIdentifier} with the identifier in the 042 * {@code referenceText}. 043 * 044 * @param referenceText 045 * the reference text containing the original identifier 046 * @param newIdentifier 047 * the new identifier to replace the existing identifier 048 * @return the updated reference text with the identifier replaced 049 * @throws ProfileResolutionEvaluationException 050 * if the identifier could not be updated 051 */ 052 @NonNull 053 String update(@NonNull String referenceText, @NonNull String newIdentifier); 054}