Introduce a simple Content API for usage by Version API's Resource
[smart-dao.git] / smart-version / smart-version-api / src / main / java / com / smartitengineering / version / api / impl / ResourceImpl.java
blob22e267020af7193d440344736261cebd79396a10
1 /*
2 * This is a common dao with basic CRUD operations and is not limited to any
3 * persistent layer implementation
4 *
5 * Copyright (C) 2008 Imran M Yousuf (imyousuf@smartitengineering.com)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 package com.smartitengineering.version.api.impl;
21 import com.smartitengineering.version.api.Content;
22 import com.smartitengineering.version.api.Resource;
23 import com.smartitengineering.version.api.spi.MutableResource;
24 import java.io.InputStream;
25 import org.apache.commons.lang.StringUtils;
27 /**
28 * Default implementation of resource
29 * @author imyousuf
31 public class ResourceImpl
32 implements Resource, MutableResource {
34 private String id;
35 private boolean deleted;
36 protected String mimeType;
37 protected Content content;
39 /**
40 * Get the value of mimeType
42 * @return the value of mimeType
44 public String getMimeType() {
45 return mimeType;
48 /**
49 * Set the value of mimeType
51 * @param mimeType new value of mimeType
53 public void setMimeType(String mimeType) {
54 this.mimeType = mimeType;
57 /**
58 * Get the value of deleted
60 * @return the value of deleted
62 public boolean isDeleted() {
63 return deleted;
66 /**
67 * Set the value of deleted
69 * @param deleted new value of deleted
71 public void setDeleted(boolean deleted) {
72 this.deleted = deleted;
75 /**
76 * Get the value of content
78 * @return the value of content
80 public String getContent() {
81 return content.getContent();
84 public InputStream getContentAsStream() {
85 return content.getContentAsStream();
88 public int getContentSize() {
89 return content.getContentSize();
92 public boolean isContentLoaded() {
93 return content.isContentLoaded();
96 /**
97 * Get the value of id
99 * @return the value of id
101 public String getId() {
102 return id;
106 * Set the value of id
108 * @param id new value of id
110 public void setId(String id) {
111 this.id = id;
114 public void setContent(Content content)
115 throws IllegalArgumentException {
116 if(content == null) {
117 throw new IllegalArgumentException();
119 this.content = content;
122 @Override
123 public boolean equals(Object obj) {
124 if(obj instanceof Resource) {
125 Resource resourceObj = (Resource) obj;
126 if(StringUtils.isNotBlank(getId())) {
127 return getId().equals(resourceObj.getId());
130 return super.equals(obj);
133 @Override
134 public int hashCode() {
135 if(StringUtils.isNotBlank(getId())) {
136 return getId().hashCode();
138 return super.hashCode();