Page 1 sur 1

Copie d'une base par DXL

MessagePublié: 16 Fév 2007 à 14:32
par billbock
import lotus.domino.*;

public class JavaAgent extends AgentBase
{
public void NotesMain()
{
DxlImporter importer = null;

try
{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();

// This is pretty much straight from the online help.
// Get current database
Database db = agentContext.getCurrentDatabase();
// Get DXL file
String filename = "C:\\ls06\\DXLCopy.xml";
Stream stream = session.createStream();
if (stream.open(filename) & (stream.getBytes() >0))
{
// Create new database - replace if it already exists
Database newdb = session.getDatabase(null, "DXLCopy.nsf");
if (newdb.isOpen())
newdb.remove();
DbDirectory dbdir = session.getDbDirectory(null);
newdb = dbdir.createDatabase("DXLCopy.nsf", true);
newdb.setTitle("Imported from DXL");

// Import DXL from file to new database
importer = session.createDxlImporter();

// By default, the Importer does NOT use database properties specified in the DXL to replace
// those in the database. When creating a new database, you usually do want it to.
importer.setReplaceDbProperties(true);

// The default ACL import option is DxlImporter.DXLIMPORTOPTION_IGNORE, meaning the
// Importer will not import the DXL acl. When creating a new database, you may want it to be
// imported, as we do here.
importer.setAclImportOption(DxlImporter.DXLIMPORTOPTION_REPLACE_ELSE_IGNORE);

// The default design note import option is DxlImporter.DXLIMPORTOPTION_IGNORE,
// meaning the Importer will not import design notes (only documents). In this case, we do
// want to create design notes as well.
importer.setDesignImportOption(DxlImporter.DXLIMPORTOPTION_CREATE);

// When using any REPLACE or UPDATE options, by default the Importer requires that the
// database replica ID matches the one in the DXL, to prevent accidental overwriting of data.
// In this case we are importing into a copy of a database, not a replica, so the replica IDs
// won't match. Thus we need this option to tell the Importer to replace/update anyway.
importer.setReplicaRequiredForReplaceOrUpdate(false);

importer.importDxl(stream, newdb);
}
else
System.out.println(filename + " does not exist or is empty");
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
// Print importer log
try
{
// IMPORTANT! On success or failure, there might be errors/warnings in the Importer log.
// You should always check the log. (The Exporter has a log as well.) When this agent is
// run from the Notes Client, this output will go to the Java debug console.
System.out.println(importer.getLog());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}