View Javadoc

1   /**
2    * Copyright 2005-2012 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.inquiry;
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.uif.view.View;
25  import org.kuali.rice.krad.uif.view.ViewPresentationControllerBase;
26  import org.kuali.rice.krad.util.KRADConstants;
27  import org.kuali.rice.krad.web.form.UifFormBase;
28  
29  /**
30   * Implementation of {@link org.kuali.rice.krad.uif.view.ViewPresentationController} for
31   * {@link InquiryView} instances
32   *
33   * <p>
34   * Adds flag for export of inquiry record
35   * </p>
36   *
37   * @author Kuali Rice Team (rice.collab@kuali.org)
38   */
39  public class InquiryViewPresentationControllerBase extends ViewPresentationControllerBase {
40      private static final long serialVersionUID = 7504225899471226403L;
41  
42      /**
43       * @see org.kuali.rice.krad.uif.view.ViewPresentationController#getActionFlags(org.kuali.rice.krad.uif.view.View,
44       * org.kuali.rice.krad.web.form.UifFormBase)
45       */
46      @Override
47      public Set<String> getActionFlags(View view, UifFormBase model) {
48          Set<String> actionFlags = super.getActionFlags(view, model);
49  
50          if (isExportSupported((InquiryView) model.getView())) {
51              actionFlags.add(KRADConstants.KUALI_ACTION_CAN_EXPORT);
52          }
53  
54          return actionFlags;
55      }
56  
57      /**
58       * Examines the data objects data dictionary entry to determine if it supports XML export or not
59       *
60       * @return boolean true if it supports export, false if not
61       */
62      protected boolean isExportSupported(InquiryView view) {
63          DataObjectEntry dataObjectEntry =
64                  KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary().getDataObjectEntry(
65                          view.getDataObjectClassName().getName());
66  
67          Class<? extends Exporter> exporterClass = dataObjectEntry.getExporterClass();
68          if (exporterClass != null) {
69              try {
70                  Exporter exporter = exporterClass.newInstance();
71                  if (exporter.getSupportedFormats(dataObjectEntry.getDataObjectClass()).contains(
72                          KRADConstants.XML_FORMAT)) {
73                      return true;
74                  }
75              } catch (Exception e) {
76                  throw new RuntimeException("Failed to locate or create exporter class: " + exporterClass);
77              }
78          }
79  
80          return false;
81      }
82  }