01: /**
02: * Copyright 2004 Sun Microsystems, Inc. All
03: * rights reserved. Use of this product is subject
04: * to license terms. Federal Acquisitions:
05: * Commercial Software -- Government Users
06: * Subject to Standard License Terms and
07: * Conditions.
08: *
09: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
10: * are trademarks or registered trademarks of Sun Microsystems,
11: * Inc. in the United States and other countries.
12: */package com.sun.portal.admin.cli.commands.search;
13:
14: import java.util.ArrayList;
15: import java.util.Properties;
16: import java.util.Date;
17: import java.text.DateFormat;
18: import java.text.SimpleDateFormat;
19:
20: // CLI framework
21: import com.sun.enterprise.cli.framework.*;
22:
23: // Base Class
24: import com.sun.portal.admin.cli.commands.GenericCommand;
25:
26: /**
27: * This class implements the psadmin get-popular-search subcommand. The
28: * get-popular-search subcommand calls the SearchServerMBean and shows
29: * a list of popular searchs.
30: */
31: public class GetPopularSearchCommand extends GenericCommand {
32:
33: private static final String QUERY_LABEL = "psadmin.subcommand.resource.get-popular-search.query.label";
34: private static final String QUERIES_LABEL = "psadmin.subcommand.resource.get-popular-search.queries.label";
35:
36: /**
37: * process return value from MBean
38: * @param object
39: */
40: protected void handleReturnValue(Object object) {
41: StringBuffer sb = new StringBuffer();
42:
43: ArrayList data = (ArrayList) object;
44:
45: Integer totalQueries = (Integer) data.get(0);
46:
47: Date date = (Date) data.get(1);
48: DateFormat df = new SimpleDateFormat("EEE, MMM d, yyyy");
49:
50: if (totalQueries.intValue() == 1) {
51: sb.append(getLocalizedString(QUERY_LABEL, new Object[] {
52: totalQueries.toString(), df.format(date) }));
53: } else {
54: sb.append(getLocalizedString(QUERIES_LABEL, new Object[] {
55: totalQueries.toString(), df.format(date) }));
56: }
57:
58: sb.append("\n");
59:
60: ArrayList list = (ArrayList) data.get(2);
61: for (int index = 0; index < list.size(); index++) {
62: Properties p = (Properties) list.get(index);
63: sb.append(p.getProperty("frequency") + " - "
64: + p.getProperty("scope") + "\n");
65: }
66:
67: CLILogger.getInstance().printMessage(sb.toString());
68: }
69:
70: }
|