001/*
002 * Licensed to DuraSpace under one or more contributor license agreements.
003 * See the NOTICE file distributed with this work for additional information
004 * regarding copyright ownership.
005 *
006 * DuraSpace licenses this file to you under the Apache License,
007 * Version 2.0 (the "License"); you may not use this file except in
008 * compliance with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.fcrepo.kernel.impl.operations;
019
020import java.io.InputStream;
021import java.net.URI;
022import java.util.Collection;
023
024import org.fcrepo.kernel.api.Transaction;
025import org.fcrepo.kernel.api.identifiers.FedoraId;
026import org.fcrepo.kernel.api.operations.NonRdfSourceOperation;
027
028/**
029 * An abstract operation for interacting with a non-rdf source
030 *
031 * @author bbpennel
032 */
033public abstract class AbstractNonRdfSourceOperation extends AbstractResourceOperation implements
034        NonRdfSourceOperation {
035
036    private InputStream content;
037
038    private URI externalHandlingURI;
039
040    private String externalHandlingType;
041
042    private String mimeType;
043
044    private String filename;
045
046    private Collection<URI> digests;
047
048    private long contentSize = -1;
049
050    /**
051     * Constructor for external content.
052     *
053     * @param rescId the internal identifier.
054     * @param externalContentURI the URI of the external content.
055     * @param externalHandling the type of external content handling (REDIRECT, PROXY)
056     */
057    protected AbstractNonRdfSourceOperation(final Transaction transaction, final FedoraId rescId,
058                                            final URI externalContentURI,
059                                            final String externalHandling) {
060        super(transaction, rescId);
061        this.externalHandlingURI = externalContentURI;
062        this.externalHandlingType = externalHandling;
063    }
064
065    /**
066     * Constructor for internal binaries.
067     *
068     * @param rescId the internal identifier.
069     * @param content the stream of the content.
070     */
071    protected AbstractNonRdfSourceOperation(final Transaction transaction, final FedoraId rescId,
072                                            final InputStream content) {
073        super(transaction, rescId);
074        this.content = content;
075    }
076
077    /**
078     * Basic constructor.
079     *
080     * @param rescId The internal Fedora ID.
081     */
082    protected AbstractNonRdfSourceOperation(final Transaction transaction, final FedoraId rescId) {
083        super(transaction, rescId);
084    }
085
086    @Override
087    public InputStream getContentStream() {
088        return content;
089    }
090
091    @Override
092    public String getExternalHandling() {
093        return externalHandlingType;
094    }
095
096    @Override
097    public URI getContentUri() {
098        return externalHandlingURI;
099    }
100
101    @Override
102    public String getMimeType() {
103        return mimeType;
104    }
105
106    @Override
107    public String getFilename() {
108        return filename;
109    }
110
111    @Override
112    public Collection<URI> getContentDigests() {
113        return digests;
114    }
115
116    @Override
117    public long getContentSize() {
118        return contentSize;
119    }
120
121    /**
122     * @return the content
123     */
124    protected InputStream getContent() {
125        return content;
126    }
127
128    /**
129     * @param content the content to set
130     */
131    protected void setContent(final InputStream content) {
132        this.content = content;
133    }
134
135    /**
136     * @return the externalHandlingURI
137     */
138    protected URI getExternalHandlingURI() {
139        return externalHandlingURI;
140    }
141
142    /**
143     * @param externalHandlingURI the externalHandlingURI to set
144     */
145    protected void setExternalHandlingURI(final URI externalHandlingURI) {
146        this.externalHandlingURI = externalHandlingURI;
147    }
148
149    /**
150     * @return the externalHandlingType
151     */
152    protected String getExternalHandlingType() {
153        return externalHandlingType;
154    }
155
156    /**
157     * @param externalHandlingType the externalHandlingType to set
158     */
159    protected void setExternalHandlingType(final String externalHandlingType) {
160        this.externalHandlingType = externalHandlingType;
161    }
162
163    /**
164     * @return the digests
165     */
166    protected Collection<URI> getDigests() {
167        return digests;
168    }
169
170    /**
171     * @param digests the digests to set
172     */
173    protected void setDigests(final Collection<URI> digests) {
174        this.digests = digests;
175    }
176
177    /**
178     * @param mimeType the mimeType to set
179     */
180    protected void setMimeType(final String mimeType) {
181        this.mimeType = mimeType;
182    }
183
184    /**
185     * @param filename the filename to set
186     */
187    protected void setFilename(final String filename) {
188        this.filename = filename;
189    }
190
191    /**
192     * @param contentSize the contentSize to set
193     */
194    protected void setContentSize(final long contentSize) {
195        this.contentSize = contentSize;
196    }
197}