01: /*
02: * Copyright 2004 Hippo Webworks.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 nl.hippo.slide.extractor;
17:
18: import java.io.InputStream;
19: import java.util.Enumeration;
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: import org.apache.slide.common.PropertyName;
24: import org.apache.slide.extractor.AbstractPropertyExtractor;
25: import org.apache.slide.extractor.ExtractorException;
26: import org.apache.slide.util.conf.Configurable;
27: import org.apache.slide.util.conf.Configuration;
28: import org.apache.slide.util.conf.ConfigurationException;
29:
30: /**
31: * Put constant properties on a document (like cms:type = asset in files/domain.preview/binaries).
32: */
33: public class ConstantExtractor extends AbstractPropertyExtractor
34: implements Configurable {
35: private Map properties = new HashMap();
36:
37: public ConstantExtractor(String namespace, String uri,
38: String contentType) {
39: super (namespace, uri, contentType);
40: }
41:
42: public Map extract(InputStream content) throws ExtractorException {
43: return properties;
44: }
45:
46: public void configure(Configuration configuration)
47: throws ConfigurationException {
48: Enumeration instructions = configuration
49: .getConfigurations("instruction");
50:
51: while (instructions.hasMoreElements()) {
52: Configuration instruction = (Configuration) instructions
53: .nextElement();
54: PropertyName propertyName = new PropertyName(instruction
55: .getAttribute("property"), instruction
56: .getAttribute("namespace", "DAV:"));
57:
58: String value = instruction.getAttribute("value", "");
59:
60: properties.put(propertyName, value);
61: }
62: }
63: }
|