001/* 002 * Copyright 2011 Anyware Services 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 */ 016package org.ametys.web.synchronization; 017 018import java.util.Map; 019 020import javax.jcr.Node; 021import javax.jcr.RepositoryException; 022import javax.jcr.Session; 023 024import org.apache.commons.collections.PredicateUtils; 025 026import org.ametys.core.observation.Event; 027import org.ametys.core.observation.Observer; 028import org.ametys.web.ObservationConstants; 029import org.ametys.web.repository.sitemap.Sitemap; 030 031/** 032 * {@link Observer} for observing sitemap change in order to synchronize live workspace. 033 */ 034public class SynchronizeSitemapChangeObserver extends AbstractSynchronizeObserver 035{ 036 @Override 037 public boolean supports(Event event) 038 { 039 return event.getId().equals(ObservationConstants.EVENT_SITEMAP_UPDATED); 040 } 041 042 @Override 043 protected void _internalObserve(Event event, Session liveSession) throws RepositoryException 044 { 045 Map<String, Object> arguments = event.getArguments(); 046 Sitemap sitemap = (Sitemap) arguments.get(ObservationConstants.ARGS_SITEMAP); 047 048 Node sitemapNode = sitemap.getNode(); 049 String sitemapNodePath = sitemapNode.getPath(); 050 051 if (liveSession.itemExists(sitemapNodePath)) 052 { 053 Node clonedSitemapNode = (Node) liveSession.getItem(sitemapNodePath); 054 055 _synchronizeComponent.cloneNodeAndPreserveUUID(sitemapNode, clonedSitemapNode, PredicateUtils.truePredicate(), PredicateUtils.falsePredicate()); 056 057 liveSession.save(); 058 } 059 } 060}