001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.asset.model.impl;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryUtil;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.ArrayUtil;
020    import com.liferay.portal.kernel.util.GetterUtil;
021    import com.liferay.portal.kernel.util.StringUtil;
022    import com.liferay.portal.kernel.util.UnicodeProperties;
023    import com.liferay.portal.kernel.util.Validator;
024    import com.liferay.portlet.asset.model.AssetCategory;
025    import com.liferay.portlet.asset.service.AssetCategoryLocalServiceUtil;
026    
027    import java.util.List;
028    
029    /**
030     * @author Brian Wing Shun Chan
031     * @author Juan Fern??ndez
032     */
033    public class AssetVocabularyImpl extends AssetVocabularyBaseImpl {
034    
035            public AssetVocabularyImpl() {
036            }
037    
038            @Override
039            public List<AssetCategory> getCategories() throws SystemException {
040                    return AssetCategoryLocalServiceUtil.getVocabularyCategories(
041                            getVocabularyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
042            }
043    
044            @Override
045            public String getSettings() {
046                    if (_settingsProperties == null) {
047                            return super.getSettings();
048                    }
049                    else {
050                            return _settingsProperties.toString();
051                    }
052            }
053    
054            @Override
055            public UnicodeProperties getSettingsProperties() {
056                    if (_settingsProperties == null) {
057                            _settingsProperties = new UnicodeProperties(true);
058    
059                            _settingsProperties.fastLoad(super.getSettings());
060                    }
061    
062                    return _settingsProperties;
063            }
064    
065            @Override
066            public String getTitle(String languageId) {
067                    String value = super.getTitle(languageId);
068    
069                    if (Validator.isNull(value)) {
070                            value = getName();
071                    }
072    
073                    return value;
074            }
075    
076            @Override
077            public String getTitle(String languageId, boolean useDefault) {
078                    String value = super.getTitle(languageId, useDefault);
079    
080                    if (Validator.isNull(value)) {
081                            value = getName();
082                    }
083    
084                    return value;
085            }
086    
087            @Override
088            public boolean isMultiValued() {
089                    if (Validator.isNull(_settingsProperties)) {
090                            _settingsProperties = getSettingsProperties();
091                    }
092    
093                    return GetterUtil.getBoolean(
094                            _settingsProperties.getProperty("multiValued"), true);
095            }
096    
097            @Override
098            public boolean isRequired(long classNameId) {
099                    if (Validator.isNull(_settingsProperties)) {
100                            _settingsProperties = getSettingsProperties();
101                    }
102    
103                    long[] requiredClassNameIds = StringUtil.split(
104                            _settingsProperties.getProperty("requiredClassNameIds"), 0L);
105    
106                    return ArrayUtil.contains(requiredClassNameIds, classNameId);
107            }
108    
109            @Override
110            public void setSettings(String settings) {
111                    _settingsProperties = null;
112    
113                    super.setSettings(settings);
114            }
115    
116            @Override
117            public void setSettingsProperties(UnicodeProperties settingsProperties) {
118                    _settingsProperties = settingsProperties;
119    
120                    super.setSettings(settingsProperties.toString());
121            }
122    
123            private UnicodeProperties _settingsProperties;
124    
125    }