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.plugins.workspaces.calendars.jcr;
017
018import javax.jcr.Node;
019
020import org.ametys.cms.data.holder.ModifiableIndexableDataHolder;
021import org.ametys.cms.data.holder.impl.DefaultModifiableModelAwareDataHolder;
022import org.ametys.plugins.repository.AmetysObject;
023import org.ametys.plugins.repository.data.repositorydata.ModifiableRepositoryData;
024import org.ametys.plugins.repository.data.repositorydata.impl.JCRRepositoryData;
025import org.ametys.plugins.repository.jcr.DefaultAmetysObject;
026import org.ametys.plugins.workspaces.calendars.Calendar;
027import org.ametys.plugins.workspaces.calendars.resources.CalendarResource;
028
029/**
030 * Default implementation of an {@link Calendar}, backed by a JCR node.<br>
031 */
032public class JCRCalendarResource extends DefaultAmetysObject<JCRCalendarResourceFactory> implements CalendarResource
033{
034    /** Attribute id */
035    public static final String ATTRIBUTE_CALENDAR_RESOURCE_ID = "calendarResourceId";
036    /** Attribute title */
037    public static final String ATTRIBUTE_TITLE = "title";
038    /** Attribute icon */
039    public static final String ATTRIBUTE_ICON = "icon";
040    /** Attribute instructions */
041    public static final String ATTRIBUTE_INSTRUCTIONS = "instructions";
042    
043    /**
044     * Creates an {@link JCRCalendarResource}.
045     * @param node the node backing this {@link AmetysObject}
046     * @param parentPath the parentPath in the Ametys hierarchy
047     * @param factory the DefaultAmetysObjectFactory which created the AmetysObject
048     */
049    public JCRCalendarResource(Node node, String parentPath, JCRCalendarResourceFactory factory)
050    {
051        super(node, parentPath, factory);
052    }
053
054    public String getTitle()
055    {
056        return getValue(ATTRIBUTE_TITLE);
057    }
058
059    public void setTitle(String title)
060    {
061        setValue(ATTRIBUTE_TITLE, title);
062    }
063
064    public String getInstructions()
065    {
066        return getValue(ATTRIBUTE_INSTRUCTIONS);
067    }
068
069    public void setInstructions(String instructions)
070    {
071        setValue(ATTRIBUTE_INSTRUCTIONS, instructions);
072    }
073
074    public String getIcon()
075    {
076        return getValue(ATTRIBUTE_ICON);
077    }
078
079    public void setIcon(String icon)
080    {
081        setValue(ATTRIBUTE_ICON, icon);
082    }
083    
084    public ModifiableIndexableDataHolder getDataHolder()
085    {
086        ModifiableRepositoryData repositoryData = new JCRRepositoryData(getNode());
087        return new DefaultModifiableModelAwareDataHolder(repositoryData, _getFactory().getCalendarResourceModel());
088    }
089
090    public String getCalendarResourceId()
091    {
092        return getValue(ATTRIBUTE_CALENDAR_RESOURCE_ID);
093    }
094    
095    public void setCalendarResourceId(String id)
096    {
097        setValue(ATTRIBUTE_CALENDAR_RESOURCE_ID, id);
098    }
099}