001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.kernel.impl.operations;
007
008import java.io.InputStream;
009import java.net.URI;
010import java.util.Collection;
011
012import org.fcrepo.kernel.api.Transaction;
013import org.fcrepo.kernel.api.identifiers.FedoraId;
014import org.fcrepo.kernel.api.operations.NonRdfSourceOperation;
015
016/**
017 * An abstract operation for interacting with a non-rdf source
018 *
019 * @author bbpennel
020 */
021public abstract class AbstractNonRdfSourceOperation extends AbstractResourceOperation implements
022        NonRdfSourceOperation {
023
024    private InputStream content;
025
026    private URI externalHandlingURI;
027
028    private String externalHandlingType;
029
030    private String mimeType;
031
032    private String filename;
033
034    private Collection<URI> digests;
035
036    private long contentSize = -1;
037
038    /**
039     * Constructor for external content.
040     *
041     * @param rescId the internal identifier.
042     * @param externalContentURI the URI of the external content.
043     * @param externalHandling the type of external content handling (REDIRECT, PROXY)
044     */
045    protected AbstractNonRdfSourceOperation(final Transaction transaction, final FedoraId rescId,
046                                            final URI externalContentURI,
047                                            final String externalHandling) {
048        super(transaction, rescId);
049        this.externalHandlingURI = externalContentURI;
050        this.externalHandlingType = externalHandling;
051    }
052
053    /**
054     * Constructor for internal binaries.
055     *
056     * @param rescId the internal identifier.
057     * @param content the stream of the content.
058     */
059    protected AbstractNonRdfSourceOperation(final Transaction transaction, final FedoraId rescId,
060                                            final InputStream content) {
061        super(transaction, rescId);
062        this.content = content;
063    }
064
065    /**
066     * Basic constructor.
067     *
068     * @param rescId The internal Fedora ID.
069     */
070    protected AbstractNonRdfSourceOperation(final Transaction transaction, final FedoraId rescId) {
071        super(transaction, rescId);
072    }
073
074    @Override
075    public InputStream getContentStream() {
076        return content;
077    }
078
079    @Override
080    public String getExternalHandling() {
081        return externalHandlingType;
082    }
083
084    @Override
085    public URI getContentUri() {
086        return externalHandlingURI;
087    }
088
089    @Override
090    public String getMimeType() {
091        return mimeType;
092    }
093
094    @Override
095    public String getFilename() {
096        return filename;
097    }
098
099    @Override
100    public Collection<URI> getContentDigests() {
101        return digests;
102    }
103
104    @Override
105    public long getContentSize() {
106        return contentSize;
107    }
108
109    /**
110     * @return the content
111     */
112    protected InputStream getContent() {
113        return content;
114    }
115
116    /**
117     * @param content the content to set
118     */
119    protected void setContent(final InputStream content) {
120        this.content = content;
121    }
122
123    /**
124     * @return the externalHandlingURI
125     */
126    protected URI getExternalHandlingURI() {
127        return externalHandlingURI;
128    }
129
130    /**
131     * @param externalHandlingURI the externalHandlingURI to set
132     */
133    protected void setExternalHandlingURI(final URI externalHandlingURI) {
134        this.externalHandlingURI = externalHandlingURI;
135    }
136
137    /**
138     * @return the externalHandlingType
139     */
140    protected String getExternalHandlingType() {
141        return externalHandlingType;
142    }
143
144    /**
145     * @param externalHandlingType the externalHandlingType to set
146     */
147    protected void setExternalHandlingType(final String externalHandlingType) {
148        this.externalHandlingType = externalHandlingType;
149    }
150
151    /**
152     * @return the digests
153     */
154    protected Collection<URI> getDigests() {
155        return digests;
156    }
157
158    /**
159     * @param digests the digests to set
160     */
161    protected void setDigests(final Collection<URI> digests) {
162        this.digests = digests;
163    }
164
165    /**
166     * @param mimeType the mimeType to set
167     */
168    protected void setMimeType(final String mimeType) {
169        this.mimeType = mimeType;
170    }
171
172    /**
173     * @param filename the filename to set
174     */
175    protected void setFilename(final String filename) {
176        this.filename = filename;
177    }
178
179    /**
180     * @param contentSize the contentSize to set
181     */
182    protected void setContentSize(final long contentSize) {
183        this.contentSize = contentSize;
184    }
185}