1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.oodt.cas.crawl;
18
19
20 import org.apache.oodt.cas.metadata.MetExtractor;
21 import org.apache.oodt.cas.metadata.Metadata;
22 import org.apache.oodt.cas.metadata.exceptions.MetExtractionException;
23 import org.apache.oodt.cas.metadata.filenaming.NamingConvention;
24 import org.apache.oodt.cas.metadata.preconditions.PreConditionComparator;
25
26
27 import java.io.File;
28 import java.util.ArrayList;
29 import java.util.List;
30
31
32 import org.springframework.beans.factory.annotation.Required;
33
34
35
36
37
38
39
40
41
42
43
44 public class MetExtractorProductCrawler extends ProductCrawler {
45
46 private MetExtractor metExtractor;
47
48 private String metExtractorConfig;
49
50 private List<String> preCondIds = new ArrayList<String>();
51
52 private String namingConventionId;
53
54 @Override
55 protected Metadata getMetadataForProduct(File product) throws Exception {
56 return metExtractor.extractMetadata(product);
57 }
58
59 @Override
60 protected boolean passesPreconditions(File product) {
61 if (this.getPreCondIds() != null) {
62 for (String preCondId : this.getPreCondIds()) {
63 if (!((PreConditionComparator<?>) this.getApplicationContext()
64 .getBean(preCondId)).passes(product))
65 return false;
66 }
67 }
68 return product.exists() && product.length() > 0;
69 }
70
71 @Override
72 protected File renameProduct(File product, Metadata productMetadata)
73 throws Exception {
74 if (getNamingConventionId() != null) {
75 NamingConvention namingConvention = (NamingConvention)
76 getApplicationContext().getBean(getNamingConventionId());
77 if (namingConvention == null) {
78 throw new Exception("NamingConvention Id '" + getNamingConventionId()
79 + "' is not defined");
80 }
81 return namingConvention.rename(product, productMetadata);
82 } else {
83 return product;
84 }
85 }
86
87 @Required
88 public void setMetExtractor(String metExtractor)
89 throws MetExtractionException, InstantiationException,
90 IllegalAccessException, ClassNotFoundException {
91 this.metExtractor = (MetExtractor) Class.forName(metExtractor)
92 .newInstance();
93 if (metExtractorConfig != null && !metExtractorConfig.equals(""))
94 this.metExtractor.setConfigFile(metExtractorConfig);
95 }
96
97 @Required
98 public void setMetExtractorConfig(String metExtractorConfig)
99 throws MetExtractionException {
100 this.metExtractorConfig = metExtractorConfig;
101 if (this.metExtractor != null && metExtractorConfig != null
102 && !metExtractorConfig.equals(""))
103 this.metExtractor.setConfigFile(metExtractorConfig);
104 }
105
106 public List<String> getPreCondIds() {
107 return preCondIds;
108 }
109
110 public void setPreCondIds(List<String> preCondIds) {
111 this.preCondIds = preCondIds;
112 }
113
114 public void setNamingConventionId(String namingConventionId) {
115 this.namingConventionId = namingConventionId;
116 }
117
118 public String getNamingConventionId() {
119 return namingConventionId;
120 }
121 }