Add a link to this resource

@param rel
@param uri The target URI for the link, possibly relative to the href of this resource.
968807
public static void withLink(Representation representation, String rel, URI uri, Optional<Predicate<ReadableRepresentation>> predicate, Optional<String> name, Optional<String> title, Optional<String> hreflang, Optional<String> profile) {
        withLink(representation, rel, uri.toASCIIString(), predicate, name, title, hreflang, profile);
    }
1374213
private void relink(SimpleOutputElement parent,
                        String prefix, String localName, String uri)
    {
        super.relink(parent);
        mParent = parent;
        mPrefix = prefix;
        mLocalName = localName;
        mURI = uri;
        mNsMapping = parent.mNsMapping;
        mNsMapShared = (mNsMapping != null);
        mDefaultNsURI = parent.mDefaultNsURI;
        mRootNsContext = parent.mRootNsContext;
    }
539745
public static Link getLinkByRel(Entity entity, String... rel) {
        if(entity == null) {
            throw new IllegalArgumentException("entity cannot be null.");
        }
        if(ArrayUtils.isEmpty(rel)) {
            throw new IllegalArgumentException("rel cannot be null or empty");
        }
        List<Link> links = entity.getLinks();
        if (links == null)
            return null;
        Link link = null;
        for (Link l : links) {
            if (ArrayUtils.isNotEmpty(l.getRel()) && ArrayUtils.toString(rel).equals(ArrayUtils.toString(l.getRel()))) {
                link = l;
                break;
            }
        }
        return link;
    }
1143135
private static URL findBaseURI(final Element root) {
        URL baseURI = null;
        final List<Element> linksList = root.getChildren("link", OS_NS);
        if (linksList != null) {
            for (final Element element : linksList) {
                final Element link = element;
                if (!root.equals(link.getParent())) {
                    break;
                }
                String href = link.getAttribute("href").getValue();
                if (link.getAttribute("rel", OS_NS) == null || link.getAttribute("rel", OS_NS).getValue().equals("alternate")) {
                    href = resolveURI(null, link, href);
                    try {
                        baseURI = new URL(href);
                        break;
                    } catch (final MalformedURLException e) {
                        System.err.println("Base URI is malformed: " + href);
                    }
                }
            }
        }
        return baseURI;
    }
709753
public NatsConnector addHost(URI uri) {
		if (!Constants.PROTOCOL.equalsIgnoreCase(uri.getScheme())) {
			throw new IllegalArgumentException("Invalid protocol in URL: " + uri);
		}
		hosts.add(uri);
		return this;
	}
457138
public void setLink(Link link) {
		setHref(link.getHref());
		setHrefAbsolute(link.getHrefAbsolute());
		HttpParameters linkParams = link.getParams();
		if(linkParams != null) {
			for(Map.Entry<String,List<String>> entry : linkParams.getParameterMap().entrySet()) {
				String paramName = entry.getKey();
				for(String paramValue : entry.getValue()) {
					addParam(paramName, paramValue);
				}
			}
		}
		this.addLastModified = link.getAddLastModified();
		setHreflang(link.getHreflang());
		setRel(link.getRel());
		setType(link.getType());
		setMedia(link.getMedia());
		setTitle(link.getTitle());
	}
639932
private static String buildLink(final URI linkUri, final String relation) {
        return Link.fromUri(linkUri).rel(relation).build().toString();
    }
1128818
public static void withLink(Representation representation, String rel, String href, Predicate<ReadableRepresentation> predicate) {
        withLink(representation, rel, href,
                 Optional.of(predicate),
                 Optional.<String>absent(),
                 Optional.<String>absent(),
                 Optional.<String>absent(),
                 Optional.<String>absent());
    }
590169
public List<Link> collectLinks(String rel) {
    return collectResources(Link.class, HalResourceType.LINKS, rel);
  }
1074226
@Nullable
  public static URL uriToUrl(@Nullable Uri uri) {
    if (uri == null) {
      return null;
    }

    try {
      return new URL(uri.toString());
    } catch (java.net.MalformedURLException e) {
      // This should never happen since we got a valid uri
      throw new RuntimeException(e);
    }
  }
1342661
public static void addURL(URL u) throws IOException {
        if (!(ClassLoader.getSystemClassLoader() instanceof URLClassLoader)) {
            return;
        }

        URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
        URL[] urls = sysLoader.getURLs();
        for (int i = 0; i < urls.length; i++) {
            if (StringUtils.equalsIgnoreCase(urls[i].toString(), u.toString())) {
                if (log.isDebugEnabled()) {
                    log.debug("URL " + u + " is already in the CLASSPATH");
                }
                return;
            }
        }
        Class<URLClassLoader> sysclass = URLClassLoader.class;
        try {
            Method method = sysclass.getDeclaredMethod("addURL", parameters);
            method.setAccessible(true);
            method.invoke(sysLoader, new Object[]{u});
        } catch (Throwable t) {
            t.printStackTrace();
            throw new IOException("Error, could not add URL to system classloader");
        }
    }
1144994
public void addLinkRef(final String key, final LinkRef linkRef)
    {
        this.linkRefs.put(key.toLowerCase(), linkRef);
    }
1074559
public static Link link(String href, String rel) {
        return link(href, rel, null, null, null);
    }
806281
public void setUrl(String url) {
        if (url != null && url.trim().length() > 0) {
            if (Url.isUrl(url)) {
                this.url = url;
            } else {
                throw new IllegalArgumentException(url + " is not a valid URL.");
            }
        }
    }
911647
public GenericResponseBuilder<T> link(URI uri, String rel) {
    rawBuilder.link(uri, rel);
    return this;
  }
343266
private String rewriteUri(String internalUri) {

        // if an object wrapper is used, rewrite the uri
        if (m_cms != null) {
            Object obj = m_cms.getRequestContext().getAttribute(CmsObjectWrapper.ATTRIBUTE_NAME);
            if (obj != null) {
                CmsObjectWrapper wrapper = (CmsObjectWrapper)obj;
                return wrapper.restoreLink(internalUri);
            }
        }

        return internalUri;
    }
264953
def add_link(self, rel, value, href=None):
        
        links_node = self.metadata.find('links')
        if links_node is None:
            links_node = ioc_et.make_links_node()
            self.metadata.append(links_node)
        link_node = ioc_et.make_link_node(rel, value, href)
        links_node.append(link_node)
        return True