001/* 002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Olivier Grisel 018 */ 019package org.nuxeo.ecm.platform.categorization.listener; 020 021import java.util.Arrays; 022 023import org.apache.commons.logging.Log; 024import org.apache.commons.logging.LogFactory; 025import org.nuxeo.ecm.core.api.DocumentModel; 026import org.nuxeo.ecm.core.event.Event; 027import org.nuxeo.ecm.core.event.EventContext; 028import org.nuxeo.ecm.core.event.EventListener; 029import org.nuxeo.ecm.core.event.impl.DocumentEventContext; 030import org.nuxeo.ecm.platform.categorization.service.DocumentCategorizationService; 031import org.nuxeo.runtime.api.Framework; 032 033/** 034 * Base default implementation of a synchronous event listener that runs the document categorization service. 035 * 036 * @author ogrisel@nuxeo.com 037 */ 038public class DocumentCategorizationSyncListener implements EventListener { 039 040 public static final Log log = LogFactory.getLog(DocumentCategorizationSyncListener.class); 041 042 public void handleEvent(Event event) { 043 EventContext ctx = event.getContext(); 044 if (!(ctx instanceof DocumentEventContext)) { 045 return; 046 } 047 DocumentEventContext docCtx = (DocumentEventContext) ctx; 048 DocumentModel doc = docCtx.getSourceDocument(); 049 DocumentCategorizationService categorizationService = Framework.getService(DocumentCategorizationService.class); 050 categorizationService.updateCategories(Arrays.asList(doc)); 051 } 052 053}