001/* 002 * Copyright 2019 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.forms.workflow; 017 018import java.lang.management.ManagementFactory; 019import java.util.Collections; 020import java.util.Map; 021import java.util.Optional; 022 023import org.apache.avalon.framework.parameters.Parameters; 024import org.apache.cocoon.acting.AbstractAction; 025import org.apache.cocoon.environment.ObjectModelHelper; 026import org.apache.cocoon.environment.Redirector; 027import org.apache.cocoon.environment.SourceResolver; 028 029/** 030 * Set the last modified date for the form ribbon generated on the fly 031 */ 032public class FormRibbonSetLastModifiedAction extends AbstractAction 033{ 034 @SuppressWarnings("unchecked") 035 public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception 036 { 037 // Use Server startup time as "last modified", since ribbon.xml is generated from form workflows, read once at startup 038 Long serverStartupTime = ManagementFactory.getRuntimeMXBean().getStartTime(); 039 Optional.ofNullable(objectModel.get(ObjectModelHelper.PARENT_CONTEXT)) 040 .filter(Map.class::isInstance) 041 .map(Map.class::cast) 042 .ifPresent(params -> params.put("lastModified", serverStartupTime)); 043 return Collections.emptyMap(); 044 } 045}