001    /**
002     * Copyright 2005-2013 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     */
016    package org.kuali.rice.kns.web.struts.config;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.apache.struts.config.ControllerConfig;
020    import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
021    import 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    public class KualiControllerConfig extends ControllerConfigWrapper {
029        public KualiControllerConfig(ControllerConfig config) {
030            super(config);
031        }
032    
033        /**
034         * Returns the global max file upload size, which is dynamically derived from the Rice parameter service.
035         * This technically breaks the implicit contract in ControllerConfig that the config is frozen after startup.
036         * @return the global max file upload size
037         */
038        @Override
039        public String getMaxFileSize() {
040            String maxFileSize = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsString(KRADConstants.KNS_NAMESPACE, KRADConstants.DetailTypes.ALL_DETAIL_TYPE, KRADConstants.MAX_UPLOAD_SIZE_PARM_NM);
041            if (StringUtils.isNotBlank(maxFileSize)) {
042                return maxFileSize;
043            }
044            return super.getMaxFileSize();
045        }
046    
047        /**
048         * Overridden to throw an UnsupportedOperationException.  Once our KualiControllerConfig is
049         * in place, it does not make sense to support this setter.
050         */
051        @Override
052        public void setMaxFileSize(String s) {
053            throw new UnsupportedOperationException("Cannot set max file size through KualiControllerConfig");
054        }
055    }