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.client.webdav.binding.content;
17  
18  import nl.hippo.client.api.content.Document;
19  import nl.hippo.client.api.content.DocumentMetadata;
20  import nl.hippo.client.api.content.DocumentPath;
21  import nl.hippo.client.api.content.RawResponse;
22  
23  import org.apache.commons.lang.builder.EqualsBuilder;
24  import org.apache.commons.lang.builder.HashCodeBuilder;
25  import org.apache.commons.lang.builder.ToStringBuilder;
26  import org.apache.commons.lang.builder.ToStringStyle;
27  
28  /**
29   * Java binding for a document XML fragment
30   */
31  public class DocumentImpl implements Document {
32  
33      private static final long serialVersionUID = 1L;
34  
35      protected DocumentMetadata metadata;
36      protected RawResponse content;
37      protected DocumentPath path;
38  
39      //Temporary store for the documentpath & content
40      //The JIBX binder sets it and the DocumentFactory reads it in order to set the other fields 
41      //It should not be accessed in any other way
42      protected String tmpPath;
43      protected String tmpContent;
44  
45      //Private constructor: this class can only be instantiated by the jibx binder
46      private DocumentImpl() {
47      }
48  
49      protected DocumentImpl(DocumentPath path, DocumentMetadata metadata, RawResponse content) {
50          this.path = path;
51          this.metadata = metadata;
52          this.content = content;
53      }
54  
55      public RawResponse getContent() {
56          return content;
57      }
58  
59      public DocumentPath getPath() {
60          return path;
61      }
62  
63      public DocumentMetadata getMetadata() {
64          return metadata;
65      }
66  
67      public String toString() {
68          ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
69          .append("Path", path == null ? "null": path.getFullPath())
70          .append("Content", content == null ? "null": content.toString())
71          .append("Metadata", metadata == null ? "null" : metadata.toString());
72          return builder.toString();
73      }
74  
75      public boolean equals(Object obj) {
76          if (obj instanceof DocumentImpl == false) {
77              return false;
78            }
79            if (this == obj) {
80              return true;
81            }
82            DocumentImpl rhs = (DocumentImpl) obj;
83            return new EqualsBuilder()
84                          .append(content, rhs.content)
85                          .append(path, rhs.path)
86                          .append(metadata, rhs.metadata)
87                          .isEquals();
88      }
89  
90      public int hashCode() {
91          int hash = new HashCodeBuilder(17, 27)
92              .append(getPath())
93              .append(getContent())
94              .append(getMetadata())
95              .toHashCode();
96          return hash;
97      }
98  
99  }