1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.cli.cmd;
20
21 import nl.toolforge.karma.core.cmd.CommandDescriptor;
22 import nl.toolforge.karma.core.cmd.CommandException;
23 import nl.toolforge.karma.core.cmd.CommandResponse;
24 import nl.toolforge.karma.core.cmd.event.MessageEvent;
25 import nl.toolforge.karma.core.cmd.event.SimpleMessage;
26 import nl.toolforge.karma.core.cmd.impl.ViewManifest;
27 import nl.toolforge.karma.core.manifest.ReleaseManifest;
28 import org.apache.commons.lang.StringUtils;
29
30 import java.util.Iterator;
31 import java.util.List;
32
33 /***
34 * @author D.A. Smedes
35 *
36 * @version $Id: ViewManifestImpl.java,v 1.26 2004/11/16 22:32:23 asmedes Exp $
37 */
38 public class ViewManifestImpl extends ViewManifest {
39
40 private CommandResponse commandResponse = new CommandResponse();
41
42 public ViewManifestImpl(CommandDescriptor descriptor) {
43 super(descriptor);
44 }
45
46 /***
47 * Shows the contents using simple rendering.
48 */
49 public void execute() throws CommandException {
50
51 SimpleMessage message = new SimpleMessage("Checking manifest status, please wait ...");
52 commandResponse.addEvent(new MessageEvent(this, message));
53
54 super.execute();
55
56 List renderedData = getData();
57
58
59
60 StringBuffer buffer = new StringBuffer();
61 buffer.append("\n");
62
63 try {
64 if (getContext().getCurrentManifest() instanceof ReleaseManifest) {
65 buffer.append("RELEASE MANIFEST\n\n");
66
67 String h1 = "MODULE-NAME";
68 String h2 = "TYPE";
69 String h3 = "LOCAL";
70 String h4 = "REMOTE";
71 String h5 = "STATIC";
72 String h6 = "PATCHLINE";
73 String h7 = "STATE";
74 String h8 = "LOCATION";
75
76 buffer.append(h1 + StringUtils.repeat(" ", 45 - h1.length()) + "| ");
77 buffer.append(h2 + StringUtils.repeat(" ", 8 - h2.length()) + "| ");
78 buffer.append(h3 + StringUtils.repeat(" ", 7 - h3.length()) + "| ");
79 buffer.append(h4 + StringUtils.repeat(" ", 9 - h4.length()) + "| ");
80 buffer.append(h5 + StringUtils.repeat(" ", 7 - h5.length()) + "| ");
81 buffer.append(h6 + StringUtils.repeat(" ", 15 - h6.length()) + "| ");
82 buffer.append(h7 + StringUtils.repeat(" ", 10 - h7.length()) + "| ");
83 buffer.append(h8 + "\n");
84 buffer.append(StringUtils.repeat("_", 155));
85 buffer.append("\n");
86
87 for (Iterator i = renderedData.iterator(); i.hasNext();) {
88
89 String[] data = (String[]) i.next();
90
91 buffer.append(data[0] + StringUtils.repeat(" ", 45 - data[0].length()) + "| ");
92 buffer.append(data[1] + StringUtils.repeat(" ", 8 - data[1].length()) + "| ");
93 buffer.append(data[2] + StringUtils.repeat(" ", 7 - data[2].length()) + "| ");
94 buffer.append(data[3] + StringUtils.repeat(" ", 9 - data[3].length()) + "| ");
95 buffer.append(data[4] + StringUtils.repeat(" ", 7 - data[4].length()) + "| ");
96 buffer.append(data[5] + StringUtils.repeat(" ", 15 - data[5].length()) + "| ");
97 buffer.append(data[6] + StringUtils.repeat(" ", 10 - data[6].length()) + "| ");
98 buffer.append(data[7] + "\n");
99 }
100
101 } else {
102
103 buffer.append("DEVELOPMENT MANIFEST\n\n");
104
105 String h1 = "MODULE-NAME";
106 String h2 = "TYPE";
107 String h3 = "LOCAL";
108 String h4 = "REMOTE";
109 String h5 = "STATIC";
110 String h6 = "STATE";
111 String h7 = "LOCATION";
112
113 buffer.append(h1 + StringUtils.repeat(" ", 45 - h1.length()) + "| ");
114 buffer.append(h2 + StringUtils.repeat(" ", 8 - h2.length()) + "| ");
115 buffer.append(h3 + StringUtils.repeat(" ", 7 - h3.length()) + "| ");
116 buffer.append(h4 + StringUtils.repeat(" ", 9 - h4.length()) + "| ");
117 buffer.append(h5 + StringUtils.repeat(" ", 7 - h5.length()) + "| ");
118 buffer.append(h6 + StringUtils.repeat(" ", 35 - h6.length()) + "| ");
119 buffer.append(h7 + "\n");
120 buffer.append(StringUtils.repeat("_", 155));
121 buffer.append("\n");
122
123 for (Iterator i = renderedData.iterator(); i.hasNext();) {
124
125 String[] data = (String[]) i.next();
126 buffer.append(data[0] + StringUtils.repeat(" ", 45 - data[0].length()) + "| ");
127 buffer.append(data[1] + StringUtils.repeat(" ", 8 - data[1].length()) + "| ");
128 buffer.append(data[2] + StringUtils.repeat(" ", 7 - data[2].length()) + "| ");
129 buffer.append(data[3] + StringUtils.repeat(" ", 9 - data[3].length()) + "| ");
130 buffer.append(data[4] + StringUtils.repeat(" ", 7 - data[4].length()) + "| ");
131
132 buffer.append(data[6] + StringUtils.repeat(" ", 35 - data[6].length()) + "| ");
133 buffer.append(data[7] + "\n");
134 }
135 }
136 } catch (NegativeArraySizeException n) {
137 logger.error(n);
138 buffer = new StringBuffer().append("Pfff, some data item is bigger than Karma can handle.");
139 }
140
141
142
143 message = new SimpleMessage(buffer.toString());
144 commandResponse.addEvent(new MessageEvent(message));
145 }
146
147 public CommandResponse getCommandResponse() {
148 return this.commandResponse;
149 }
150 }