View Javadoc

1   /*
2    * Copyright 2007 Hippo
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" 
12   * BASIS, 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.portal.cms.repository;
17  
18  import nl.hippo.client.api.content.Document;
19  
20  public class WebdavResource implements Comparable {
21  
22      private Document document;
23  
24      public WebdavResource(Document document){
25          this.document=document;
26      }
27      
28      public Document getDocument() {
29          return document;
30      }
31  
32      public boolean equals(Object o){
33          if (o instanceof WebdavResource){
34              return this.document.getPath().equals(((WebdavResource)o).getDocument().getPath());
35          } 
36          return false;
37      }
38      
39      public int compareTo(Object o) {
40          if (o instanceof WebdavResource){
41              Document otherDoc = ((WebdavResource)o).getDocument();
42              Integer thisInteger = this.document.getMetadata().getIndex();
43              Integer otherInteger = otherDoc.getMetadata().getIndex();
44              
45              if (thisInteger == null && otherInteger == null){
46                  return (this == o)?0:-1;
47              } else 
48              if (thisInteger == null){
49                  return 1;
50              } else 
51              if (otherInteger == null){
52                  return -1;
53              } else {
54                  return thisInteger.compareTo(otherInteger);
55              }
56          }            
57          return -1;
58      }
59      
60      
61  }