01: /**
02: *
03: */package org.apache.slide.search.basic;
04:
05: import org.apache.slide.content.NodeProperty;
06: import org.apache.slide.search.BadQueryException;
07: import org.apache.slide.search.QueryScope;
08: import org.jdom.Element;
09: import org.jdom.Namespace;
10:
11: /**
12: * @author mpfingsthorn
13: *
14: */
15: public class LuceneBasicQueryScope extends BasicQueryScope {
16:
17: private static Namespace slideNamespace = NodeProperty.NamespaceCache
18: .getNamespace(NodeProperty.SLIDE_NAMESPACE);
19:
20: private int depth;
21: private int mindepth;
22:
23: /**
24: * Constructs a scope from e FROM element
25: *
26: * @param propertyName the name of the property
27: */
28: public LuceneBasicQueryScope(Element fromElement)
29: throws BadQueryException {
30: super (fromElement);
31:
32: // reparse depth
33:
34: Namespace namespace = fromElement.getNamespace();
35: String name = fromElement.getName();
36:
37: if (!(namespace.getURI().equals(NodeProperty.DEFAULT_NAMESPACE) && (name
38: .equals(Literals.FROM) || name.equals(Literals.SCOPE))))
39: throw new BadQueryException(
40: "expected DAV:from or DAV:scope");
41:
42: Element scope = null;
43: if (name.equals(Literals.FROM))
44: scope = fromElement.getChild(Literals.SCOPE, namespace);
45: else
46: scope = fromElement;
47:
48: Element depth = scope.getChild(Literals.DEPTH, namespace);
49: if (depth != null) {
50: String d = depth.getTextTrim();
51: try {
52: this .depth = Integer.parseInt(d);
53: if (this .depth < 0)
54: this .depth = 0;
55: } catch (Exception e) {
56: this .depth = QueryScope.DEPTH_INFINITY;
57: }
58: }
59:
60: this .mindepth = 0;
61: depth = scope.getChild("minimum-depth", slideNamespace);
62: if (depth != null) {
63: String d = depth.getTextTrim();
64: try {
65: this .mindepth = Integer.parseInt(d);
66: if (this .mindepth < 0)
67: this .mindepth = 0;
68: } catch (Exception e) {
69: this .mindepth = 0;
70: }
71: }
72: }
73:
74: /**
75: * depth accessor
76: *
77: * @return an int
78: *
79: */
80: public int getDepth() {
81: return depth;
82: }
83:
84: public int getMinDepth() {
85: return mindepth;
86: }
87: }
|