1 2 package org.apache.jetspeed.modules.actions; 3 4 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 21 public class ImportPsml extends org.apache.turbine.modules.Action 22 { 23 24 public static final String USER = "user"; 25 public static final String PASSWORD = "password"; 26 public static final String CHECK_IMPORT = "check-import"; 27 28 31 public void doPerform(RunData data) throws Exception 32 { 33 try 34 { 35 ParameterParser parser = data.getParameters(); 36 boolean checkImport = parser.getBoolean(CHECK_IMPORT, false); 39 40 String username = data.getUser().getUserName(); 42 if (!JetspeedSecurity.hasRole(username, "admin")) 43 { 44 data.setMessage("Only administrator can perform this action"); 45 throw new Exception ("Only administrator can perform this action"); 46 } 47 48 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 msg = "PSML Importer: error loading Psml Exporter Service"; 61 data.setMessage(msg); 62 Log.error(msg, e); 63 } 64 65 try 69 { 70 importerService = PsmlManager.getService(); 71 } 72 catch (org.apache.turbine.services.InstantiationException e) 73 { 74 String 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 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 msg = "**** PSML Importer - completed"; 93 System.out.println(msg); 94 data.setMessage(msg); 95 } 96 else 97 { 98 String msg = "**** PSML Importer - did not run"; 99 System.out.println(msg); 100 data.setMessage(msg); 101 } 102 } 103 catch (Exception e) 104 { 105 data.setMessage(e.getMessage()); 106 Log.error(e.getMessage()); 107 } 108 } 109 110 } | Popular Tags |