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 = new ArrayList<>();
029    private List<Content> _contents = new ArrayList<>();
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        _subList.add(subList);
059    }
060    /**
061     * Add contents in this group
062     * @param contents contents to add
063     */
064    public void addContents(List<Content> contents)
065    {
066        _contents.addAll(contents);
067    }
068    /**
069     * Add a content in this group
070     * @param content content to add
071     */
072    public void addContent(Content content)
073    {
074        _contents.add(content);
075    }
076    /**
077     * Get the sub groups in this group
078     * @return list of groups
079     */
080    public List<GroupSearchContent> getSubList()
081    {
082        return _subList;
083    }
084
085    /**
086     * Get the list of contents in this group
087     * @return list of contents in this group
088     */
089    public List<Content> getContents()
090    {
091        return _contents;
092    }
093
094    /**
095     * Get the value of the metadata (as a String) used to create this group
096     * @return Metadata value as a string
097     */
098    public String getGroupName()
099    {
100        return _groupName;
101    }
102
103    /**
104     * Get the metadataPath that was used to create this group
105     * @return metadataPath
106     */
107    public String getGroupFieldPath()
108    {
109        return _fieldPath;
110    }
111}