001/* 002 * (C) Copyright 2006-2007 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 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.content.template.listener; 023 024import org.apache.commons.logging.Log; 025import org.apache.commons.logging.LogFactory; 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.core.api.NuxeoException; 028import org.nuxeo.ecm.core.api.event.DocumentEventTypes; 029import org.nuxeo.ecm.core.event.Event; 030import org.nuxeo.ecm.core.event.EventListener; 031import org.nuxeo.ecm.core.event.impl.DocumentEventContext; 032import org.nuxeo.ecm.platform.content.template.service.ContentTemplateService; 033import org.nuxeo.runtime.api.Framework; 034 035public class ContentCreationListener implements EventListener { 036 037 private static final Log log = LogFactory.getLog(ContentCreationListener.class); 038 039 public void handleEvent(Event event) { 040 041 DocumentEventContext docCtx = null; 042 if (event.getContext() instanceof DocumentEventContext) { 043 docCtx = (DocumentEventContext) event.getContext(); 044 } else { 045 return; 046 } 047 String eventId = event.getName(); 048 DocumentModel createdDocument = docCtx.getSourceDocument(); 049 050 if (eventId.equals(DocumentEventTypes.DOCUMENT_CREATED)) { 051 try { 052 Framework.getService(ContentTemplateService.class).executeFactoryForType(createdDocument); 053 } catch (NuxeoException e) { 054 log.error("Error while executing content factory for type " + createdDocument.getType(), e); 055 } 056 } 057 } 058 059}