1 20 21 package org.apache.directory.ldapstudio.browser.core.jobs; 22 23 24 import java.io.Reader ; 25 import java.io.StringReader ; 26 import java.io.Writer ; 27 import java.util.ArrayList ; 28 import java.util.List ; 29 30 import org.apache.commons.codec.digest.DigestUtils; 31 import org.apache.directory.ldapstudio.browser.core.BrowserCoreMessages; 32 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 33 import org.apache.directory.ldapstudio.browser.core.model.ldif.LdifEnumeration; 34 import org.apache.directory.ldapstudio.browser.core.model.ldif.parser.LdifParser; 35 36 37 public class ExecuteLdifJob extends AbstractEclipseJob 38 { 39 40 private IConnection connection; 41 42 private String ldif; 43 44 private boolean continueOnError; 45 46 47 public ExecuteLdifJob( IConnection connection, String ldif, boolean continueOnError ) 48 { 49 this.connection = connection; 50 this.ldif = ldif; 51 this.continueOnError = continueOnError; 52 53 setName( BrowserCoreMessages.jobs__execute_ldif_name ); 54 } 55 56 57 protected IConnection[] getConnections() 58 { 59 return new IConnection[] 60 { connection }; 61 } 62 63 64 protected Object [] getLockedObjects() 65 { 66 List l = new ArrayList (); 67 l.add( connection.getUrl() + "_" + DigestUtils.shaHex( ldif ) ); 68 return l.toArray(); 69 } 70 71 72 protected void executeAsyncJob( ExtendedProgressMonitor monitor ) 73 { 74 75 monitor.beginTask( BrowserCoreMessages.jobs__execute_ldif_task, 2 ); 76 monitor.reportProgress( " " ); monitor.worked( 1 ); 78 79 try 80 { 81 Reader ldifReader = new StringReader ( this.ldif ); 82 LdifParser parser = new LdifParser(); 83 LdifEnumeration enumeration = parser.parse( ldifReader ); 84 85 Writer logWriter = new Writer () 86 { 87 public void close() 88 { 89 } 90 91 92 public void flush() 93 { 94 } 95 96 97 public void write( char[] cbuf, int off, int len ) 98 { 99 } 100 }; 101 102 connection.importLdif( enumeration, logWriter, continueOnError, monitor ); 103 104 logWriter.close(); 105 ldifReader.close(); 106 } 107 catch ( Exception e ) 108 { 109 monitor.reportError( e ); 110 } 111 } 112 113 114 protected String getErrorMessage() 115 { 116 return BrowserCoreMessages.jobs__execute_ldif_error; 117 } 118 119 } 120 | Popular Tags |