001/* 002 * (C) Copyright 2010 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 * Olivier Grisel 016 */ 017package org.nuxeo.ecm.platform.categorization.listener; 018 019import java.util.Arrays; 020 021import org.apache.commons.logging.Log; 022import org.apache.commons.logging.LogFactory; 023import org.nuxeo.ecm.core.api.DocumentModel; 024import org.nuxeo.ecm.core.event.Event; 025import org.nuxeo.ecm.core.event.EventContext; 026import org.nuxeo.ecm.core.event.EventListener; 027import org.nuxeo.ecm.core.event.impl.DocumentEventContext; 028import org.nuxeo.ecm.platform.categorization.service.DocumentCategorizationService; 029import org.nuxeo.runtime.api.Framework; 030 031/** 032 * Base default implementation of a synchronous event listener that runs the document categorization service. 033 * 034 * @author ogrisel@nuxeo.com 035 */ 036public class DocumentCategorizationSyncListener implements EventListener { 037 038 public static final Log log = LogFactory.getLog(DocumentCategorizationSyncListener.class); 039 040 public void handleEvent(Event event) { 041 EventContext ctx = event.getContext(); 042 if (!(ctx instanceof DocumentEventContext)) { 043 return; 044 } 045 DocumentEventContext docCtx = (DocumentEventContext) ctx; 046 DocumentModel doc = docCtx.getSourceDocument(); 047 DocumentCategorizationService categorizationService = Framework.getService(DocumentCategorizationService.class); 048 categorizationService.updateCategories(Arrays.asList(doc)); 049 } 050 051}