Export API
Contents
This API provides functions for creating and importing node-exports.
Usage
Add the following to your build.gradle
file:
dependencies {
include "com.enonic.xp:lib-export:${xpVersion}"
}
Add the import
statement to your controller:
import exportLib from '/lib/xp/export';
You are now ready to use the API.
Functions
exportNodes
Creates a node export. Export will be created in exports directory.
Parameters
An object with the following keys and their values:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sourceNodePath |
string |
Source nodes path |
||
exportName |
string |
Export name |
||
includeNodeIds |
boolean |
<optional> |
true |
Set to true to export node IDs |
includeVersions |
boolean |
<optional> |
false |
Set to true to export all node versions |
nodeResolved |
function |
<optional> |
A function to be called before export starts with number of nodes to export |
|
nodeExported |
function |
<optional> |
A function to be called during export with number of nodes exported since last call |
Returns
object : Node export results
Examples
import {exportNodes} from '/lib/xp/export';
// Export content nodes.
const exportNodes = exportNodes({
sourceNodePath: '/content',
exportName: 'export-1',
includeNodeIds: true,
includeVersions: true,
nodeExported: (i) => {
},
nodeResolved: (i) => {
}
});
// Information about exported nodes.
const expected = {
exportedNodes: [
'/content'
],
exportedBinaries: [
'binaryPath [ref]'
],
exportErrors: [
'some error'
]
};
importNodes
Imports nodes from a node export located in exports directory or from application resource files. Optionally pre-transforms node XML node files with XSLT before import.
During node export, current permissions are included in the export file. But when importing, you may need to apply permissions according to your new environment/parent permissions. includePermissions parameter is used to control this behavior. |
Parameters
An object with the following keys and their values:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
source |
string or object |
Either name of nodes-export located in exports directory or application resource key |
||
targetNodePath |
string |
Target path for imported nodes |
||
xslt |
string or object |
<optional> |
true |
XSLT file name in exports directory or application resource key. Used for XSLT transformation |
xsltParams |
object |
<optional> |
Parameters used in XSLT transformation |
|
includeNodeIds |
boolean |
<optional> |
false |
Set to |
includePermissions |
boolean |
<optional> |
false |
Set to |
nodeResolved |
function |
<optional> |
A function to be called during import with number of nodes imported since last call |
|
nodeImported |
function |
<optional> |
A function to be called during import with number of nodes imported since last call |
Returns
object : Node import results
Examples
import {importNodes} from '/lib/xp/export';
// Import from application resource files
const importedNodes = importNodes({
source: resolve('/import'),
targetNodePath: '/content',
xslt: 'transform.xslt',
xsltParams: {k: 'v'},
includeNodeIds: true,
includePermissions: true,
nodeImported: (i) => {
},
nodeResolved: (i) => {
}
});
import {importNodes} from '/lib/xp/export';
// Import from an export in exports directory
const importedNodes = importNodes({
source: 'export-1',
targetNodePath: '/content'
});
// Information about imported nodes.
const expected = {
addedNodes: [
'/added'
],
updatedNodes: [
'/updated'
],
importedBinaries: [
'binaryPath [ref]'
],
importErrors: [
{
exception: 'com.enonic.xp.lib.export.ImportHandlerTest$NoStacktraceException',
message: 'error',
stacktrace: []
}
]
};