001/* 002 * Copyright 2010 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 */ 016 017package org.ametys.cms.content; 018 019import java.util.HashMap; 020import java.util.Map; 021 022import org.apache.avalon.framework.parameters.Parameters; 023import org.apache.cocoon.acting.AbstractAction; 024import org.apache.cocoon.environment.ObjectModelHelper; 025import org.apache.cocoon.environment.Redirector; 026import org.apache.cocoon.environment.Request; 027import org.apache.cocoon.environment.SourceResolver; 028 029import org.ametys.cms.repository.Content; 030 031/** 032 * Helper action for getting plugin names for content-types pipelines. 033 * The name is get either in request parameter or in request attribute. 034 */ 035public class GetContentTypeInformationAction extends AbstractAction 036{ 037 @Override 038 public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception 039 { 040 Map<String, String> result = new HashMap<>(); 041 042 Request request = ObjectModelHelper.getRequest(objectModel); 043 044 String pluginName = request.getParameter("pluginName"); 045 046 if (pluginName == null) 047 { 048 pluginName = (String) request.getAttribute("pluginName"); 049 } 050 051 result.put("pluginName", pluginName); 052 053 Content content = (Content) request.getAttribute(Content.class.getName()); 054 if (content != null && content.getLanguage() != null) 055 { 056 result.put("contentLanguage", content.getLanguage()); 057 } 058 059 return result; 060 } 061}