View Javadoc

1   /*
2   Karma CLI - Command Line Interface for the Karma application
3   Copyright (C) 2004  Toolforge <www.toolforge.nl>
4   
5   This library is free software; you can redistribute it and/or
6   modify it under the terms of the GNU Lesser General Public
7   License as published by the Free Software Foundation; either
8   version 2.1 of the License, or (at your option) any later version.
9   
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  Lesser General Public License for more details.
14  
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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(); // Ignore the response from the superclass
55  
56      List renderedData = getData();
57  
58      // -- formatting manifest data
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           // No fifth column
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     // -- end of formatting
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 }