Package ch.ethz.inf.vs.californium.server.resources

Examples of ch.ethz.inf.vs.californium.server.resources.ResourceAttributes$AttributeValues


  public static boolean matches(Resource resource, List<String> queries) {
   
    if (resource==null) return false;
    if (queries==null || queries.size()==0) return true;
   
    ResourceAttributes attributes = resource.getAttributes();
    String path = resource.getPath()+resource.getName();
   
    for (String s : queries) {
      int delim = s.indexOf("=");
      if (delim != -1) {
       
        // split name-value-pair
        String attrName = s.substring(0, delim);
        String expected = s.substring(delim+1);

        if (attrName.equals(LinkFormat.LINK)) {
          if (expected.endsWith("*")) {
            return path.startsWith(expected.substring(0, expected.length()-1));
          } else {
            return path.equals(expected);
          }
        } else if (attributes.containsAttribute(attrName)) {
          // lookup attribute value
          for (String actual : attributes.getAttributeValues(attrName)) {
         
            // get prefix length according to "*"
            int prefixLength = expected.indexOf('*');
            if (prefixLength >= 0 && prefixLength < actual.length()) {
         
              // reduce to prefixes
              expected = expected.substring(0, prefixLength);
              actual = actual.substring(0, prefixLength);
            }
           
            // handle case like rt=[Type1 Type2]
            if (actual.indexOf(" ") > -1) { // if contains white space
              String[] parts = actual.split(" ");
              for (String part : parts) { // check each part for match
                if (part.equals(expected)) {
                  return true;
                }
              }
            }
           
            // compare strings
            if (expected.equals(actual)) {
              return true;
            }
          }
        }
      } else {
        // flag attribute
        if (attributes.getAttributeValues(s).size()>0) {
          return true;
        }
      }
    }
    return false;
View Full Code Here


  private String uri;
  private final ResourceAttributes attributes;
 
  public WebLink(String uri) {
    this.uri = uri;
    this.attributes = new ResourceAttributes();
  }
View Full Code Here

  private List<Integer> supported = new ArrayList<Integer>();

  public ImageResource(String resourceIdentifier) {
    super(resourceIdentifier);
   
    ResourceAttributes attributes = getAttributes();
    attributes.setTitle("GET an image with different content-types");
    attributes.addResourceType("Image");
   
    supported.add(MediaTypeRegistry.IMAGE_PNG);
    supported.add(MediaTypeRegistry.IMAGE_JPEG);
   
    for (int ct : supported) {
      attributes.addContentType(ct);
    }
   
    attributes.setMaximumSizeEstimate(18029);
  }
View Full Code Here

TOP

Related Classes of ch.ethz.inf.vs.californium.server.resources.ResourceAttributes$AttributeValues

Copyright © 2018 www.massapicom. 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.