Magnolia 4.5 reached end of life on June 30, 2016. This branch is no longer supported, see End-of-life policy.
Importing and exporting content and data is useful when migrating content from one system to another, taking a backup or bringing in a custom taxonomy. The default file format for content exports is JCR System View XML. You can also export content hierarchies to a ZIP archive. The tools available range from a quick right-click export to scripting and writing custom import handlers depending on the frequency of use.
The file formats that can be used for imports and exports include:
website.demo-project.about.xml
. When used to export a node, the node's subnodes are also included.You can initiate imports and exports in AdminCentral with the context menu (right-click). This option is not available in all repositories.
If a node is selected when performing an import, then the imported node or data becomes children of the specified parent. If no node or data is specified, then the top imported node or data is included at the root of the repository or path into which the import is initiated.
To export XML:
If you right-click the white space on the page, the export includes all nodes. If you right-click on a node or data, the export includes that node or data and their children.
To import XML:
If a content node in the incoming has a unique ID (UUID) that is already used in the repository, the imported UUID will be changed.
You can upload a ZIP file in the Documents workspace. See the Export tool on how to export content to a ZIP file.
To import a ZIP file:
Use the import tool to import XML files to all repositories including those not available with the context menu.
To export:
To import:
This tool uses the Content Translation Support module to import and export page content in CSV and Excel formats. The module's documentation contains procedures for exporting and importing content into Magnolia as well as performing the translation.
When exported as a Google Spreadsheet, the translation will occur automatically when exported spreadsheet is opened in Google Docs.
You can export content from Magnolia using a simple Groovy script. This example exports the news-overview
page and children provided in demo-project
. This script performs the functionality equivalent to exporting to XML for the news-overview
node.
import info.magnolia.importexport.DataTransporter hm = ctx.getHierarchyManager('website') newsRoot = hm.getContent('/demo-project/news-and-events/news-overview') xmlFileOutput = new FileOutputStream('C:/test/export/news.xml') DataTransporter.executeExport(xmlFileOutput, false, false, hm.getWorkspace().getSession(), newsRoot.getHandle(), 'website', DataTransporter.XML) xmlFileOutput.close()
Similarly, you can import content with the following Groovy script. It imports the content exported for news-overview
and imports it into demo-project
. This script performs the functionality equivalent to right-clicking /demo-project/news-and-events
and importing the XML file.
import info.magnolia.importexport.DataTransporter import javax.jcr.ImportUUIDBehavior hm = ctx.getHierarchyManager('website') newsRoot = hm.getContent('/demo-project/news-and-events') xmlFile = new File('C:/test/export/news.xml') DataTransporter.importFile(xmlFile, 'website', newsRoot.getHandle(), false, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true, true)
For more information on Groovy see Groovy module documentation.
DataTransporter
API provides information on the parameters for the executeExport
and importFile
methods.
Import and export functionality is implemented in package info.magnolia.importexport
. This implementation is primarily contained within the DataTransporter
and PropertiesImportExport
classes. You can invoke methods in these classes from a custom class. An example for implementing the executeExport
method:
File xmlFile = new File(folder.getAbsoluteFile(), xmlName); FileOutputStream fos = new FileOutputStream(xmlFile); try { DataTransporter.executeExport(fos, false, false, MgnlContext.getHierarchyManager(repository).getWorkspace().getSession(), node.getHandle(), repository, DataTransporter.XML); } finally { IOUtils.closeQuietly(fos);}
These classes will not complete the import for any UUIDs that are identical to existing UUIDs.
Data and Content Translation Support modules include examples of commands that import and export content. The commands use an import handler that corresponds to the data type upon which the command is invoked. For example, CompanyImportHandler
is used to import company data while RSSFeedImportHandler
is used to import RSS aggregator data.
Both handlers extend the ImportHandler
class in the Data module. ImportHandler
provides the common functionality needed for all import handlers such as tracking configuration characteristics (repository, name, target). You can write your own import handler by extending the ImportHandler
class. In your custom handler, read the incoming data and assign it to parameters as configured in the data type. Implement the doImport
method to do the actual data processing such as parsing the incoming file.
See Importing data on how to configure an import handler in AdminCentral. Importers and exporters in Content Translation Support module is another example. These examples also show how an import handler can be periodically executed without a corresponding command. Using the Data module to import data gives an example of an import handler that is executed at the same time every night. This example includes a import handler implementation that parses and processes a non-XML file. This import handler implementation extends SimpleImportHandler
which in turn is an extension of ImportHandler
. The onDoImport
method needs to implemented when extending SimpleImportHandler
.
There are various operations in which importing and exporting can be helpful.
You can import DMS assets into Magnolia using the context menu as well as Import and export tool.
You can also use the packager module for DMS assets transfer. The dms
repository can be selected for populating a package. Assets can then be selected for inclusion in the package. The package containing the assets can be downloaded and uploaded to another Magnolia system for installation.
You can accomplish site migration in a number of ways.
You can back up content by exporting it to XML or ZIP and storing the files in a disaster recovery system. The name of the file containing the XML reflects the path of the exported data making identification easier.
You can also use the Packager module for backups. The name of the downloaded package can be set to indicate the date of the backup or some other type of identification. The packages can be stored in a DR system.
The Backup module is an alternative to file system and database backup solutions. The module features immediate interactive backup of JackRabbit backed repositories and scheduled recurring backup support with cron like configuration options.
The recommended procedure for importing tags depends on the size and format of the taxonomy as well as whether the taxonomy needs to be added once or repeatedly. Depending on your need, you can import the tags into the existing Category
data type or add a new data type.
If the taxonomy does not need to be added repeatedly you should enter the taxonomy manually in AdminCentral if the size and format is such that it can reasonably be manually entered.
To enter a taxonomy manually into the existing Category
data type:
Movies
branch with a genre scheme as children.If you prefer to create a new data type:
Movies
.If the taxonomy is too large to enter manually but needs to be entered only once then you should write a Groovy script to process a file containing the taxonomy.
Use a Groovy script to import a large taxonomy once:
data
instead of website
and root the path of the parent data type such as /movies
.Write an import handler to import a taxonomy repeatedly:
/modules/data/config/importers
with properties set to execute as needed.You can use the tags in an imported taxonomy to classify content once the import is completed. Keep in mind that the data type will not have functionality such as Category Cloud that are available with the example Category
data type. You can add such functionality by copy and customizing.
The new taxonomy can be used as options for some control types. For instance, you can use subtypes as options for radio
, checkbox
, and select
controls by setting the path
, repository
, valueNodeData
, and labelNodeData
properties. For the movies example, repository
would be set to data
and path
to /movies
. Assuming that a name
property is set for each movie category, you would set valueNodeData
and labelNodeData
to name
.