001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.cms.impl;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.jboss.portal.cms.model.Content;
027: import org.jboss.portal.cms.util.FileUtil;
028:
029: import java.io.ByteArrayInputStream;
030: import java.io.InputStream;
031: import java.io.Serializable;
032: import java.io.UnsupportedEncodingException;
033: import java.util.Locale;
034:
035: /**
036: * CMS Version implementation.
037: *
038: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
039: * @author <a href="mailto:christophe.lombart@sword-technologies.com">Christophe Lombart</a>
040: */
041: public class ContentImpl extends CMSObjectImpl implements Content,
042: Serializable {
043: /** The serialVersionUID */
044: private static final long serialVersionUID = 4439612949586405113L;
045:
046: protected final static Log log = LogFactory
047: .getLog(ContentImpl.class);
048:
049: protected byte[] bytes;
050:
051: protected String encoding;
052:
053: protected boolean isLive;
054:
055: protected String versionNumber;
056:
057: protected Locale locale;
058:
059: protected String mimeType;
060:
061: protected int size;
062:
063: protected boolean isWaitingForPublishApproval = false;
064: protected String approvalProcessId = null;
065:
066: public String getTitle() {
067: return title;
068: }
069:
070: public void setTitle(String title) {
071: this .title = title;
072: }
073:
074: public String getDescription() {
075: return description;
076: }
077:
078: public void setDescription(String description) {
079: this .description = description;
080: }
081:
082: public Locale getLocale() {
083: return locale;
084: }
085:
086: public void setLocale(Locale locale) {
087: this .locale = locale;
088: }
089:
090: public String getVersionNumber() {
091: return versionNumber;
092: }
093:
094: public void setVersionNumber(String versionNumber) {
095: this .versionNumber = versionNumber;
096: }
097:
098: /** @return Returns the content. */
099: public InputStream getStream() {
100: return new ByteArrayInputStream(bytes);
101: }
102:
103: /** @return Returns the content. */
104: public byte[] getBytes() {
105: return bytes;
106: }
107:
108: public String getContentAsString() {
109: if (encoding != null) {
110: try {
111: return new String(bytes, encoding);
112: } catch (UnsupportedEncodingException e) {
113: }
114: }
115: return new String(bytes);
116: }
117:
118: /** @param stream The content to set. */
119: public void setStream(InputStream stream) {
120: bytes = FileUtil.getBytes(stream);
121: }
122:
123: /** @param bytes The content to set. */
124: public void setBytes(byte[] bytes) {
125: this .bytes = bytes;
126: }
127:
128: /** @return Returns the encoding. */
129: public String getEncoding() {
130: return encoding;
131: }
132:
133: /** @param encoding The encoding to set. */
134: public void setEncoding(String encoding) {
135: this .encoding = encoding;
136: }
137:
138: public boolean isLive() {
139: return isLive;
140: }
141:
142: public void setLive(boolean live) {
143: isLive = live;
144: }
145:
146: public int getSize() {
147: return this .size;
148: }
149:
150: public String getMimeType() {
151: return mimeType;
152: }
153:
154: public void setMimeType(String mimeType) {
155: this .mimeType = mimeType;
156: }
157:
158: public void setSize(int size) {
159: this .size = size;
160: }
161:
162: /**
163: *
164: */
165: public boolean isWaitingForPublishApproval() {
166: return this .isWaitingForPublishApproval;
167: }
168:
169: /** @param isWaitingForPublishApproval */
170: public void setWaitingForPublishApproval(
171: boolean isWaitingForPublishApproval) {
172: this .isWaitingForPublishApproval = isWaitingForPublishApproval;
173: }
174:
175: /** @return the approvalProcessId */
176: public String getApprovalProcessId() {
177: return approvalProcessId;
178: }
179:
180: /** @param approvalProcessId the approvalProcessId to set */
181: public void setApprovalProcessId(String approvalProcessId) {
182: this.approvalProcessId = approvalProcessId;
183: }
184: }
|