/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.models.dao.converters;
-import javax.persistence.AttributeConverter;
-import javax.persistence.Converter;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
+import com.google.re2j.Pattern;
+import jakarta.persistence.AttributeConverter;
+import jakarta.persistence.Converter;
+import jakarta.xml.bind.annotation.adapters.XmlAdapter;
/**
- * The Class CDATAConditioner converts a CDATA String to and from database format by removing spaces
+ * The Class CDataConditioner converts a CDATA String to and from database format by removing spaces
* at the ends of lines and platform-specific new line endings.
*/
@Converter
public class CDataConditioner extends XmlAdapter<String, String> implements AttributeConverter<String, String> {
+ private static final Pattern TRAILING_SPACE_PAT = Pattern.compile("\\s+$");
private static final String NL = "\n";
@Override
* @param in the in
* @return the string
*/
- public static final String clean(final String in) {
+ public static String clean(final String in) {
if (in == null) {
return null;
} else {
- return in.replaceAll("\\s+$", "").replaceAll("\\r?\\n", NL);
+ return TRAILING_SPACE_PAT.matcher(in).replaceAll("").replaceAll("\\r?\\n", NL);
}
}
}