001/**
002 * Copyright 2005-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.kuali.rice.kns.web.struts.config;
017
018import org.apache.commons.lang.StringUtils;
019import org.apache.struts.config.ControllerConfig;
020import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
021import org.kuali.rice.krad.util.KRADConstants;
022
023/**
024 * Kuali customization of ControllerConfig which delegates max upload size lookup to
025 * parameter service: KRADConstants.KNS_NAMESPACE, KRADConstants.DetailTypes.ALL_DETAIL_TYPE, KRADConstants.MAX_UPLOAD_SIZE_PARM_NM
026 * The value must be a string compatible with Struts maxFileSize attribute.
027 *
028 * @deprecated KNS Struts deprecated, use KRAD and the Spring MVC framework.
029 */
030@Deprecated
031public class KualiControllerConfig extends ControllerConfigWrapper {
032    public KualiControllerConfig(ControllerConfig config) {
033        super(config);
034    }
035
036    /**
037     * Returns the global max file upload size, which is dynamically derived from the Rice parameter service.
038     * This technically breaks the implicit contract in ControllerConfig that the config is frozen after startup.
039     * @return the global max file upload size
040     */
041    @Override
042    public String getMaxFileSize() {
043        String maxFileSize = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(KRADConstants.KNS_NAMESPACE, KRADConstants.DetailTypes.ALL_DETAIL_TYPE, KRADConstants.MAX_UPLOAD_SIZE_PARM_NM);
044        if (StringUtils.isNotBlank(maxFileSize)) {
045            return maxFileSize;
046        }
047        return super.getMaxFileSize();
048    }
049
050    /**
051     * Overridden to throw an UnsupportedOperationException.  Once our KualiControllerConfig is
052     * in place, it does not make sense to support this setter.
053     */
054    @Override
055    public void setMaxFileSize(String s) {
056        throw new UnsupportedOperationException("Cannot set max file size through KualiControllerConfig");
057    }
058}