1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.plugin;
16  
17  import com.liferay.portal.kernel.util.StringBundler;
18  import com.liferay.portal.kernel.util.StringPool;
19  import com.liferay.portal.kernel.util.Validator;
20  
21  import java.util.Iterator;
22  import java.util.Map;
23  import java.util.Set;
24  import java.util.TreeMap;
25  
26  /**
27   * <a href="RepositoryReport.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Jorge Ferrer
30   */
31  public class RepositoryReport {
32  
33      public static final String SUCCESS = "success";
34  
35      public void addSuccess(String repositoryURL) {
36          _reportMap.put(repositoryURL, SUCCESS);
37      }
38  
39      public void addError(String repositoryURL, PluginPackageException ppe) {
40          StringBundler sb = new StringBundler(3);
41  
42          if (Validator.isNotNull(ppe.getMessage())) {
43              sb.append(ppe.getMessage());
44          }
45  
46          if ((ppe.getCause() != null) &&
47              Validator.isNull(ppe.getCause().getMessage())) {
48  
49              sb.append(ppe.getCause().getMessage());
50          }
51  
52          if (sb.length() == 0) {
53              sb.append(ppe.toString());
54          }
55  
56          _reportMap.put(repositoryURL, sb.toString());
57      }
58  
59      public Set<String> getRepositoryURLs() {
60          return _reportMap.keySet();
61      }
62  
63      public String getState(String repositoryURL) {
64          return _reportMap.get(repositoryURL);
65      }
66  
67      public String toString() {
68          Iterator<String> itr = getRepositoryURLs().iterator();
69  
70          if (getRepositoryURLs().isEmpty()) {
71              return StringPool.BLANK;
72          }
73  
74          StringBundler sb = new StringBundler(getRepositoryURLs().size() * 3);
75  
76          while (itr.hasNext()) {
77              String repositoryURL = itr.next();
78  
79              sb.append(repositoryURL);
80              sb.append(": ");
81              sb.append(_reportMap.get(repositoryURL));
82          }
83  
84          return sb.toString();
85      }
86  
87      private Map<String, String> _reportMap = new TreeMap<String, String>();
88  
89  }