View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.authorization;
17  
18  import java.util.Set;
19  
20  import org.kuali.rice.krad.bo.Exporter;
21  import org.kuali.rice.krad.datadictionary.DataObjectEntry;
22  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23  import org.kuali.rice.krad.uif.view.InquiryView;
24  import org.kuali.rice.krad.util.KRADConstants;
25  import org.kuali.rice.krad.web.form.UifFormBase;
26  
27  /**
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class InquiryPresentationControllerBase extends ViewPresentationControllerBase {
31  
32      /**
33       * Prepares a list of action flags applicable for a inquiry
34       *
35       * @see ViewPresentationControllerBase#getActionFlags(org.kuali.rice.krad.web.spring.form.UifFormBase)
36       */
37      @Override
38      public Set<String> getActionFlags(UifFormBase model) {
39          Set<String> actionFlags = super.getActionFlags(model);
40  
41          if (isExportSupported((InquiryView) model.getView())) {
42              actionFlags.add(KRADConstants.KUALI_ACTION_CAN_EXPORT);
43          }
44  
45          return actionFlags;
46      }
47  
48      /**
49       * Examines the dataobjects's data dictionary entry to determine if it supports XML export or not
50       *
51       * @return boolean true if it supports export, false if not
52       */
53      protected boolean isExportSupported(InquiryView view) {
54          DataObjectEntry dataObjectEntry = KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary()
55                  .getDataObjectEntry(view.getDataObjectClassName().getName());
56  
57          Class<? extends Exporter> exporterClass = dataObjectEntry.getExporterClass();
58          if (exporterClass != null) {
59              try {
60                  Exporter exporter = exporterClass.newInstance();
61                  if (exporter.getSupportedFormats(dataObjectEntry.getDataObjectClass())
62                          .contains(KRADConstants.XML_FORMAT)) {
63                      return true;
64                  }
65              } catch (Exception e) {
66                  throw new RuntimeException("Failed to locate or create exporter class: " + exporterClass);
67              }
68          }
69  
70          return false;
71      }
72  }