View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package com.isenshi.util.extlib;
17  
18  import org.apache.slide.content.NodeProperty;
19  import org.apache.slide.content.NodeProperty.NamespaceCache;
20  import org.apache.slide.search.basic.Literals;
21  import org.apache.slide.webdav.util.DaslConstants;
22  import org.apache.slide.webdav.util.WebdavConstants;
23  import org.jdom.Element;
24  import org.jdom.Namespace;
25  
26  public class SearchElement {
27  
28  	private static final Namespace DNSP = NodeProperty.NamespaceCache.DEFAULT_NAMESPACE;
29  
30  	private Element rootElement = new Element(DaslConstants.E_BASICSEARCH, DNSP);;
31  
32  	public SearchElement() {
33  		Element select = new Element(DaslConstants.E_SELECT, DNSP);
34  		rootElement.addContent(select);
35  		Element prop = new Element("prop", DNSP);
36  		select.addContent(prop);
37  	}
38  	
39  	public void addHref(String path){
40  		Element from = new Element(DaslConstants.E_FROM, DNSP);
41  		rootElement.addContent(from);
42  
43  		Element scope = new Element(DaslConstants.E_SCOPE, DNSP);
44  		from.addContent(scope);
45  		
46  		Element href = new Element("href", DNSP);
47  		scope.addContent(href);
48  		href.setText(path);
49  	}
50  
51  	public Element getRoot() {
52  		return rootElement;
53  	}
54  
55  	public void addSearchKeyword(String keyword) {
56  		Element where = new Element(DaslConstants.E_WHERE, DNSP);
57  		rootElement.addContent(where);
58  		Element contains = new Element(Literals.CONTAINS, DNSP);
59  		where.addContent(contains);
60  		contains.setText(keyword);
61  	}
62  
63  	
64  	public void addLimitElement(int limitSize) {
65  		Element limit = new Element(Literals.LIMIT, DNSP);
66  		rootElement.addContent(limit);
67  		Element nresults = new Element(Literals.NRESULTS, DNSP);
68  		nresults.setText(String.valueOf(limitSize));
69  		limit.addContent(nresults);
70  	}
71  
72  	public void addExcludedCollectionElement() {
73  		Element where = createWhereElement();
74  
75  		Element neq = new Element(Literals.NOT,
76  				NamespaceCache.DEFAULT_NAMESPACE);
77  		where.addContent(neq);
78  
79  		Element propcontains = new Element(DaslConstants.E_PROPCONTAINS,
80  				NamespaceCache.SLIDE_NAMESPACE);
81  		neq.addContent(propcontains);
82  		Element resourceTypeProp = new Element("prop", DNSP);
83  		propcontains.addContent(resourceTypeProp);
84  		Element resType = new Element(Literals.RESOURCETYPE, DNSP);
85  		resourceTypeProp.addContent(resType);
86  		Element literal = new Element(DaslConstants.E_LITERAL, DNSP);
87  		propcontains.addContent(literal);
88  		literal.setText("<collection/>");
89  	}
90  
91  	public void addOrderElement() {
92  		Element orderby = new Element(Literals.ORDERBY, DNSP);
93  		rootElement.addContent(orderby);
94  		Element order = new Element(Literals.ORDER, DNSP);
95  		orderby.addContent(order);
96  		Element orderProp = new Element(Literals.PROP, DNSP);
97  		order.addContent(orderProp);
98  		Element lastModified = new Element(WebdavConstants.P_CREATIONDATE,
99  				DNSP);
100 		Element isDescending = new Element(Literals.DESCENDING, DNSP);
101 		order.addContent(isDescending);
102 		orderProp.addContent(lastModified);
103 	}
104 
105 	private Element createWhereElement() {
106 		Element where = new Element(DaslConstants.E_WHERE, DNSP);
107 		rootElement.addContent(where);
108 		return where;
109 	}
110 
111 }