001/* 002 * Copyright 2017 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.plugins.frontedition; 017 018import java.util.Arrays; 019import java.util.Map; 020 021import org.apache.avalon.framework.service.ServiceException; 022import org.apache.avalon.framework.service.ServiceManager; 023 024import org.ametys.cms.repository.WorkflowAwareContent; 025import org.ametys.plugins.repository.version.VersionableAmetysObject; 026import org.ametys.web.renderingcontext.RenderingContext; 027import org.ametys.web.renderingcontext.RenderingContextHandler; 028import org.ametys.web.workflow.ValidateContentFunction; 029 030import com.opensymphony.module.propertyset.PropertySet; 031import com.opensymphony.workflow.WorkflowException; 032 033/** 034 * Validate a content only if the current context is the front 035 */ 036public class ValidateFrontContentFunction extends ValidateContentFunction 037{ 038 private RenderingContextHandler _renderingContextHandler; 039 040 @Override 041 public void service(ServiceManager manager) throws ServiceException 042 { 043 super.service(manager); 044 _renderingContextHandler = (RenderingContextHandler) manager.lookup(RenderingContextHandler.ROLE); 045 } 046 047 @Override 048 public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException 049 { 050 WorkflowAwareContent content = getContent(transientVars); 051 052 RenderingContext context = _renderingContextHandler.getRenderingContext(); 053 if (context == RenderingContext.FRONT && content instanceof VersionableAmetysObject) 054 { 055 String[] labels = ((VersionableAmetysObject) content).getLabels(); 056 if (Arrays.asList(labels).contains("live")) 057 { 058 super.execute(transientVars, args, ps); 059 } 060 } 061 } 062}