Skip to content

Commit f8da659

Browse files
Waldemar Billerzesaro
authored andcommitted
copy bibsonomy-jabref-plugin to jabref
1 parent 4363f7e commit f8da659

File tree

61 files changed

+5967
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5967
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
*
3+
* JabRef Bibsonomy Plug-in - Plugin for the reference management
4+
* software JabRef (http://jabref.sourceforge.net/)
5+
* to fetch, store and delete entries from BibSonomy.
6+
*
7+
* Copyright (C) 2008 - 2011 Knowledge & Data Engineering Group,
8+
* University of Kassel, Germany
9+
* http://www.kde.cs.uni-kassel.de/
10+
*
11+
* This program is free software; you can redistribute it and/or
12+
* modify it under the terms of the GNU General Public License
13+
* as published by the Free Software Foundation; either version 2
14+
* of the License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24+
*/
25+
26+
package org.bibsonomy.plugin.jabref;
27+
28+
/**
29+
* Provide some default values for configuration of the plugin.
30+
* @author Waldemar Biller <[email protected]>
31+
*
32+
*/
33+
public class PluginGlobals {
34+
35+
public static final String PLUGIN_NAME = "BibSonomy";
36+
37+
public static final String API_URL = "http://www.bibsonomy.org/api/";
38+
39+
public static final String API_USERNAME = "jabreftest";
40+
41+
public static final String API_KEY = "4cc8425ab4dfcce2c5d1b5a96d2c7134";
42+
43+
public static final String PLUGIN_NUMBER_OF_POSTS_PER_REQUEST = "20";
44+
45+
public static final String PLUGIN_FILE_DIRECTORY = System.getProperty("user.dir");
46+
}
Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
/**
2+
*
3+
* JabRef Bibsonomy Plug-in - Plugin for the reference management
4+
* software JabRef (http://jabref.sourceforge.net/)
5+
* to fetch, store and delete entries from BibSonomy.
6+
*
7+
* Copyright (C) 2008 - 2011 Knowledge & Data Engineering Group,
8+
* University of Kassel, Germany
9+
* http://www.kde.cs.uni-kassel.de/
10+
*
11+
* This program is free software; you can redistribute it and/or
12+
* modify it under the terms of the GNU General Public License
13+
* as published by the Free Software Foundation; either version 2
14+
* of the License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24+
*/
25+
26+
package org.bibsonomy.plugin.jabref;
27+
28+
import java.io.File;
29+
import java.io.FileInputStream;
30+
import java.io.FileOutputStream;
31+
import java.util.Properties;
32+
33+
import org.apache.commons.logging.Log;
34+
import org.apache.commons.logging.LogFactory;
35+
import org.bibsonomy.common.enums.GroupingEntity;
36+
import org.bibsonomy.model.enums.Order;
37+
38+
/**
39+
* {@link PluginProperties} read and write the plugin properties file.
40+
* @author Waldemar Biller <[email protected]>
41+
*
42+
*/
43+
public class PluginProperties extends Properties {
44+
45+
private static final long serialVersionUID = 5420450194355211249L;
46+
47+
private static final Log LOG = LogFactory.getLog(PluginProperties.class);
48+
49+
/**
50+
* API properties
51+
*/
52+
private static final String API_URL = "api.url";
53+
private static final String API_USERNAME = "api.username";
54+
private static final String API_KEY = "api.key";
55+
56+
/**
57+
* Plugin properties
58+
*/
59+
private static final String PLUGIN_SAVE_API_KEY = "plugin.saveapikey";
60+
private static final String PLUGIN_DOCUMENTS_IMPORT = "plugin.documents.import";
61+
private static final String PLUGIN_DOCUMENTS_EXPORT = "plugin.documents.export";
62+
private static final String PLUGIN_TAGS_REFRESH_ON_STARTUP = "plugin.tags.refreshonstartup";
63+
private static final String PLUGIN_TAGS_IGNORE_NO_TAGS = "plugin.tags.ignorenotags";
64+
private static final String PLUGIN_NUMBER_OF_POSTS_PER_REQUEST = "plugin.request.size";
65+
private static final String PLUGIN_IGNORE_WARNING_MORE_POSTS = "plugin.request.size.ignorewarning";
66+
private static final String PLUGIN_EXTRA_TAB_FIELDS = "plugin.tabs.extra";
67+
private static final String PLUGIN_VISIBILITY = "plugin.visibilty";
68+
private static final String PLUGIN_TAG_CLOUD_SIZE = "plugin.tagcloud.size";
69+
private static final String PLUGIN_SIDE_PANE_VISIBILITY_TYPE = "plugin.sidepane.visibility.type";
70+
private static final String PLUGIN_SIDE_PANE_VISIBILITY_NAME = "plugin.sidepane.visibility.name";
71+
private static final String PLUGIN_TAG_CLOUD_ORDER = "plugin.tagcloud.order";
72+
73+
/**
74+
* Singleton of {@link PluginProperties}
75+
*/
76+
private static PluginProperties INSTANCE = null;
77+
78+
/**
79+
* location of properties file; JabRef stores the plugin itself also in this
80+
* directory.
81+
*/
82+
private static final String PATH_TO_PROPERTIES_FILE = System.getProperty("user.home") + "/.jabref/plugins/";
83+
private static final String PROPERTIES_FILE = PATH_TO_PROPERTIES_FILE + "bibsonomy-plugin.properties";
84+
85+
/**
86+
* Get the singleton of {@link PluginProperties}.
87+
* Will create one if INSTANCE is null
88+
* @return singleton of {@link PluginProperties}
89+
*/
90+
public static PluginProperties getInstance() {
91+
92+
if(INSTANCE == null)
93+
INSTANCE = new PluginProperties();
94+
95+
return INSTANCE;
96+
}
97+
98+
/**
99+
* The constructor reads the properties from the file system.
100+
*/
101+
private PluginProperties() {
102+
103+
try {
104+
File propertiesFile = new File(PROPERTIES_FILE);
105+
if(propertiesFile.exists() && propertiesFile.isFile())
106+
load(new FileInputStream(propertiesFile));
107+
} catch(Exception e) {
108+
LOG.error("Error loading properties file", e);
109+
}
110+
}
111+
112+
/**
113+
* Saves the properties to the file system.
114+
* Checks if the option to store the API is checked.
115+
*/
116+
public static void save() {
117+
118+
String apiKey = getApiKey();
119+
if(getStoreApiKey() == false)
120+
setApiKey(""); //set the api key to empty string
121+
//if user does not want to save api key
122+
try {
123+
124+
getInstance().store(new FileOutputStream(PROPERTIES_FILE), "");
125+
} catch(Exception ex) {
126+
127+
LOG.error("Failed saving properties file");
128+
}
129+
//set api key back to its actual value
130+
setApiKey(apiKey);
131+
}
132+
133+
public static boolean ignoreNoTagsAssigned() {
134+
135+
return Boolean.valueOf(getInstance().getProperty(PLUGIN_TAGS_IGNORE_NO_TAGS, "false"));
136+
}
137+
138+
public static String getUsername() {
139+
140+
return getInstance().getProperty(API_USERNAME, PluginGlobals.API_USERNAME);
141+
}
142+
143+
public static String getApiKey() {
144+
145+
return getInstance().getProperty(API_KEY, PluginGlobals.API_KEY);
146+
}
147+
148+
public static String getApiUrl() {
149+
150+
return getInstance().getProperty(API_URL, PluginGlobals.API_URL);
151+
}
152+
153+
public static boolean getDownloadDocumentsOnImport() {
154+
155+
return Boolean.parseBoolean(getInstance().getProperty(PLUGIN_DOCUMENTS_IMPORT, "true"));
156+
}
157+
158+
public static int getNumberOfPostsPerRequest() {
159+
160+
return Integer.parseInt(getInstance().getProperty(PLUGIN_NUMBER_OF_POSTS_PER_REQUEST, PluginGlobals.PLUGIN_NUMBER_OF_POSTS_PER_REQUEST));
161+
}
162+
163+
public static boolean getIgnoreMorePostsWarning() {
164+
165+
return Boolean.parseBoolean(getInstance().getProperty(PLUGIN_IGNORE_WARNING_MORE_POSTS, "false"));
166+
}
167+
168+
public static String getExtraTabFields() {
169+
170+
return getInstance().getProperty(PLUGIN_EXTRA_TAB_FIELDS, "issn;isbn");
171+
}
172+
173+
public static String getDefaultVisibilty() {
174+
175+
return getInstance().getProperty(PLUGIN_VISIBILITY, "public");
176+
}
177+
178+
public static boolean getStoreApiKey() {
179+
180+
return Boolean.parseBoolean(getInstance().getProperty(PLUGIN_SAVE_API_KEY, "true"));
181+
}
182+
183+
public static boolean getUpdateTagsOnStartUp() {
184+
185+
return Boolean.parseBoolean(getInstance().getProperty(PLUGIN_TAGS_REFRESH_ON_STARTUP, "false"));
186+
}
187+
188+
public static boolean getUploadDocumentsOnExport() {
189+
190+
return Boolean.parseBoolean(getInstance().getProperty(PLUGIN_DOCUMENTS_EXPORT, "true"));
191+
}
192+
193+
public static int getTagCloudSize() {
194+
195+
return Integer.parseInt(getInstance().getProperty(PLUGIN_TAG_CLOUD_SIZE, "100"));
196+
}
197+
198+
public static void setUsername(String text) {
199+
getInstance().setProperty(API_USERNAME, text);
200+
}
201+
202+
public static void setApiKey(String text) {
203+
getInstance().setProperty(API_KEY, text);
204+
}
205+
206+
public static void setStoreApiKey(boolean selected) {
207+
getInstance().setProperty(PLUGIN_SAVE_API_KEY, String.valueOf(selected));
208+
}
209+
210+
public static void setNumberOfPostsPerRequest(int value) {
211+
212+
getInstance().setProperty(PLUGIN_NUMBER_OF_POSTS_PER_REQUEST, String.valueOf(value));
213+
}
214+
215+
public static void setTagCloudSize(int value) {
216+
217+
getInstance().setProperty(PLUGIN_TAG_CLOUD_SIZE, String.valueOf(value));
218+
219+
}
220+
221+
public static void setIgnoreNoTagsAssigned(boolean selected) {
222+
223+
getInstance().setProperty(PLUGIN_TAGS_IGNORE_NO_TAGS, String.valueOf(selected));
224+
}
225+
226+
public static void setUpdateTagsOnStartup(boolean selected) {
227+
228+
getInstance().setProperty(PLUGIN_TAGS_REFRESH_ON_STARTUP, String.valueOf(selected));
229+
}
230+
231+
public static void setUploadDocumentsOnExport(boolean selected) {
232+
233+
getInstance().setProperty(PLUGIN_DOCUMENTS_EXPORT, String.valueOf(selected));
234+
235+
}
236+
237+
public static void setDownloadDocumentsOnImport(boolean selected) {
238+
239+
getInstance().setProperty(PLUGIN_DOCUMENTS_IMPORT, String.valueOf(selected));
240+
}
241+
242+
public static void setDefaultVisisbility(String key) {
243+
getInstance().setProperty(PLUGIN_VISIBILITY, key);
244+
}
245+
246+
public static void setIgnoreMorePostsWarning(boolean selected) {
247+
getInstance().setProperty(PLUGIN_IGNORE_WARNING_MORE_POSTS, String.valueOf(selected));
248+
}
249+
250+
public static void setExtraFields(String text) {
251+
getInstance().setProperty(PLUGIN_EXTRA_TAB_FIELDS, text);
252+
}
253+
254+
public static GroupingEntity getSidePaneVisibilityType() {
255+
256+
return GroupingEntity.getGroupingEntity(getInstance().getProperty(PLUGIN_SIDE_PANE_VISIBILITY_TYPE, "ALL"));
257+
}
258+
259+
public static String getSidePaneVisibilityName() {
260+
261+
return getInstance().getProperty(PLUGIN_SIDE_PANE_VISIBILITY_NAME, "all users");
262+
}
263+
264+
public static void setSidePaneVisibilityType(GroupingEntity entity) {
265+
266+
getInstance().setProperty(PLUGIN_SIDE_PANE_VISIBILITY_TYPE, entity.toString());
267+
}
268+
269+
public static void setSidePaneVisibilityName(String value) {
270+
271+
getInstance().setProperty(PLUGIN_SIDE_PANE_VISIBILITY_NAME, value);
272+
}
273+
274+
public static Order getTagCloudOrder() {
275+
276+
String order = getInstance().getProperty(PLUGIN_TAG_CLOUD_ORDER, "FREQUENCY");
277+
return Order.getOrderByName(order);
278+
}
279+
280+
public static void setTagCloudOrder(Order order) {
281+
282+
getInstance().setProperty(PLUGIN_TAG_CLOUD_ORDER, order.toString());
283+
}
284+
285+
public static void setApiUrl(String text) {
286+
getInstance().setProperty(API_URL, text);
287+
}
288+
289+
}

0 commit comments

Comments
 (0)