All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.synopsys.integration.bdio.model.BdioIdEscaper Maven / Gradle / Ivy

Go to download

A library to allow for easy and clear creation of Black Duck I/O (bdio) documents.

There is a newer version: 26.0.13
Show newest version
/*
 * 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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy