001    /**
002     * Copyright (c) 2000-2010 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.util.Iterator;
022    import java.util.Map;
023    import java.util.Set;
024    import java.util.TreeMap;
025    
026    /**
027     * @author Jorge Ferrer
028     */
029    public class RepositoryReport {
030    
031            public static final String SUCCESS = "success";
032    
033            public void addSuccess(String repositoryURL) {
034                    _reportMap.put(repositoryURL, SUCCESS);
035            }
036    
037            public void addError(String repositoryURL, PluginPackageException ppe) {
038                    StringBundler sb = new StringBundler(3);
039    
040                    if (Validator.isNotNull(ppe.getMessage())) {
041                            sb.append(ppe.getMessage());
042                    }
043    
044                    if ((ppe.getCause() != null) &&
045                            Validator.isNull(ppe.getCause().getMessage())) {
046    
047                            sb.append(ppe.getCause().getMessage());
048                    }
049    
050                    if (sb.length() == 0) {
051                            sb.append(ppe.toString());
052                    }
053    
054                    _reportMap.put(repositoryURL, sb.toString());
055            }
056    
057            public Set<String> getRepositoryURLs() {
058                    return _reportMap.keySet();
059            }
060    
061            public String getState(String repositoryURL) {
062                    return _reportMap.get(repositoryURL);
063            }
064    
065            public String toString() {
066                    Iterator<String> itr = getRepositoryURLs().iterator();
067    
068                    if (getRepositoryURLs().isEmpty()) {
069                            return StringPool.BLANK;
070                    }
071    
072                    StringBundler sb = new StringBundler(getRepositoryURLs().size() * 3);
073    
074                    while (itr.hasNext()) {
075                            String repositoryURL = itr.next();
076    
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    }