Search in sources :

Example 1 with PackageException

use of com.xpn.xwiki.plugin.packaging.PackageException in project xwiki-platform by xwiki.

the class Exporter method exportDocuments.

/**
 * Export documents from an existing loaded XWiki database. The database is defined by its passed name and by an
 * Hibernate configuration file.
 *
 * @param exportDirectory the directory where to export the documents
 * @param wikiId the wiki to export
 * @throws Exception if the export failed for any reason
 */
public void exportDocuments(File exportDirectory, String wikiId) throws Exception {
    WikiReference currentWikiReference = this.oldCoreHelper.getXWikiContext().getWikiReference();
    try {
        this.oldCoreHelper.getXWikiContext().setWikiId(wikiId);
        // TODO: Use Filter framework instead
        Package pack = new Package();
        pack.setWithVersions(false);
        pack.addAllWikiDocuments(this.oldCoreHelper.getXWikiContext());
        // See https://jira.xwiki.org/browse/XWIKI-458
        try {
            pack.exportToDir(exportDirectory, this.oldCoreHelper.getXWikiContext());
        } catch (IOException e) {
            throw new PackageException(PackageException.ERROR_PACKAGE_UNKNOWN, "Failed to export documents to [" + exportDirectory + "]", e);
        }
    } finally {
        this.oldCoreHelper.getXWikiContext().setWikiReference(currentWikiReference);
    }
}
Also used : PackageException(com.xpn.xwiki.plugin.packaging.PackageException) Package(com.xpn.xwiki.plugin.packaging.Package) IOException(java.io.IOException) WikiReference(org.xwiki.model.reference.WikiReference)

Example 2 with PackageException

use of com.xpn.xwiki.plugin.packaging.PackageException in project xwiki-platform by xwiki.

the class Importer method importDocuments.

/**
 * Import documents defined in an XML file located in the passed document definition directory into a database
 * defined by its passed name and by an Hibernate configuration file.
 * <p>
 * Note: I would have liked to call this method "import" but it's a reserved keyword... Strange that it's not
 * allowed for method names though.
 * </p>
 *
 * @param sourceDirectory the directory where the package.xml file is located and where the documents to import are
 *            located
 * @param wikiId id of the wiki into which to import the documents (e.g. {@code xwiki})
 * @param importUser optionally the user under which to perform the import (useful for example when importing pages
 *            that need to have Programming Rights and the page author is not the same as the importing user)
 * @throws Exception if the import failed for any reason
 */
// TODO: Replace the Hibernate config file with a list of parameters required for the import
public void importDocuments(File sourceDirectory, String wikiId, String importUser) throws Exception {
    Package pack = new Package();
    pack.setWithVersions(false);
    // See https://jira.xwiki.org/browse/XWIKI-458
    try {
        pack.readFromDir(sourceDirectory, this.oldCoreHelper.getXWikiContext());
    } catch (IOException e) {
        throw new PackageException(PackageException.ERROR_PACKAGE_UNKNOWN, "Failed to import documents from [" + sourceDirectory + "]", e);
    }
    installWithUser(importUser, pack, this.oldCoreHelper.getXWikiContext());
}
Also used : PackageException(com.xpn.xwiki.plugin.packaging.PackageException) Package(com.xpn.xwiki.plugin.packaging.Package) IOException(java.io.IOException)

Aggregations

Package (com.xpn.xwiki.plugin.packaging.Package)2 PackageException (com.xpn.xwiki.plugin.packaging.PackageException)2 IOException (java.io.IOException)2 WikiReference (org.xwiki.model.reference.WikiReference)1