Coverage Report - org.kuali.rice.kew.api.document.DocumentContent
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentContent
0%
0/34
0%
0/2
1.28
DocumentContent$1
N/A
N/A
1.28
DocumentContent$Builder
0%
0/34
0%
0/6
1.28
DocumentContent$Constants
0%
0/2
N/A
1.28
DocumentContent$Elements
0%
0/1
N/A
1.28
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl1.php
 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, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kew.api.document;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.Collection;
 20  
 
 21  
 import javax.xml.bind.annotation.XmlAccessType;
 22  
 import javax.xml.bind.annotation.XmlAccessorType;
 23  
 import javax.xml.bind.annotation.XmlAnyElement;
 24  
 import javax.xml.bind.annotation.XmlElement;
 25  
 import javax.xml.bind.annotation.XmlRootElement;
 26  
 import javax.xml.bind.annotation.XmlType;
 27  
 
 28  
 import org.apache.commons.lang.StringUtils;
 29  
 import org.apache.commons.lang.builder.EqualsBuilder;
 30  
 import org.apache.commons.lang.builder.HashCodeBuilder;
 31  
 import org.apache.commons.lang.builder.ToStringBuilder;
 32  
 import org.kuali.rice.core.api.CoreConstants;
 33  
 import org.kuali.rice.core.api.mo.ModelBuilder;
 34  
 import org.kuali.rice.core.api.mo.ModelObjectComplete;
 35  
 import org.kuali.rice.kew.api.KewApiConstants;
 36  
 import org.w3c.dom.Element;
 37  
 
 38  
 @XmlRootElement(name = DocumentContent.Constants.ROOT_ELEMENT_NAME)
 39  
 @XmlAccessorType(XmlAccessType.NONE)
 40  
 @XmlType(name = DocumentContent.Constants.TYPE_NAME, propOrder = {
 41  
     DocumentContent.Elements.DOCUMENT_ID,
 42  
     DocumentContent.Elements.APPLICATION_CONTENT,
 43  
     DocumentContent.Elements.ATTRIBUTE_CONTENT,
 44  
     DocumentContent.Elements.SEARCHABLE_CONTENT,
 45  
     DocumentContent.Elements.FORMAT_VERSION,
 46  
     CoreConstants.CommonElements.FUTURE_ELEMENTS
 47  
 })
 48  0
 public final class DocumentContent implements ModelObjectComplete, DocumentContentContract {
 49  
 
 50  
         private static final long serialVersionUID = 6110079520547685342L;
 51  
 
 52  
         @XmlElement(name = Elements.DOCUMENT_ID, required = true)
 53  
     private final String documentId;
 54  
     
 55  
         @XmlElement(name = Elements.APPLICATION_CONTENT, required = false)
 56  
     private final String applicationContent;
 57  
     
 58  
         @XmlElement(name = Elements.ATTRIBUTE_CONTENT, required = false)
 59  
     private final String attributeContent;
 60  
     
 61  
         @XmlElement(name = Elements.SEARCHABLE_CONTENT, required = false)
 62  
     private final String searchableContent;
 63  
     
 64  
         @XmlElement(name = Elements.FORMAT_VERSION, required = true)
 65  
     private final int formatVersion;
 66  
     
 67  0
         @SuppressWarnings("unused")
 68  
     @XmlAnyElement
 69  
     private final Collection<Element> _futureElements = null;
 70  
 
 71  
     /**
 72  
      * Private constructor used only by JAXB.
 73  
      * 
 74  
      */
 75  0
     private DocumentContent() {
 76  0
         this.documentId = null;
 77  0
         this.applicationContent = null;
 78  0
         this.attributeContent = null;
 79  0
         this.searchableContent = null;
 80  0
         this.formatVersion = 0;
 81  0
     }
 82  
 
 83  0
     private DocumentContent(Builder builder) {
 84  0
         this.documentId = builder.getDocumentId();
 85  0
         this.applicationContent = builder.getApplicationContent();
 86  0
         this.attributeContent = builder.getAttributeContent();
 87  0
         this.searchableContent = builder.getSearchableContent();
 88  0
         this.formatVersion = builder.getFormatVersion();
 89  0
     }
 90  
 
 91  
     @Override
 92  
     public String getDocumentId() {
 93  0
         return this.documentId;
 94  
     }
 95  
 
 96  
     @Override
 97  
     public String getApplicationContent() {
 98  0
         return this.applicationContent;
 99  
     }
 100  
 
 101  
     @Override
 102  
     public String getAttributeContent() {
 103  0
         return this.attributeContent;
 104  
     }
 105  
 
 106  
     @Override
 107  
     public String getSearchableContent() {
 108  0
         return this.searchableContent;
 109  
     }
 110  
 
 111  
     @Override
 112  
     public int getFormatVersion() {
 113  0
         return this.formatVersion;
 114  
     }
 115  
     
 116  
     public String getFullContent() {
 117  0
         StringBuilder fullContent = new StringBuilder();
 118  0
         fullContent.append("<").append(KewApiConstants.DOCUMENT_CONTENT_ELEMENT).append(">");
 119  0
         if (!StringUtils.isBlank(getApplicationContent())) {
 120  0
             fullContent.append("<").append(KewApiConstants.APPLICATION_CONTENT_ELEMENT).append(">");
 121  0
             fullContent.append(getApplicationContent());
 122  0
             fullContent.append("</").append(KewApiConstants.APPLICATION_CONTENT_ELEMENT).append(">");                
 123  
         }
 124  0
         fullContent.append(getAttributeContent());
 125  0
         fullContent.append(getSearchableContent());
 126  0
         fullContent.append("</").append(KewApiConstants.DOCUMENT_CONTENT_ELEMENT).append(">");
 127  0
         return fullContent.toString();
 128  
     }
 129  
 
 130  
     @Override
 131  
     public int hashCode() {
 132  0
         return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 133  
     }
 134  
 
 135  
     @Override
 136  
     public boolean equals(Object object) {
 137  0
         return EqualsBuilder.reflectionEquals(object, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
 138  
     }
 139  
 
 140  
     @Override
 141  
     public String toString() {
 142  0
         return ToStringBuilder.reflectionToString(this);
 143  
     }
 144  
 
 145  
 
 146  
     /**
 147  
      * A builder which can be used to construct {@link DocumentContent} instances.  Enforces the constraints of the {@link DocumentContentContract}.
 148  
      */
 149  0
     public final static class Builder implements Serializable, ModelBuilder, DocumentContentContract {
 150  
 
 151  
                 private static final long serialVersionUID = 7549637048594326790L;
 152  
 
 153  
                 private String documentId;
 154  
         private String applicationContent;
 155  
         private String attributeContent;
 156  
         private String searchableContent;
 157  
         private int formatVersion;
 158  
 
 159  0
         private Builder(String documentId) {
 160  0
             setDocumentId(documentId);
 161  0
             setFormatVersion(KewApiConstants.DocumentContentVersions.CURRENT);
 162  0
         }
 163  
 
 164  
         public static Builder create(String documentId) {
 165  0
             return new Builder(documentId);
 166  
         }
 167  
 
 168  
         public static Builder create(DocumentContentContract contract) {
 169  0
             if (contract == null) {
 170  0
                 throw new IllegalArgumentException("contract was null");
 171  
             }
 172  0
             Builder builder = create(contract.getDocumentId());
 173  0
             builder.setApplicationContent(contract.getApplicationContent());
 174  0
             builder.setAttributeContent(contract.getAttributeContent());
 175  0
             builder.setSearchableContent(contract.getSearchableContent());
 176  0
             builder.setFormatVersion(contract.getFormatVersion());
 177  0
             return builder;
 178  
         }
 179  
 
 180  
         public DocumentContent build() {
 181  0
             return new DocumentContent(this);
 182  
         }
 183  
 
 184  
         @Override
 185  
         public String getDocumentId() {
 186  0
             return this.documentId;
 187  
         }
 188  
 
 189  
         @Override
 190  
         public String getApplicationContent() {
 191  0
             return this.applicationContent;
 192  
         }
 193  
 
 194  
         @Override
 195  
         public String getAttributeContent() {
 196  0
             return this.attributeContent;
 197  
         }
 198  
 
 199  
         @Override
 200  
         public String getSearchableContent() {
 201  0
             return this.searchableContent;
 202  
         }
 203  
 
 204  
         @Override
 205  
         public int getFormatVersion() {
 206  0
             return this.formatVersion;
 207  
         }
 208  
 
 209  
         public void setDocumentId(String documentId) {
 210  0
             if (StringUtils.isBlank(documentId)) {
 211  0
                     throw new IllegalArgumentException("documentId was null or blank");
 212  
             }
 213  0
             this.documentId = documentId;
 214  0
         }
 215  
 
 216  
         public void setApplicationContent(String applicationContent) {
 217  0
             this.applicationContent = applicationContent;
 218  0
         }
 219  
 
 220  
         public void setAttributeContent(String attributeContent) {
 221  0
             this.attributeContent = attributeContent;
 222  0
         }
 223  
 
 224  
         public void setSearchableContent(String searchableContent) {
 225  0
             this.searchableContent = searchableContent;
 226  0
         }
 227  
 
 228  
         public void setFormatVersion(int formatVersion) {
 229  0
                 if (formatVersion < 0) {
 230  0
                         throw new IllegalArgumentException("formatVersion must be a valid version, was " + formatVersion);
 231  
                 }
 232  0
             this.formatVersion = formatVersion;
 233  0
         }
 234  
 
 235  
     }
 236  
 
 237  
     /**
 238  
      * Defines some internal constants used on this class.
 239  
      */
 240  0
     static class Constants {
 241  
 
 242  
         final static String ROOT_ELEMENT_NAME = "documentContent";
 243  
         final static String TYPE_NAME = "DocumentContentType";
 244  0
         final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] { CoreConstants.CommonElements.FUTURE_ELEMENTS };
 245  
 
 246  
     }
 247  
 
 248  
     /**
 249  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 250  
      */
 251  0
     static class Elements {
 252  
 
 253  
         final static String DOCUMENT_ID = "documentId";
 254  
         final static String APPLICATION_CONTENT = "applicationContent";
 255  
         final static String ATTRIBUTE_CONTENT = "attributeContent";
 256  
         final static String SEARCHABLE_CONTENT = "searchableContent";
 257  
         final static String FORMAT_VERSION = "formatVersion";
 258  
 
 259  
     }
 260  
 
 261  
 }
 262