com.synopsys.integration.bdio.model.BdioIdEscaper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of integration-bdio Show documentation
Show all versions of integration-bdio Show documentation
A library to allow for easy and clear creation of Black Duck I/O (bdio) documents.
/*
* integration-bdio
*
* Copyright (c) 2022 Synopsys, Inc.
*
* Use subject to the terms and conditions of the Synopsys End User Software License and Maintenance Agreement. All rights reserved worldwide.
*/
package com.synopsys.integration.bdio.model;
import com.synopsys.integration.util.IntegrationEscapeUtil;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
public class BdioIdEscaper {
private IntegrationEscapeUtil integrationEscapeUtil;
public BdioIdEscaper() {
this.integrationEscapeUtil = new IntegrationEscapeUtil();
}
public BdioIdEscaper(IntegrationEscapeUtil integrationEscapeUtil) {
this.integrationEscapeUtil = new IntegrationEscapeUtil();
}
public List escapePiecesForUri(final List pieces) {
final List escapedPieces = new ArrayList<>(pieces.size());
for (final String piece : pieces) {
final String escaped = escapeForUri(piece);
escapedPieces.add(escaped);
}
return escapedPieces;
}
public String escapeForUri(final String s) {
if (s == null) {
return null;
}
try {
return URLEncoder.encode(s, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
return poorManEscaping(s);
}
}
private String poorManEscaping(String s) {
return integrationEscapeUtil.replaceWithUnderscore(s);
}
}