001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.file;
029
030import org.opencms.util.CmsStringUtil;
031
032/**
033 * Describes where the binary content for a VFS resource is stored without loading the content bytes.<p>
034 */
035public class CmsStoredContentInfo {
036
037    /** The content hash. */
038    private final String m_hash;
039
040    /** The content length. */
041    private final long m_length;
042
043    /** The resource. */
044    private final CmsResource m_resource;
045
046    /** The storage identifier. */
047    private final String m_storage;
048
049    /**
050     * Creates a new stored content info instance.<p>
051     *
052     * @param resource the resource
053     * @param storage the storage identifier
054     * @param hash the content hash
055     * @param length the content length
056     */
057    public CmsStoredContentInfo(CmsResource resource, String storage, String hash, long length) {
058
059        m_resource = resource;
060        m_storage = storage;
061        m_hash = hash;
062        m_length = length;
063    }
064
065    /**
066     * Returns the content hash.<p>
067     *
068     * @return the content hash
069     */
070    public String getHash() {
071
072        return m_hash;
073    }
074
075    /**
076     * Returns the content length.<p>
077     *
078     * @return the content length
079     */
080    public long getLength() {
081
082        return m_length;
083    }
084
085    /**
086     * Returns the resource.<p>
087     *
088     * @return the resource
089     */
090    public CmsResource getResource() {
091
092        return m_resource;
093    }
094
095    /**
096     * Returns the storage identifier.<p>
097     *
098     * @return the storage identifier
099     */
100    public String getStorage() {
101
102        return m_storage;
103    }
104
105    /**
106     * Returns if the content is externally stored.<p>
107     *
108     * @return <code>true</code> if the content is externally stored
109     */
110    public boolean isExternallyStored() {
111
112        return CmsStringUtil.isNotEmpty(m_storage) && CmsStringUtil.isNotEmpty(m_hash);
113    }
114
115    /**
116     * Returns if the content is stored in the given storage backend.<p>
117     *
118     * @param storage the storage identifier
119     *
120     * @return <code>true</code> if the content is stored in the given storage backend
121     */
122    public boolean isStoredIn(String storage) {
123
124        return isExternallyStored() && m_storage.equals(storage);
125    }
126}