001/******************************************************************************* 002 * Copyright (c) 2006-2013 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 *******************************************************************************/ 009/** 010 * 011 */ 012 013package org.nuxeo.ecm.core.model; 014 015import org.nuxeo.ecm.core.api.event.CoreEventConstants; 016import org.nuxeo.ecm.core.event.Event; 017import org.nuxeo.ecm.core.event.EventListener; 018import org.nuxeo.ecm.core.event.impl.DocumentEventContext; 019 020/** 021 * @author Stephane Lacoin at Nuxeo (aka matic) 022 */ 023public class DuplicatedNameFixer implements EventListener { 024 025 @Override 026 public void handleEvent(Event event) { 027 DocumentEventContext context = (DocumentEventContext) event.getContext(); 028 Boolean destinationExists = (Boolean) context.getProperty(CoreEventConstants.DESTINATION_EXISTS); 029 if (!destinationExists) { 030 return; 031 } 032 String name = (String) context.getProperty(CoreEventConstants.DESTINATION_NAME); 033 name += '.' + String.valueOf(System.currentTimeMillis()); 034 context.setProperty(CoreEventConstants.DESTINATION_NAME, name); 035 } 036 037}