001/*
002 *  Copyright 2014 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.odf.catalog;
017
018import javax.jcr.Node;
019
020import org.ametys.cms.data.ametysobject.ModifiableModelAwareDataAwareAmetysObject;
021import org.ametys.cms.data.holder.ModifiableIndexableDataHolder;
022import org.ametys.cms.data.holder.impl.DefaultModifiableModelAwareDataHolder;
023import org.ametys.plugins.repository.data.repositorydata.impl.JCRRepositoryData;
024import org.ametys.plugins.repository.jcr.SimpleAmetysObject;
025
026/**
027 * Catalog java object
028 */
029public class Catalog extends SimpleAmetysObject<CatalogFactory> implements ModifiableModelAwareDataAwareAmetysObject
030{
031    /**
032     * Constructor
033     * @param node The JCR node
034     * @param parentPath The parent path
035     * @param catalogFactory the object factory
036     */
037    public Catalog(Node node, String parentPath, CatalogFactory catalogFactory)
038    {
039        super(node, parentPath, catalogFactory);
040    }
041
042    /**
043     * Get the title of catalog
044     * @return the title
045     */
046    public String getTitle()
047    {
048        return getValue(CatalogModel.TITLE);
049    }
050    
051    /**
052     * Set the title of catalog
053     * @param title the title to set
054     */
055    public void setTitle (String title)
056    {
057        setValue(CatalogModel.TITLE, title);
058    }
059    
060    /**
061     * Set the default state of this catalog
062     * @param isDefault true to set this catalog as the default catalog
063     */
064    public void setDefault(boolean isDefault)
065    {
066        setValue(CatalogModel.IS_DEFAULT, isDefault);
067    }
068    
069    /**
070     * Determines if this catalog is the default catalog
071     * @return true if the catalog is the default catalog
072     */
073    public boolean isDefault()
074    {
075        return getValue(CatalogModel.IS_DEFAULT, false, false);
076    }
077
078    public ModifiableIndexableDataHolder getDataHolder()
079    {
080        JCRRepositoryData repositoryData = new JCRRepositoryData(getNode());
081        return new DefaultModifiableModelAwareDataHolder(repositoryData, _getFactory().getModel());
082    }
083}