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

no.hasmac.jsonld.http.link.Link Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2020 APICATALOG and HASMAC.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * SPDX-License-Identifier: Apache-2.0
 */

package no.hasmac.jsonld.http.link;

import no.hasmac.jsonld.http.media.MediaType;

import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;

/**
 *
 * @see Web Linking
 *
 */
public final class Link {

    private final URI contextUri;

    private final URI targetUri;

    private final Set relations;

    private final MediaType type;

    private final LinkAttributes attributes;

    protected Link(URI contextUri, URI targetUri, Set relations, final MediaType type, final LinkAttributes attributes) {
        this.contextUri = contextUri;
        this.targetUri = targetUri;
        this.relations = relations;
        this.type = type;
        this.attributes = attributes;
    }

    public static Collection of(final String linkHeader) {
        return of(linkHeader, null);
    }

    public static Collection of(final String linkHeader, final URI baseUri) {
        if (linkHeader == null) {
            throw new IllegalArgumentException("Link header value cannot be null.");
        }

        return new LinkHeaderParser(baseUri).parse(linkHeader);
    }

    public URI target() {
        return targetUri;
    }

    public Optional context() {
        return Optional.ofNullable(contextUri);
    }

    public Set relations() {
        return Collections.unmodifiableSet(relations);
    }

    public Optional type() {
        return Optional.ofNullable(type);
    }

    public LinkAttributes attributes() {
        return attributes;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy