001/*
002 * (C) Copyright 2007 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 *
017 * $Id: DocumentBlob.java 13220 2007-03-03 18:45:30Z bstefanescu $
018 */
019
020package org.nuxeo.ecm.platform.api.ws;
021
022import java.io.IOException;
023import java.io.Serializable;
024
025import org.nuxeo.ecm.core.api.Blob;
026
027/**
028 * Web service document blob.
029 *
030 * @author <a href="mailto:ja@nuxeo.com">Julien Anguenot</a>
031 * @author <a href="mailto:td@nuxeo.com">Thierry Delprat</a>
032 */
033public class DocumentBlob implements Serializable {
034
035    private static final long serialVersionUID = 1L;
036
037    private String encoding;
038
039    private String mimeType;
040
041    private String[] extensions;
042
043    private String name;
044
045    private byte[] blob;
046
047    private String url;
048
049    /**
050     * Empty ctor needed by tools like jaxb.
051     */
052    public DocumentBlob() {
053    }
054
055    public DocumentBlob(String name, Blob blob) throws IOException {
056        this.blob = blob.getByteArray();
057        encoding = blob.getEncoding();
058        mimeType = blob.getMimeType();
059        this.name = name;
060    }
061
062    public DocumentBlob(String name, String encoding, String mimeType, String downloadUrl) {
063        this.name = name;
064        this.encoding = encoding;
065        this.mimeType = mimeType;
066        url = downloadUrl;
067    }
068
069    /**
070     * Returns the name of the document field name.
071     * <p>
072     * We probably need to embed the name along with the schema prefix.
073     *
074     * @return the name of the document field name
075     */
076    public String getName() {
077        return name;
078    }
079
080    /**
081     * Returns the main RFC-2046 mimetype name.
082     *
083     * @return the main RFC-2046 name
084     */
085    public String getMimetype() {
086        return mimeType;
087    }
088
089    /**
090     * Returns the encoding of the blob.
091     *
092     * @return the encoding of the blob
093     */
094    public String getEncoding() {
095        return encoding;
096    }
097
098    /**
099     * Returns the actual blob as a serializable input stream.
100     *
101     * @return the actual blob as a serializable input stream
102     */
103    public byte[] getBlob() {
104        return blob;
105    }
106
107    public void setExtensions(String[] extensions) {
108        this.extensions = extensions;
109    }
110
111    public String[] getExtensions() {
112        return extensions;
113    }
114
115    public void setBlob(byte[] blob) {
116        this.blob = blob;
117    }
118
119    public void setMimetype(String mimeType) {
120        this.mimeType = mimeType;
121    }
122
123    public void setEncoding(String encoding) {
124        this.encoding = encoding;
125    }
126
127    public void setName(String name) {
128        this.name = name;
129    }
130
131    public String getDownloadUrl() {
132        return url;
133    }
134
135    public String getMimeType() {
136        return mimeType;
137    }
138
139    public void setMimeType(String mimeType) {
140        this.mimeType = mimeType;
141    }
142
143    public String getUrl() {
144        return url;
145    }
146
147    public void setUrl(String url) {
148        this.url = url;
149    }
150
151}