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.plugins.repository.jcr.SimpleAmetysObject;
021
022/**
023 * Catalog java object
024 */
025public class Catalog extends SimpleAmetysObject<CatalogFactory>
026{
027    /** code property. */
028    public static final String TITLE = "title";
029    
030    /** code property. */
031    public static final String IS_DEFAULT = "isDefault";
032    
033    /**
034     * Constructor
035     * @param node The JCR node
036     * @param parentPath The parent path
037     * @param catalogFactory the object factory
038     */
039    public Catalog(Node node, String parentPath, CatalogFactory catalogFactory)
040    {
041        super(node, parentPath, catalogFactory);
042    }
043
044    /**
045     * Get the title of catalog
046     * @return the title
047     */
048    public String getTitle()
049    {
050        return getMetadataHolder().getString(Catalog.TITLE);
051    }
052    
053    /**
054     * Set the title of catalog
055     * @param title the title to set
056     */
057    public void setTitle (String title)
058    {
059        getMetadataHolder().setMetadata(Catalog.TITLE, title);
060    }
061    
062    /**
063     * Set the default state of this catalog
064     * @param isDefault true to set this catalog as the default catalog
065     */
066    public void setDefault(boolean isDefault)
067    {
068        if (!isDefault && getMetadataHolder().hasMetadata(IS_DEFAULT))
069        {
070            getMetadataHolder().removeMetadata(IS_DEFAULT);
071        }
072        else if (isDefault)
073        {
074            getMetadataHolder().setMetadata(IS_DEFAULT, isDefault);
075        }
076    }
077    
078    /**
079     * Determines if this catalog is the default catalog
080     * @return true if the catalog is the default catalog
081     */
082    public boolean isDefault()
083    {
084        return getMetadataHolder().getBoolean(IS_DEFAULT, false);
085    }
086}