/** * Adds an attribute to the tag * * @param name the name of the attribute to add * @param value the value of the attribute to add * @return <tt>this</tt> to fluently add more attributes */ public TagBuilder addAttribute(@Nonnull String name, @Nullable String value) { attributes.add(Attribute.set(name, value)); return this; }
/** * Returns a list of at most the provided number of stored objects * * @param output the xml structured output the list of objects should be written to * @param limit controls the maximum number of objects returned * @param marker the key to start with when listing objects in a bucket * @param prefix limits the response to keys that begin with the specified prefix */ public void outputObjects(XMLStructuredOutput output, int limit, @Nullable String marker, @Nullable String prefix) { ListFileTreeVisitor visitor = new ListFileTreeVisitor(output, limit, marker, prefix); output.beginOutput("ListBucketResult", Attribute.set("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/")); output.property("Name", getName()); output.property("MaxKeys", limit); output.property("Marker", marker); output.property("Prefix", prefix); try { Files.walkFileTree(file.toPath(), visitor); } catch (IOException e) { Exceptions.handle(e); } output.property("IsTruncated", limit > 0 && visitor.getCount() > limit); output.endOutput(); }
/** * GET a list of all buckets * * @param ctx the context describing the current request */ private void listBuckets(WebContext ctx) { HttpMethod method = ctx.getRequest().method(); if (GET == method) { List<Bucket> buckets = storage.getBuckets(); Response response = ctx.respondWith(); response.setHeader(HTTP_HEADER_NAME_CONTENT_TYPE, CONTENT_TYPE_XML); XMLStructuredOutput out = response.xml(); out.beginOutput("ListAllMyBucketsResult", Attribute.set("xmlns", "http://s3.amazonaws.com/doc/2006-03-01/")); out.property("hint", "Goto: " + ctx.getBaseURL() + "/ui to visit the admin UI"); outputOwnerInfo(out, "Owner"); out.beginObject("Buckets"); for (Bucket bucket : buckets) { out.beginObject(RESPONSE_BUCKET); out.property("Name", bucket.getName()); out.property("CreationDate", RFC822_INSTANT.format(Instant.ofEpochMilli(bucket.getFile().lastModified()))); out.endObject(); } out.endObject(); out.endOutput(); } else { throw new IllegalArgumentException(ctx.getRequest().method().name()); } }