package org.jboss.resteasy.spi;
import org.jboss.resteasy.plugins.delegates.LinkHeaderDelegate;
import javax.ws.rs.core.Link;
import javax.ws.rs.core.MultivaluedMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class
{
private Map<String, Link> = new HashMap<String, Link>();
private Map<String, Link> = new HashMap<String, Link>();
private List<Link> = new ArrayList<Link>();
public LinkHeaders (MultivaluedMap<String, String> headers)
{
List<String> values = headers.get("Link");
if (values == null) return this;
for (String val : values)
{
LinkHeader linkHeader = new LinkHeaderDelegate().fromString(val);
for (org.jboss.resteasy.spi.Link link : linkHeader.getLinks())
{
addLink(link.toJaxrsLink());
}
}
return this;
}
public LinkHeaders (MultivaluedMap<String, Object> headers, HeaderValueProcessor factory)
{
List<Object> values = headers.get("Link");
if (values == null) return this;
for (Object val : values)
{
if (val instanceof Link) addLink((Link)val);
else
{
String str = factory.toHeaderString(val);
addLink(Link.valueOf(str));
}
}
return this;
}
public LinkHeaders (final Link link)
{
links.add(link);
for (String rel : link.getRels())
{
linksByRelationship.put(rel, link);
}
if (link.getTitle() != null) linksByTitle.put(link.getTitle(), link);
return this;
}
public Link (String title)
{
return linksByTitle.get(title);
}
public Link (String rel)
{
return linksByRelationship.get(rel);
}
public Map<String, Link> ()
{
return linksByRelationship;
}
public Map<String, Link> ()
{
return linksByTitle;
}
public List<Link> ()
{
return links;
}
}