001/*
002 *  Copyright 2017 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.cms.search.cocoon;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import org.ametys.cms.repository.Content;
022
023/**
024 * Object created to group content, according to a metadata
025 */
026public class GroupSearchContent
027{
028    private List<GroupSearchContent> _subList;
029    private List<Content> _contents;
030    private String _groupName;
031    private String _fieldPath;
032    
033    /**
034     * Create a new empty group, only used for root
035     */
036    public GroupSearchContent()
037    {
038        this._fieldPath = "";
039        this._groupName = "";
040    }
041    /**
042     * Create a group, named after a metadataPath/name
043     * @param fieldPath path of the field used to create this group and siblings
044     * @param groupName value of the field for this group
045     */
046    public GroupSearchContent(String fieldPath, String groupName)
047    {
048        this._fieldPath = fieldPath;
049        this._groupName = groupName;
050    }
051
052    /**
053     * Add a sub group in this group
054     * @param subList sub-group
055     */
056    public void addToSubList(GroupSearchContent subList)
057    {
058        if (this._subList == null)
059        {
060            this._subList = new ArrayList<>();
061        }
062        this._subList.add(subList);
063    }
064    /**
065     * Add contents in this group
066     * @param contents contents to add
067     */
068    public void addContents(List<Content> contents)
069    {
070        if (this._contents == null)
071        {
072            this._contents = new ArrayList<>();
073        }
074        this._contents.addAll(contents);
075    }
076    /**
077     * Add a content in this group
078     * @param content content to add
079     */
080    public void addContent(Content content)
081    {
082        if (this._contents == null)
083        {
084            this._contents = new ArrayList<>();
085        }
086        this._contents.add(content);
087    }
088    /**
089     * Get the sub groups in this group
090     * @return list of groups
091     */
092    public List<GroupSearchContent> getSubList()
093    {
094        return _subList;
095    }
096
097    /**
098     * Get the list of contents in this group
099     * @return list of contents in this group
100     */
101    public List<Content> getContents()
102    {
103        return _contents;
104    }
105
106    /**
107     * Get the value of the metadata (as a String) used to create this group
108     * @return Metadata value as a string
109     */
110    public String getGroupName()
111    {
112        return _groupName;
113    }
114
115    /**
116     * Get the metadataPath that was used to create this group
117     * @return metadataPath
118     */
119    public String getGroupFieldPath()
120    {
121        return _fieldPath;
122    }
123}