KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > admin > datasources > DatasourceAdminHelper


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Jan 23, 2006
14  * @author James Dixon
15  */

16
17 package org.pentaho.core.admin.datasources;
18
19 import org.pentaho.core.solution.IParameterProvider;
20 import org.pentaho.messages.Messages;
21
22 public class DatasourceAdminHelper {
23
24     public static int saveEdit(IParameterProvider parameters, ServerDatasourceAdmin dsAdmin) {
25         String JavaDoc dsName = parameters.getStringParameter("dsname", null); //$NON-NLS-1$
26
String JavaDoc url = parameters.getStringParameter("url", null); //$NON-NLS-1$
27
String JavaDoc driverName = parameters.getStringParameter("driver", null); //$NON-NLS-1$
28
String JavaDoc user = parameters.getStringParameter("user", null); //$NON-NLS-1$
29
String JavaDoc keepPassword = parameters.getStringParameter("keeppassword", null); //$NON-NLS-1$
30
String JavaDoc password = null;
31         int status = IDatasourceAdmin.DS_OPERATION_FAILED;
32         DataSourceInfo dsInfo = dsAdmin.getDataSourceInfo(dsName);
33         if ("on".equals(keepPassword) && dsName != null) { //$NON-NLS-1$
34
if (dsInfo != null) {
35                 password = dsInfo.getPassword();
36             }
37         } else {
38             password = parameters.getStringParameter("newpwd1", null); //$NON-NLS-1$
39
if (!password.equals(parameters.getStringParameter("newpwd2", null))) { //$NON-NLS-1$
40
password = null;
41             } else {
42             }
43         }
44         if (password != null) {
45             dsInfo.setDriver(driverName);
46             dsInfo.setPassword(password);
47             dsInfo.setUrl(url);
48             dsInfo.setUserId(user);
49             status = dsAdmin.saveDataSource(dsInfo, true);
50         }
51         return status;
52     }
53
54     public static final String JavaDoc getMessage(int status, String JavaDoc dsName) {
55         String JavaDoc message = ""; //$NON-NLS-1$
56
switch (status) {
57         case IDatasourceAdmin.DS_DELETED:
58             message = Messages.getString("DSAdminHelper.USER_DATASOURCE_DELETED") + dsName;break; //$NON-NLS-1$
59
case IDatasourceAdmin.DS_FILE_OPERATION_FAILED:
60             message = Messages.getString("DSAdminHelper.USER_FILE_ERROR");break; //$NON-NLS-1$
61
case IDatasourceAdmin.DS_NOT_FOUND:
62             message = Messages.getString("DSAdminHelper.USER_DATASOURCE_MISSING") + dsName;break; //$NON-NLS-1$
63
case IDatasourceAdmin.DS_OPERATION_FAILED:
64             message = Messages.getString("DSAdminHelper.USER_OPERATION_FAILED");break; //$NON-NLS-1$
65
case IDatasourceAdmin.DS_OPERATION_NOT_ALLOWED:
66             message = Messages.getString("DSAdminHelper.USER_OPERATION_NOT_ALLOWED");break; //$NON-NLS-1$
67
case IDatasourceAdmin.DS_RENAMED:
68             message = Messages.getString("DSAdminHelper.USER_DATASOURCE_RENAMED") + dsName;break; //$NON-NLS-1$
69
case IDatasourceAdmin.DS_SAVED:
70             message = Messages.getString("DSAdminHelper.USER_DATASOURCE_SAVED") + dsName;break; //$NON-NLS-1$
71
}
72         return message;
73     }
74
75 }
76
Popular Tags