1   /*
2    * BibSonomyExporter
3    * Copyright (C) 2007 Christian Schenk
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    * 
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18   */
19  package org.christianschenk.bibsonomy.export;
20  
21  import java.util.List;
22  
23  import org.bibsonomy.common.enums.GroupID;
24  import org.bibsonomy.model.Group;
25  import org.bibsonomy.model.Tag;
26  
27  /**
28   * Some helper to transform information from BibSonomy into data that's
29   * compatible with the del.icio.us Java API.
30   * 
31   * @author Christian Schenk
32   */
33  public class BibSonomyHelper {
34  
35  	public static boolean getShared(final List<Group> groups) {
36  		for (final Group group : groups) {
37  			if (GroupID.isSpecialGroupId(group.getGroupId())) {
38  				return getShared(group.getName());
39  			}
40  		}
41  		return false;
42  	}
43  
44  	public static boolean getShared(final String groupName) {
45  		switch (GroupID.getSpecialGroup(groupName)) {
46  		case PUBLIC:
47  			return true;
48  		case PRIVATE:
49  		case FRIENDS:
50  			return false;
51  		default:
52  			throw new RuntimeException("Unknown group name '" + groupName + "'");
53  		}
54  	}
55  
56  	public static String getTags(final List<Tag> tags) {
57  		final StringBuffer buf = new StringBuffer();
58  		for (final Tag tag : tags) {
59  			buf.append(tag.getName() + " ");
60  		}
61  		return buf.toString().trim();
62  	}
63  
64  	public static String getTagsCommaSeparated(final List<Tag> tags) {
65  		return getTags(tags).replaceAll(" ", ",");
66  	}
67  }