public DOTRenderer(Writer writer) {
this.writer = writer;
}
public void render(String ns) {
Graph graph = new Graph();
TreeMap viewMap = new TreeMap(new Comparator() {
public int compare(Object o1, Object o2) {
ViewNode v1 = (ViewNode) o1;
ViewNode v2 = (ViewNode) o2;
return v1.getFullName().compareTo(v2.getFullName());
}
});
Set namespaces = StrutsConfigRetriever.getNamespaces();
for (Iterator iter = namespaces.iterator(); iter.hasNext();) {
String namespace = (String) iter.next();
if (!namespace.startsWith(ns)) {
continue;
}
SubGraph subGraph = graph.create(namespace);
Set actionNames = StrutsConfigRetriever.getActionNames(namespace);
for (Iterator iterator = actionNames.iterator(); iterator.hasNext();) {
String actionName = (String) iterator.next();
ActionConfig actionConfig = StrutsConfigRetriever.getActionConfig(namespace,
actionName);
ActionNode action = new ActionNode(actionName);
subGraph.addNode(action);
Set resultNames = actionConfig.getResults().keySet();
for (Iterator iterator2 = resultNames.iterator(); iterator2.hasNext();) {
String resultName = (String) iterator2.next();
ResultConfig resultConfig = ((ResultConfig) actionConfig.getResults().get(resultName));
String resultClassName = resultConfig.getClassName();
if (resultClassName.equals(ActionChainResult.class.getName())) {
} else if (resultClassName.indexOf("Dispatcher") != -1
|| resultClassName.indexOf("Velocity") != -1
|| resultClassName.indexOf("Freemarker") != -1) {
if (resultConfig.getParams().get("location") == null) {
continue;
}
String location = getViewLocation((String) resultConfig.getParams().get("location"), namespace);
// FIXME: work with new configuration style
if (location.endsWith("action")) {
addTempLink(action, location, Link.TYPE_RESULT, resultConfig.getName());
} else {
ViewNode view = new ViewNode(stripLocation(location));
subGraph.addNode(view);
addTempLink(action, location, Link.TYPE_RESULT, resultConfig.getName());
View viewFile = getView(namespace, actionName, resultName, location);
if (viewFile != null) {
viewMap.put(view, viewFile);
}
}
} else if (resultClassName.indexOf("Jasper") != -1) {
} else if (resultClassName.indexOf("XSLT") != -1) {
} else if (resultClassName.indexOf("Redirect") != -1) {
// check if the redirect is to an action -- if so, link it
String locationConfig = (String) resultConfig.getParams().get("location");
if (locationConfig == null) {
locationConfig = (String) resultConfig.getParams().get("actionName");
}
String location = getViewLocation(locationConfig, namespace);
// FIXME: work with new configuration style
if (location.endsWith("action")) {
addTempLink(action, location, Link.TYPE_REDIRECT, resultConfig.getName());
} else {
ViewNode view = new ViewNode(stripLocation(location));
subGraph.addNode(view);
addTempLink(action, location, Link.TYPE_REDIRECT, resultConfig.getName());
View viewFile = getView(namespace, actionName, resultName, location);
if (viewFile != null) {
viewMap.put(view, viewFile);
}
}
}
}
}
}
// now look for links in the view
for (Iterator iterator = viewMap.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
ViewNode view = (ViewNode) entry.getKey();
View viewFile = (View) entry.getValue();
Set targets = viewFile.getTargets();
for (Iterator iterator1 = targets.iterator(); iterator1.hasNext();) {
Target target = (Target) iterator1.next();
String viewTarget = target.getTarget();
addTempLink(view, viewTarget, target.getType(), "");
}
}
// finally, let's match up these links as real Link objects
for (Iterator iterator = links.iterator(); iterator.hasNext();) {
TempLink temp = (TempLink) iterator.next();
String location = temp.location;
// FIXME: work with new configuration style
if (location.endsWith("action")) {
location = location.substring(0, location.indexOf("action") - 1);
if (location.indexOf('!') != -1) {
temp.label = temp.label + "\\n(" + location.substring(location.indexOf('!')) + ")";
location = location.substring(0, location.indexOf('!'));
}
}
SiteGraphNode to = graph.findNode(location, temp.node);
if (to != null) {
graph.addLink(new Link(temp.node, to, temp.typeResult, temp.label));
}
}
try {
//writer.write(graph.to_s(true));
graph.render(new IndentWriter(writer));
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}