001
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
029 public class RepositoryReport {
030
031 public static final String SUCCESS = "success";
032
033 public void addError(String repositoryURL, PluginPackageException ppe) {
034 StringBundler sb = new StringBundler(3);
035
036 if (Validator.isNotNull(ppe.getMessage())) {
037 sb.append(ppe.getMessage());
038 }
039
040 if ((ppe.getCause() != null) &&
041 Validator.isNull(ppe.getCause().getMessage())) {
042
043 sb.append(ppe.getCause().getMessage());
044 }
045
046 if (sb.length() == 0) {
047 sb.append(ppe.toString());
048 }
049
050 _reportMap.put(repositoryURL, sb.toString());
051 }
052
053 public void addSuccess(String repositoryURL) {
054 _reportMap.put(repositoryURL, SUCCESS);
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 @Override
066 public String toString() {
067 Iterator<String> itr = getRepositoryURLs().iterator();
068
069 if (getRepositoryURLs().isEmpty()) {
070 return StringPool.BLANK;
071 }
072
073 StringBundler sb = new StringBundler(getRepositoryURLs().size() * 3);
074
075 while (itr.hasNext()) {
076 String repositoryURL = itr.next();
077
078 sb.append(repositoryURL);
079 sb.append(": ");
080 sb.append(_reportMap.get(repositoryURL));
081 }
082
083 return sb.toString();
084 }
085
086 private Map<String, String> _reportMap = new TreeMap<String, String>();
087
088 }