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.krad.inquiry;
017
018 import java.util.Set;
019
020 import org.kuali.rice.krad.bo.Exporter;
021 import org.kuali.rice.krad.datadictionary.DataObjectEntry;
022 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
023 import org.kuali.rice.krad.uif.view.InquiryView;
024 import org.kuali.rice.krad.uif.view.View;
025 import org.kuali.rice.krad.uif.view.ViewPresentationControllerBase;
026 import org.kuali.rice.krad.util.KRADConstants;
027 import org.kuali.rice.krad.web.form.UifFormBase;
028
029 /**
030 * Implementation of {@link org.kuali.rice.krad.uif.view.ViewPresentationController} for
031 * {@link InquiryView} instances
032 *
033 * <p>
034 * Adds flag for export of inquiry record
035 * </p>
036 *
037 * @author Kuali Rice Team (rice.collab@kuali.org)
038 */
039 public class InquiryViewPresentationControllerBase extends ViewPresentationControllerBase {
040 private static final long serialVersionUID = 7504225899471226403L;
041
042 /**
043 * @see org.kuali.rice.krad.uif.view.ViewPresentationController#getActionFlags(org.kuali.rice.krad.uif.view.View,
044 * org.kuali.rice.krad.web.form.UifFormBase)
045 */
046 @Override
047 public Set<String> getActionFlags(View view, UifFormBase model) {
048 Set<String> actionFlags = super.getActionFlags(view, model);
049
050 if (isExportSupported((InquiryView) model.getView())) {
051 actionFlags.add(KRADConstants.KUALI_ACTION_CAN_EXPORT);
052 }
053
054 return actionFlags;
055 }
056
057 /**
058 * Examines the data objects data dictionary entry to determine if it supports XML export or not
059 *
060 * @return boolean true if it supports export, false if not
061 */
062 protected boolean isExportSupported(InquiryView view) {
063 DataObjectEntry dataObjectEntry =
064 KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDataObjectEntry(
065 view.getDataObjectClassName().getName());
066
067 Class<? extends Exporter> exporterClass = dataObjectEntry.getExporterClass();
068 if (exporterClass != null) {
069 try {
070 Exporter exporter = exporterClass.newInstance();
071 if (exporter.getSupportedFormats(dataObjectEntry.getDataObjectClass()).contains(
072 KRADConstants.XML_FORMAT)) {
073 return true;
074 }
075 } catch (Exception e) {
076 throw new RuntimeException("Failed to locate or create exporter class: " + exporterClass);
077 }
078 }
079
080 return false;
081 }
082 }