001    /**
002     * Copyright (c) 2000-2012 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            public List<AssetCategory> getCategories() throws SystemException {
039                    return AssetCategoryLocalServiceUtil.getVocabularyCategories(
040                            getVocabularyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
041            }
042    
043            @Override
044            public String getSettings() {
045                    if (_settingsProperties == null) {
046                            return super.getSettings();
047                    }
048                    else {
049                            return _settingsProperties.toString();
050                    }
051            }
052    
053            public UnicodeProperties getSettingsProperties() {
054                    if (_settingsProperties == null) {
055                            _settingsProperties = new UnicodeProperties(true);
056    
057                            _settingsProperties.fastLoad(super.getSettings());
058                    }
059    
060                    return _settingsProperties;
061            }
062    
063            @Override
064            public String getTitle(String languageId) {
065                    String value = super.getTitle(languageId);
066    
067                    if (Validator.isNull(value)) {
068                            value = getName();
069                    }
070    
071                    return value;
072            }
073    
074            @Override
075            public String getTitle(String languageId, boolean useDefault) {
076                    String value = super.getTitle(languageId, useDefault);
077    
078                    if (Validator.isNull(value)) {
079                            value = getName();
080                    }
081    
082                    return value;
083            }
084    
085            public boolean isMultiValued() {
086                    if (Validator.isNull(_settingsProperties)) {
087                            _settingsProperties = getSettingsProperties();
088                    }
089    
090                    return GetterUtil.getBoolean(
091                            _settingsProperties.getProperty("multiValued"), true);
092            }
093    
094            public boolean isRequired(long classNameId) {
095                    if (Validator.isNull(_settingsProperties)) {
096                            _settingsProperties = getSettingsProperties();
097                    }
098    
099                    long[] requiredClassNameIds = StringUtil.split(
100                            _settingsProperties.getProperty("requiredClassNameIds"), 0L);
101    
102                    return ArrayUtil.contains(requiredClassNameIds, classNameId);
103            }
104    
105            @Override
106            public void setSettings(String settings) {
107                    _settingsProperties = null;
108    
109                    super.setSettings(settings);
110            }
111    
112            public void setSettingsProperties(UnicodeProperties settingsProperties) {
113                    _settingsProperties = settingsProperties;
114    
115                    super.setSettings(settingsProperties.toString());
116            }
117    
118            private UnicodeProperties _settingsProperties;
119    
120    }