View Javadoc
1   /**
2    * Copyright 2004-2014 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.kpme.core.sys;
17  
18  
19  import java.io.IOException;
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import org.kuali.rice.krad.bo.ModuleConfiguration;
24  import org.kuali.rice.krad.datadictionary.DataDictionaryException;
25  import org.springframework.core.io.ClassPathResource;
26  import org.springframework.core.io.FileSystemResource;
27  import org.springframework.core.io.Resource;
28  import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
29  
30  public class KpmeModuleConfiguration extends ModuleConfiguration {
31      @Override
32      public void setDataDictionaryPackages(List<String> dataDictionaryPackages) {
33          this.trimList(dataDictionaryPackages);
34          //resolve individual xml files
35  
36          List<String> ddFiles = new ArrayList<String>();
37          for (String ddPackage : dataDictionaryPackages) {
38              if (ddPackage.contains("*")) {
39                  try {
40                      PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
41                      Resource[] resources = resolver.getResources(ddPackage);
42                      for (Resource resource : resources) {
43                          String prefix = "classpath:";
44                          if (resource instanceof FileSystemResource) {
45                              ddFiles.add("file:" + ((FileSystemResource)resource).getPath());
46                          } else if (resource instanceof ClassPathResource) {
47                              ddFiles.add("classpath:" + ((ClassPathResource)resource).getPath());
48                          } else {
49                              throw new DataDictionaryException("DD Resource " + resource.getFile().getPath() + " not found");
50                          }
51                      }
52                  } catch (IOException e) {
53                      throw new DataDictionaryException("DD Resource " + ddPackage + " not found");
54                  }
55              } else {
56                  ddFiles.add(ddPackage);
57              }
58          }
59          this.dataDictionaryPackages = ddFiles;
60      }
61  }