@Override public String asLinkFormat() { final StringBuilder linkFormat = LinkFormat.serializeResource(this).append( LinkFormat.serializeAttributes(getAttributes())); linkFormat.deleteCharAt(linkFormat.length() - 1); return linkFormat.toString(); }
public static void serializeTree(Resource resource, List<String> queries, StringBuilder buffer) { // add the current resource to the buffer if (resource.isVisible() && LinkFormat.matches(resource, queries)) { buffer.append(LinkFormat.serializeResource(resource)); } // sort by resource name List<Resource> childs = new ArrayList<Resource>(resource.getChildren()); Collections.sort(childs, new Comparator<Resource>() { @Override public int compare(Resource o1, Resource o2) { return o1.getName().compareTo(o2.getName()); } }); for (Resource child:childs) { serializeTree(child, queries, buffer); } }
public static StringBuilder serializeAttributes(ResourceAttributes attributes) { StringBuilder buffer = new StringBuilder(); List<String> attributesList = new ArrayList<String>(attributes.getAttributeKeySet()); Collections.sort(attributesList); for (String attr : attributesList) { List<String> values = attributes.getAttributeValues(attr); if (values == null) continue; buffer.append(";"); // Make a copy to not depend on thread-safety buffer.append(serializeAttribute(attr, new LinkedList<String>(values))); } return buffer; }
success &= LinkFormat.matches(sub, query); LinkFormat.serializeResource(sub));
public static String serializeTree(Resource resource) { StringBuilder buffer = new StringBuilder(); List<String> noQueries = Collections.emptyList(); // only include children, not the entry point itself for (Resource child:resource.getChildren()) { serializeTree(child, noQueries, buffer); } if (buffer.length()>1) buffer.delete(buffer.length()-1, buffer.length()); return buffer.toString(); }
public static StringBuilder serializeResource(Resource resource) { StringBuilder buffer = new StringBuilder(); buffer.append("<") .append(resource.getPath()) .append(resource.getName()) .append(">") .append(LinkFormat.serializeAttributes(resource.getAttributes())) .append(","); return buffer; }
client.setURI(link.getURI()); System.out.println("---------------\nGET " + link.getURI() + " with ct=40\n---------------"); Set<WebLink> links2 = LinkFormat.parse(client.get(MediaTypeRegistry.APPLICATION_LINK_FORMAT).getResponseText()); System.out.println("Found " + links2.size() + " resource(s)"); for (WebLink link2 : links2) {
@Override public void handleGET(CoapExchange exchange) { exchange.respond(CONTENT, LinkFormat.serializeTree(this), APPLICATION_LINK_FORMAT); }
public static StringBuilder serializeResource(Resource resource) { StringBuilder buffer = new StringBuilder(); buffer.append("<") .append(resource.getPath()) .append(resource.getName()) .append(">") .append(LinkFormat.serializeAttributes(resource.getAttributes())) .append(","); return buffer; }
public Set<WebLink> discover(String query) { Request discover = Request.newGet(); discover.setURI(uri); // for scheme and authority, but then remove path and query discover.getOptions().clearUriPath().clearUriQuery().setUriPath("/.well-known/core"); if (query!=null) { discover.getOptions().setUriQuery(query); } CoapResponse links = synchronous(discover); // if no response, return null (e.g., timeout) if (links == null) { return null; } // check if Link Format if (links.getOptions().getContentFormat()!=MediaTypeRegistry.APPLICATION_LINK_FORMAT) return Collections.emptySet(); // parse and return return LinkFormat.parse(links.getResponseText()); }
@Override public String asLinkFormat() { final StringBuilder linkFormat = LinkFormat.serializeResource(this).append( LinkFormat.serializeAttributes(getAttributes())); linkFormat.deleteCharAt(linkFormat.length() - 1); return linkFormat.toString(); }
public static void serializeTree(Resource resource, List<String> queries, StringBuilder buffer) { // add the current resource to the buffer if (resource.isVisible() && LinkFormat.matches(resource, queries)) { buffer.append(LinkFormat.serializeResource(resource)); } // sort by resource name List<Resource> childs = new ArrayList<Resource>(resource.getChildren()); Collections.sort(childs, new Comparator<Resource>() { @Override public int compare(Resource o1, Resource o2) { return o1.getName().compareTo(o2.getName()); } }); for (Resource child:childs) { serializeTree(child, queries, buffer); } }
public static String serializeTree(Resource resource) { StringBuilder buffer = new StringBuilder(); List<String> noQueries = Collections.emptyList(); // only include children, not the entry point itself for (Resource child:resource.getChildren()) { serializeTree(child, noQueries, buffer); } if (buffer.length()>1) buffer.delete(buffer.length()-1, buffer.length()); return buffer.toString(); }
public Set<WebLink> discover(String query) { Request discover = newGet(); discover.setURI(uri); // for scheme and authority, but then remove path and query discover.getOptions().clearUriPath().clearUriQuery().setUriPath("/.well-known/core"); if (query!=null) { discover.getOptions().setUriQuery(query); } CoapResponse links = synchronous(discover); // if no response, return null (e.g., timeout) if (links == null) { return null; } // check if Link Format if (links.getOptions().getContentFormat()!=MediaTypeRegistry.APPLICATION_LINK_FORMAT) return Collections.emptySet(); // parse and return return LinkFormat.parse(links.getResponseText()); }
public static StringBuilder serializeAttributes(ResourceAttributes attributes) { StringBuilder buffer = new StringBuilder(); List<String> attributesList = new ArrayList<String>(attributes.getAttributeKeySet()); Collections.sort(attributesList); for (String attr : attributesList) { List<String> values = attributes.getAttributeValues(attr); if (values == null) continue; buffer.append(";"); // Make a copy to not depend on thread-safety buffer.append(serializeAttribute(attr, new LinkedList<String>(values))); } return buffer; }
@Override public String asLinkFormat() { final StringBuilder linkFormat = LinkFormat.serializeResource(this).append( LinkFormat.serializeAttributes(getAttributes())); for (final Resource child : getChildren()) { linkFormat.append(LinkFormat.serializeResource(child)); } linkFormat.deleteCharAt(linkFormat.length() - 1); return linkFormat.toString(); }
@Override public void handleGET(CoapExchange exchange) { String subtree = LinkFormat.serializeTree(this); exchange.respond(CONTENT, subtree, APPLICATION_LINK_FORMAT); }
@Override public String asLinkFormat() { final StringBuilder linkFormat = LinkFormat.serializeResource(this).append( LinkFormat.serializeAttributes(getAttributes())); for (final Resource child : getChildren()) { linkFormat.append(LinkFormat.serializeResource(child)); } linkFormat.deleteCharAt(linkFormat.length() - 1); return linkFormat.toString(); }
@Override public void handleGET(CoapExchange exchange) { exchange.respond(CONTENT, LinkFormat.serializeTree(this), APPLICATION_LINK_FORMAT); }
@Override public String asLinkFormat() { final StringBuilder linkFormat = LinkFormat.serializeResource(this).append( LinkFormat.serializeAttributes(getAttributes())); for (final Resource child : getChildren()) { for (final Resource grandchild : child.getChildren()) { linkFormat.append(LinkFormat.serializeResource(grandchild)); } } linkFormat.deleteCharAt(linkFormat.length() - 1); return linkFormat.toString(); }