Hi,
I was trying to make an xsl that takes the jersey-generated wadl and
turns it into a flat text file in a particular wiki markup format. I
am not very good at xsl so I gave up, and decided to postprocess the
wadl in java. Then I thought, gee, if I'm going to do that, why don't
I just make a jersey resource that generates the document in the
format that I want?
I don't want output for anything that's not attached to a method (GET,
POST, etc.)
I must not be traversing the tree correctly, though, because I only
see one resource/method for each top level resource.
Does this look right?
this.wadlContext = wadlContext; /* came in via @Context */
this.application = wadlContext.getApplication();
List<Resource> resourceList = resources.getResource();
StringBuilder sb = new StringBuilder();
/* recursively traverse the tree */
for (Resource r : resourceList) {
sb = traverseResource(sb, r.getPath(), r, 0);
}
private StringBuilder traverseResource(StringBuilder sb, String path,
Resource r, int depth) {
sb.append("[dumping " + path + "(" + r.getPath() + ")]\r\n");
char[] spaces = new char[depth * 3];
Arrays.fill(spaces, ' ');
List<Object> children = r.getMethodOrResource();
if (children.size() == 0) {
sb.append(spaces).append(path).append(" has no children\r\n");
}
for (Object child : children) {
if (child instanceof Resource) {
/* If this is a resource, accumulate the path and recurse */
Resource cr = (Resource) child;
return traverseResource(sb, path + "/" + cr.getPath(),
cr, depth + 1);
} else if (child instanceof Method) {
/* If this is a method, dump out interesting
information about it */
Method m = (Method) child;
return dumpMethod(sb, path, m, depth + 1);
} else {
sb.append(spaces).append("unknown node
").append(child.getClass().getName()).append(":
").append(child.toString()).append("\r\n");
}
}
depth is used just to accumulate indentation during the recursion.
I am off in the land of com.sun.research.ws.wadl here, a place I am
probably not supposed to be. Everything "seems" normal, though,
except that it doesn't seem to recurse completely. I don't see any
children that aren't either a Resource or Method, so I do not believe
I am missing other types of objects.
Am I barking up the wrong tree?
--Chris