KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > modules > actions > ImportPsml


1
2 package org.apache.jetspeed.modules.actions;
3
4 // jetspeed stuff
5
import org.apache.jetspeed.services.JetspeedSecurity;
6 import org.apache.jetspeed.services.PsmlManager;
7 import org.apache.jetspeed.services.psmlmanager.PsmlImporter;
8 import org.apache.jetspeed.services.psmlmanager.PsmlManagerService;
9 import org.apache.turbine.services.TurbineServices;
10 import org.apache.turbine.util.Log;
11 import org.apache.turbine.util.ParameterParser;
12 import org.apache.turbine.util.RunData;
13
14 /**
15  * Import file psml into database action. This action is useful when populating
16  * psml for the first time.
17  *
18  * @author <a HREF="mark_orciuch@ngsltd.com">Mark Orciuch</a>
19  * @version $Id: ImportPsml.java,v 1.1 2004/01/29 20:36:54 morciuch Exp $
20  */

21 public class ImportPsml extends org.apache.turbine.modules.Action
22 {
23
24     public static final String JavaDoc USER = "user";
25     public static final String JavaDoc PASSWORD = "password";
26     public static final String JavaDoc CHECK_IMPORT = "check-import";
27
28     /**
29      * Perform the action
30      */

31     public void doPerform(RunData data) throws Exception JavaDoc
32     {
33         try
34         {
35             ParameterParser parser = data.getParameters();
36             //String username = parser.getString(USER, "admin");
37
//String password = parser.getString(PASSWORD);
38
boolean checkImport = parser.getBoolean(CHECK_IMPORT, false);
39
40             //JetspeedUser admin = JetspeedSecurity.login(username, password);
41
String JavaDoc username = data.getUser().getUserName();
42             if (!JetspeedSecurity.hasRole(username, "admin"))
43             {
44                 data.setMessage("Only administrator can perform this action");
45                 throw new Exception JavaDoc("Only administrator can perform this action");
46             }
47
48             //
49
// get a handle to the exporter service
50
//
51
PsmlManagerService exporterService = null;
52             PsmlManagerService importerService = null;
53
54             try
55             {
56                 exporterService = (PsmlManagerService)TurbineServices.getInstance().getService("PsmlImportManager");
57             }
58             catch (org.apache.turbine.services.InstantiationException e)
59             {
60                 String JavaDoc msg = "PSML Importer: error loading Psml Exporter Service";
61                 data.setMessage(msg);
62                 Log.error(msg, e);
63             }
64
65             //
66
// get a handle to the importer service
67
//
68
try
69             {
70                 importerService = PsmlManager.getService();
71             }
72             catch (org.apache.turbine.services.InstantiationException e)
73             {
74                 String JavaDoc msg = "PSML Importer: error loading Psml Importer Service";
75                 data.setMessage(msg);
76                 Log.error(msg, e);
77             }
78
79             if (exporterService.getClass().getName().equals(importerService.getClass().getName()))
80             {
81                 String JavaDoc msg = "PSML Importer Error: Importer Class cannot equal Exporter Class.";
82                 data.setMessage(msg);
83                 Log.error(msg);
84             }
85
86             PsmlImporter importer = new PsmlImporter();
87             importer.setCheck(checkImport);
88             boolean ran = importer.run(exporterService, importerService);
89
90             if (ran)
91             {
92                 String JavaDoc msg = "**** PSML Importer - completed";
93                 System.out.println(msg);
94                 data.setMessage(msg);
95             }
96             else
97             {
98                 String JavaDoc msg = "**** PSML Importer - did not run";
99                 System.out.println(msg);
100                 data.setMessage(msg);
101             }
102         }
103         catch (Exception JavaDoc e)
104         {
105             data.setMessage(e.getMessage());
106             Log.error(e.getMessage());
107         }
108     }
109
110 }
Popular Tags