001/* 002 * (C) Copyright 2006-2012 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id$ 018 */package org.nuxeo.ecm.platform.importer.xml.parser; 019 020import java.io.IOException; 021import java.util.List; 022 023import org.nuxeo.ecm.core.api.CoreSession; 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.core.api.NuxeoException; 026import org.nuxeo.ecm.platform.importer.base.GenericMultiThreadedImporter; 027import org.nuxeo.ecm.platform.importer.factories.ImporterDocumentModelFactory; 028import org.nuxeo.ecm.platform.importer.source.FileSourceNode; 029import org.nuxeo.ecm.platform.importer.source.SourceNode; 030import org.nuxeo.ecm.platform.scanimporter.processor.ScanedFileFactory; 031import org.nuxeo.ecm.platform.scanimporter.processor.ScannedFileImporter; 032import org.nuxeo.ecm.platform.scanimporter.service.ImporterConfig; 033import org.nuxeo.runtime.api.Framework; 034 035/** 036 * Replace default XML Parser used into the Scan Importer service by the advanced one implemented into 037 * nuxeo-importer-xml-parser 038 * 039 * @author Benjamin JALON 040 */ 041public class AdvancedScannedFileFactory extends ScanedFileFactory implements ImporterDocumentModelFactory { 042 043 public AdvancedScannedFileFactory(ImporterConfig config) { 044 super(config); 045 } 046 047 protected static String targetContainerType = null; 048 049 protected ImporterConfig config; 050 051 @Override 052 public DocumentModel createLeafNode(CoreSession session, DocumentModel parent, SourceNode node) throws IOException { 053 054 XMLImporterService importer = Framework.getLocalService(XMLImporterService.class); 055 if (!(node instanceof FileSourceNode)) { 056 throw new NuxeoException("Waiting a FileSourceNode object not: " + node.getClass().getName()); 057 } 058 FileSourceNode fileNode = (FileSourceNode) node; 059 List<DocumentModel> docCreated = importer.importDocuments(parent, fileNode.getFile()); 060 061 if (docCreated == null || docCreated.size() < 1) { 062 return null; 063 } 064 065 ScannedFileImporter.addProcessedDescriptor(fileNode.getSourcePath()); 066 067 GenericMultiThreadedImporter.addCreatedDoc("_XMLimporter", docCreated.size() - 1); 068 return docCreated.get(0); 069 } 070}