01: /*
02: * Copyright 2006 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.util.List;
19:
20: import org.apache.slide.extractor.ExtractorException;
21: import org.apache.slide.extractor.SimpleXmlExtractor;
22: import org.jdom.Attribute;
23: import org.jdom.Text;
24:
25: /**
26: * Extract a list of URLs from an XML property, ensure they are properly encoded and provide
27: * a blank-separated list of them.
28: * @deprecated Use Hippo UrlListXMLPropertyExtractor
29: */
30: public class UrlListXMLPropertyExtractor extends SimpleXmlExtractor {
31:
32: protected static final String EMPTY = "";
33:
34: public UrlListXMLPropertyExtractor(String uri, String contentType,
35: String namespace) {
36: super (uri, contentType, namespace);
37: }
38:
39: protected Object filter(List nodeList, Instruction instruction)
40: throws ExtractorException {
41: if (nodeList.size() > 0) {
42: final StringBuffer result = new StringBuffer();
43: for (int i = 0; i < nodeList.size(); i++) {
44: Object next = null;
45: if (nodeList.get(i) instanceof Text) {
46: next = ((Text) nodeList.get(i)).getText();
47: } else if (nodeList.get(i) instanceof String) {
48: next = nodeList.get(i);
49: } else if (nodeList.get(i) instanceof Attribute) {
50: next = ((Attribute) nodeList.get(i)).getValue();
51: }
52: if (next != null) {
53: if (i > 0) {
54: result.append(" ");
55: }
56: result.append(next.toString().replace(' ', '+'));
57: }
58: }
59: return result.toString();
60: }
61: return EMPTY;
62: }
63: }
|