Search in sources :

Example 1 with DocumentInfoAPI

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

the class ImportAction method importPackageOld.

private void importPackageOld(XWikiAttachment packFile, XWikiRequest request, XWikiContext context) throws IOException, XWikiException {
    PackageAPI importer = ((PackageAPI) context.getWiki().getPluginApi("package", context));
    String[] pages = request.getParameterValues("pages");
    importer.Import(packFile.getContentInputStream(context));
    if (pages != null) {
        // Skip document by default
        List<DocumentInfoAPI> filelist = importer.getFiles();
        for (DocumentInfoAPI dia : filelist) {
            dia.setAction(DocumentInfo.ACTION_SKIP);
        }
        // Indicate with documents to import
        for (String pageEntry : pages) {
            String language = getLocale(pageEntry, request);
            int iAction = getAction(pageEntry, language, request);
            String docName = getDocumentReference(pageEntry);
            if (language == null) {
                importer.setDocumentAction(docName, iAction);
            } else {
                importer.setDocumentAction(docName, language, iAction);
            }
        }
    }
    // Set the appropriate strategy to handle versions
    if (StringUtils.equals(request.getParameter("historyStrategy"), "reset")) {
        importer.setPreserveVersion(false);
        importer.setWithVersions(false);
    } else if (StringUtils.equals(request.getParameter("historyStrategy"), "replace")) {
        importer.setPreserveVersion(false);
        importer.setWithVersions(true);
    } else {
        importer.setPreserveVersion(true);
        importer.setWithVersions(false);
    }
    // Set the backup pack option
    if (StringUtils.equals(request.getParameter("importAsBackup"), "true")) {
        importer.setBackupPack(true);
    } else {
        importer.setBackupPack(false);
    }
    // Import files
    importer.install();
}
Also used : PackageAPI(com.xpn.xwiki.plugin.packaging.PackageAPI) DocumentInfoAPI(com.xpn.xwiki.plugin.packaging.DocumentInfoAPI)

Aggregations

DocumentInfoAPI (com.xpn.xwiki.plugin.packaging.DocumentInfoAPI)1 PackageAPI (com.xpn.xwiki.plugin.packaging.PackageAPI)1