001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.plugin;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.Validator;
020    
021    import java.io.Serializable;
022    
023    import java.util.Map;
024    import java.util.Set;
025    import java.util.TreeMap;
026    
027    /**
028     * @author Jorge Ferrer
029     */
030    public class RepositoryReport implements Serializable {
031    
032            public static final String SUCCESS = "success";
033    
034            public void addError(String repositoryURL, PluginPackageException ppe) {
035                    StringBundler sb = new StringBundler(3);
036    
037                    if (Validator.isNotNull(ppe.getMessage())) {
038                            sb.append(ppe.getMessage());
039                    }
040    
041                    if ((ppe.getCause() != null) &&
042                            Validator.isNull(ppe.getCause().getMessage())) {
043    
044                            sb.append(ppe.getCause().getMessage());
045                    }
046    
047                    if (sb.length() == 0) {
048                            sb.append(ppe.toString());
049                    }
050    
051                    _reportMap.put(repositoryURL, sb.toString());
052            }
053    
054            public void addSuccess(String repositoryURL) {
055                    _reportMap.put(repositoryURL, SUCCESS);
056            }
057    
058            public Set<String> getRepositoryURLs() {
059                    return _reportMap.keySet();
060            }
061    
062            public String getState(String repositoryURL) {
063                    return _reportMap.get(repositoryURL);
064            }
065    
066            @Override
067            public String toString() {
068                    Set<String> repositoryURLs = getRepositoryURLs();
069    
070                    if (repositoryURLs.isEmpty()) {
071                            return StringPool.BLANK;
072                    }
073    
074                    StringBundler sb = new StringBundler(repositoryURLs.size() * 3);
075    
076                    for (String repositoryURL : repositoryURLs) {
077                            sb.append(repositoryURL);
078                            sb.append(": ");
079                            sb.append(_reportMap.get(repositoryURL));
080                    }
081    
082                    return sb.toString();
083            }
084    
085            private Map<String, String> _reportMap = new TreeMap<String, String>();
086    
087    }