private void writePart(Element actionReport, MessagePart part, String childType) { Document d = actionReport.getOwnerDocument(); Element messagePart = d.createElement("message-part"); actionReport.appendChild(messagePart); if (childType != null) { messagePart.setAttribute("type", childType); } for (Map.Entry prop : part.getProps().entrySet()) { Element p = d.createElement("property"); messagePart.appendChild(p); p.setAttribute("name", prop.getKey().toString()); p.setAttribute("value", prop.getValue().toString()); } messagePart.setAttribute("message", part.getMessage()); for (MessagePart subPart : part.getChildren()) writeSubPart(messagePart, subPart, subPart.getChildrenType()); }
/** * Write out all the sub-parts as XML elements where the * "childType" is the name of the XML element and the properties * are attributes of the element. Recurse for any subparts. */ private void writeSubPart(Element actionReport, MessagePart part, String childType) { Document d = actionReport.getOwnerDocument(); Element messagePart = d.createElement(childType); actionReport.appendChild(messagePart); for (Map.Entry prop : part.getProps().entrySet()) { messagePart.setAttribute(prop.getKey().toString(), prop.getValue().toString()); } for (MessagePart subPart : part.getChildren()) writeSubPart(messagePart, subPart, subPart.getChildrenType()); }
private boolean superSimple(MessagePart part) { // this is mainly here for backward compatability for when this Reporter // only wrote out the main message. List<MessagePart> list = part.getChildren(); Properties props = part.getProps(); boolean hasChildren = (list != null && !list.isEmpty()); boolean hasProps = (props != null && props.size() > 0); // return true if we are very very simple! return !hasProps && !hasChildren; }
for (ActionReport.MessagePart cp : subPart.getChildren()) { ActionReport.MessagePart resourcesChildPart = childPart.addChild(); resourcesChildPart.setMessage(" " + cp.getMessage());
new RemoteCLICommand("list-commands", po, env); ActionReport report = cmd.executeAndReturnActionReport("list-commands"); List<MessagePart> children = report.getTopMessagePart().getChildren(); List<String> rcmds = new ArrayList<String>(children.size()); for (ActionReport.MessagePart msg : children) {
if (part.getChildren().size() > 0) { attr.putValue("children-type", part.getChildrenType()); attr.putValue("use-main-children-attribute", "true"); StringBuilder keys = null; for (MessagePart child : part.getChildren()) {
private void messageToString(int indentLevel, String id, MessagePart msg, StringBuilder sb) { if (msg == null) { return; } addIndent(indentLevel, sb); sb.append("MESSAGE - ").append(id).append(EOL); if (msg.getMessage() != null && !msg.getMessage().isEmpty()) { addIndent(indentLevel, sb); sb.append(" : ").append(msg.getMessage()).append(EOL); } if (msg.getChildrenType() != null) { addIndent(indentLevel, sb); sb.append(" childrenType: ").append(msg.getChildrenType()).append(EOL); } for (Map.Entry<Object, Object> entry : msg.getProps().entrySet()) { addIndent(indentLevel, sb); sb.append(" >").append(entry.getKey()).append(" = ").append(entry.getValue()); sb.append(EOL); } if (msg.getChildren() != null) { int counter = 0; for (MessagePart child : msg.getChildren()) { messageToString(indentLevel + 1, id + ".M" + counter, child, sb); counter++; } } }
private void writePart(Element actionReport, MessagePart part, String childType) { Document d = actionReport.getOwnerDocument(); Element messagePart = d.createElement("message-part"); actionReport.appendChild(messagePart); if (childType != null) { messagePart.setAttribute("type", childType); } for (Map.Entry prop : part.getProps().entrySet()) { Element p = d.createElement("property"); messagePart.appendChild(p); p.setAttribute("name", prop.getKey().toString()); Object value = prop.getValue(); if (value instanceof List) { addListElement(p, (List)value); } else if (value instanceof Map) { addMapElement(p, (Map)value); } else { p.setAttribute("value", prop.getValue().toString()); } } messagePart.setAttribute("message", part.getMessage()); for (MessagePart subPart : part.getChildren()) { writePart(messagePart, subPart, subPart.getChildrenType()); } }
private void write(MessagePart part, PrintWriter writer) { writer.println("{ " + quote("name") + ":" + quote(part.getMessage())); if (top) { writer.println(", " + quote("command") + ":" + quote(actionDescription)); writer.println(", " + quote("exit_code") + ":" + quote("" + this.exitCode)); top = false; } writeProperties(part.getProps(), writer); boolean first = true; for (MessagePart child : part.getChildren()) { if (first == true) { writer.println(", " + quote("result") + " : ["); } else { writer.println(","); } first = false; write(child, writer); } if (first == false) { //close the array writer.println("]"); } writer.println("}"); }
private static void addSubMessages(String indentPrefix, ActionReport.MessagePart mp, StringBuilder sb) { if (mp == null || sb == null) { return; } if (indentPrefix == null) { indentPrefix = ""; } List<ActionReport.MessagePart> children = mp.getChildren(); if (children != null) { for (ActionReport.MessagePart subPart : children) { if (sb.length() > 0) { sb.append(EOL); } if (ok(subPart.getMessage())) { sb.append(subPart.getMessage()); } addSubMessages(indentPrefix + " ", subPart, sb); } } }
private void displayAppScopedResources(String applicationName, ActionReport report, ActionReport.MessagePart part) { Application application = null; List<Application> applications = domain.getApplicationsInTarget(target); for (Application app : applications) { if (app.getName().equals(applicationName)) { application = app; } } if (application != null) { ActionReport subReport = report.addSubActionsReport(); CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("_list-resources", subReport); final ParameterMap parameters = new ParameterMap(); parameters.add("appname", application.getName()); inv.parameters(parameters).execute(); ActionReport.MessagePart subPart = subReport.getTopMessagePart(); for (ActionReport.MessagePart cp: subPart.getChildren()) { ActionReport.MessagePart resourcesChildPart = part.addChild(); resourcesChildPart.setMessage(cp.getMessage()); } } }
private void copyMessagePart(MessagePart source, MessagePart dest) { if (source == null || dest == null) { return; } dest.setMessage(source.getMessage()); dest.setChildrenType(source.getChildrenType()); Properties props = source.getProps(); if (props != null) { for (Map.Entry<Object, Object> entry : props.entrySet()) { dest.addProperty((String) entry.getKey(), (String) entry.getValue()); } } for (MessagePart chmp : source.getChildren()) { copyMessagePart(chmp, dest.addChild()); } }
private void displaySubComponents(String appName, ActionReport report, ActionReport.MessagePart part) { ActionReport subReport = report.addSubActionsReport(); CommandRunner.CommandInvocation inv = commandRunner.getCommandInvocation("list-sub-components", subReport); final ParameterMap parameters = new ParameterMap(); parameters.add("DEFAULT", appName); parameters.add("terse", "true"); parameters.add("resources", resources.toString()); inv.parameters(parameters).execute(); ActionReport.MessagePart subPart = subReport.getTopMessagePart(); for (ActionReport.MessagePart childPart: subPart.getChildren()) { ActionReport.MessagePart actualChildPart = part.addChild(); actualChildPart.setMessage(" " + childPart.getMessage()); for(ActionReport.MessagePart grandChildPart : childPart.getChildren()){ actualChildPart.addChild().setMessage(grandChildPart.getMessage()); } } }
private void write(int level, MessagePart part, PrintWriter writer) { String mess = part.getMessage(); if (mess==null){ mess = "";//better than a null string output } if (level>6) { writer.println(mess); } else { writer.println("<h" + level + ">" + mess + "</h" + level + ">"); } write(part.getProps(), writer); for (MessagePart child : part.getChildren()) { write(level+1, child, writer); } }
private void write(String indent, MessagePart part, StringBuilder out) { out.append(indent).append(part.getMessage()).append('\n'); write(indent + INDENT, part.getProps(), out); for (MessagePart child : part.getChildren()) { write(indent + INDENT, child, out); } }