~ubuntu-branches/ubuntu/wily/389-ds-console/wily-proposed

« back to all changes in this revision

Viewing changes to src/com/netscape/admin/dirserv/cmdln/DSCommandLine.java

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2012-03-15 19:58:37 UTC
  • Revision ID: package-import@ubuntu.com-20120315195837-296zyft51thld8q7
Tags: upstream-1.2.6
ImportĀ upstreamĀ versionĀ 1.2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** BEGIN COPYRIGHT BLOCK
 
2
 * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
 
3
 * Copyright (C) 2005 Red Hat, Inc.
 
4
 * All rights reserved.
 
5
 * 
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation version 2 of the License.
 
9
 * 
 
10
 * This program 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
 
13
 * GNU General Public License for more details.
 
14
 * 
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 * END COPYRIGHT BLOCK **/
 
19
 
 
20
package com.netscape.admin.dirserv.cmdln;
 
21
 
 
22
import javax.swing.UIManager;
 
23
import javax.swing.JFrame;
 
24
import com.netscape.management.client.console.ConsoleInfo;
 
25
import com.netscape.management.client.IPage;
 
26
import com.netscape.management.client.util.ResourceSet;
 
27
import com.netscape.management.client.util.Debug;
 
28
import com.netscape.management.client.comm.CommRecord;
 
29
import netscape.ldap.util.GetOpt;
 
30
import com.netscape.admin.dirserv.task.CGITask;
 
31
import com.netscape.admin.dirserv.DSUtil;
 
32
 
 
33
/**
 
34
 *      Netscape Admin Server 4.0 class for dealing with Directory Server
 
35
        commandine programs.
 
36
 *
 
37
 * @author  RJP
 
38
 * @version %I%, %G%
 
39
 * @date                1/15/98
 
40
 * @see     com.netscape.admin.dirserv.DSAdmin
 
41
 * @see     com.netscape.admin.dirserv.CGITask
 
42
 */
 
43
public class DSCommandLine extends CGITask {
 
44
        /**
 
45
         *      Constructor for the commandline utility
 
46
         */
 
47
        public DSCommandLine() {
 
48
                super();
 
49
 
 
50
                /* Set look and feel */
 
51
 
 
52
                try { 
 
53
                        UIManager.setLookAndFeel( "com.netscape.management.nmclf.SuiLookAndFeel" ); 
 
54
                } catch (Exception e) { 
 
55
                        System.err.println("Cannot load nmc look and feel."); 
 
56
                        System.exit(-1);
 
57
                } 
 
58
 
 
59
        }
 
60
 
 
61
        public boolean run (String operation) {
 
62
                /*_sCmd = "bin/shutdown?admin"*/
 
63
                _sCmd = "Tasks/Operation/" + operation;
 
64
 
 
65
                _consoleInfo = new ConsoleInfo();
 
66
                _consoleInfo.setAdminURL( "http://" + m_host + ":" + m_port + "/" );
 
67
                if (operation.equals("Start?InstanceName=slapd-" + m_instance)) {
 
68
                  _consoleInfo.put( "ServerInstance", "slapd" ) ;
 
69
                } else {
 
70
                  _consoleInfo.put( "ServerInstance", "slapd-" + m_instance ) ;
 
71
                }
 
72
                setAsync( true );
 
73
                return(super.run( (IPage)null ));
 
74
 
 
75
        }
 
76
 
 
77
 
 
78
        protected void showDialog( JFrame frame, String msg, String item,
 
79
                                   boolean error  ) {
 
80
                System.err.println( msg );
 
81
        }
 
82
 
 
83
        /**
 
84
         *      pass the username to the admin server
 
85
         */
 
86
        public String username(Object authObject, CommRecord cr) {
 
87
                return( m_username );
 
88
        }
 
89
        
 
90
        /**
 
91
         *      pass the user password to the admin server
 
92
         */
 
93
        public String password(Object authObject, CommRecord cr) {
 
94
                return( m_password );
 
95
        }
 
96
 
 
97
        /**
 
98
         * This function is to extract specified parameters from the
 
99
         * arguments list. Returns true if the user entered everything
 
100
         * correctly, false otherwise
 
101
         * @param args list of args
 
102
         */
 
103
        protected static GetOpt extractParameters(String privateOpts, String args[]) { 
 
104
                
 
105
                GetOpt options = new GetOpt("Hh:p:u:w:i:v" + privateOpts, args);
 
106
                
 
107
                /* -H Help */
 
108
                if (options.hasOption('H')) {
 
109
                        return (null);
 
110
                } /* Help */
 
111
  
 
112
                if (options.hasOption('v')) {
 
113
            _fTrace = true;
 
114
                        Debug.setTrace( true );
 
115
                }
 
116
 
 
117
                /* -h host */
 
118
                if (options.hasOption('h'))
 
119
                        m_host = options.getOptionParam('h');
 
120
                
 
121
                /* -p port */
 
122
                if (options.hasOption('p')) { /* if the option is -p */
 
123
                        try { 
 
124
                                m_port = Integer.parseInt(options.getOptionParam('p'));
 
125
                        } catch (NumberFormatException e) { 
 
126
                                System.err.println("Invalid Port");
 
127
                                System.exit(-1);
 
128
                        }
 
129
                } /* if the option is -p */
 
130
 
 
131
                /* -u username */
 
132
                if (options.hasOption('u'))
 
133
                        m_username = options.getOptionParam('u');
 
134
 
 
135
                /* -w password */
 
136
                if (options.hasOption('w'))
 
137
                        m_password = options.getOptionParam('w');
 
138
 
 
139
                /* -i instance */
 
140
                if (options.hasOption('i'))
 
141
                        m_instance = options.getOptionParam('i');
 
142
                
 
143
 
 
144
                if (m_host == null || m_port == 0 ||
 
145
                    m_username == null || m_password == null ||
 
146
                    m_instance == null) {
 
147
                  return (null);
 
148
                }
 
149
                
 
150
                return (options);
 
151
 
 
152
        }
 
153
        
 
154
        /**
 
155
         * Prints usage.
 
156
         */
 
157
        protected static void doUsage(String appname) {
 
158
                String msg = _resource.getString( "cmdln",
 
159
                                                                                  "usage-msg",
 
160
                                                                                  appname );
 
161
                System.out.println( msg );
 
162
        }
 
163
 
 
164
        /**
 
165
         * Print error message, using key from derived class
 
166
         */
 
167
        protected void printError( String arg ) {
 
168
                if ( _errorCode != 0 ) {
 
169
                        String msg = _resource.getString( "dirtask",
 
170
                                                                                          "error-" + _errorCode + "-msg",
 
171
                                                                                          arg );
 
172
                        System.err.println( msg );
 
173
                }
 
174
        }
 
175
 
 
176
        protected void printError() {
 
177
                printError( null );
 
178
        }
 
179
 
 
180
        /**
 
181
         * Internal variables
 
182
         */
 
183
        private static String m_host     = null;
 
184
        private static int    m_port     = 0;
 
185
        private static String m_username = null;
 
186
        private static String m_password = null;
 
187
        protected static String m_instance = null;
 
188
        protected static boolean _fTrace = false;
 
189
        protected static ResourceSet _resource = DSUtil._resource;
 
190
}