Package ch.ethz.inf.vs.californium

Source Code of ch.ethz.inf.vs.californium.WebLink

package ch.ethz.inf.vs.californium;

import ch.ethz.inf.vs.californium.coap.LinkFormat;
import ch.ethz.inf.vs.californium.server.resources.ResourceAttributes;

/**
* The WebLink class can be used to programmatically browse a remote CoAP endoint.
* It uses the {@link ResourceAttributes} class to hold the CoRE Link Format attributes.
* The {@link CoapClient#discover()} method returns a list of WebLinks for this.
*
* TODO: Add support for absolute URIs and URI checking.
*
* @author Matthias Kovatsch
*
*/
public class WebLink implements Comparable<WebLink> {
  private String uri;
  private final ResourceAttributes attributes;
 
  public WebLink(String uri) {
    this.uri = uri;
    this.attributes = new ResourceAttributes();
  }
 
  public String getURI() {
    return this.uri;
  }
 
  public ResourceAttributes getAttributes() {
    return attributes;
  }
 
  /**
   * Renders the Web link information as a multi-line string, which can be
   * displayed in console clients.
   *
   * @return a string representation of the Web link
   */
  public String toString() {
    StringBuilder builder = new StringBuilder();
   
    builder.append('<');
    builder.append(this.uri);
    builder.append('>');
    builder.append(' ').append(this.attributes.getTitle());
    if (this.attributes.containsAttribute(LinkFormat.RESOURCE_TYPE)) builder.append("\n\t").append(LinkFormat.RESOURCE_TYPE).append(":\t").append(this.attributes.getResourceTypes());
    if (this.attributes.containsAttribute(LinkFormat.INTERFACE_DESCRIPTION)) builder.append("\n\t").append(LinkFormat.INTERFACE_DESCRIPTION).append(":\t").append(this.attributes.getInterfaceDescriptions());
    if (this.attributes.containsAttribute(LinkFormat.CONTENT_TYPE)) builder.append("\n\t").append(LinkFormat.CONTENT_TYPE).append(":\t").append(this.attributes.getContentTypes());
    if (this.attributes.containsAttribute(LinkFormat.MAX_SIZE_ESTIMATE)) builder.append("\n\t").append(LinkFormat.MAX_SIZE_ESTIMATE).append(":\t").append(this.attributes.getMaximumSizeEstimate());
    if (this.attributes.hasObservable()) builder.append("\n\t").append(LinkFormat.OBSERVABLE);
    return builder.toString();
  }

  @Override
  public int compareTo(WebLink other) {
    return this.uri.compareTo(other.getURI());
  }
}
TOP

Related Classes of ch.ethz.inf.vs.californium.WebLink

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.