Skip to content

Commit

Permalink
first attempt to manage metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
zesaro committed Nov 21, 2016
1 parent 453c651 commit 25e0ee8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 50 deletions.
10 changes: 10 additions & 0 deletions src/main/java/net/sf/jabref/model/metadata/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Vector;

import net.sf.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern;
import net.sf.jabref.model.bibtexkeypattern.DatabaseBibtexKeyPattern;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class MetaData {
private SaveOrderConfig saveOrderConfig;
private Map<String, String> citeKeyPatterns = new HashMap<>(); // <BibType, Pattern>
private Map<String, String> userFileDirectory = new HashMap<>(); // <User, FilePath>
private Map<String, Vector<String>> bibsonomyData = new HashMap<>();
private String defaultCiteKeyPattern;
private FieldFormatterCleanups saveActions;
private BibDatabaseMode mode;
Expand All @@ -54,6 +56,14 @@ public MetaData() {
// Do nothing
}

public void addBibsonomyData(String key, Vector<String> value){
bibsonomyData.put(key,value);
}

public Vector<String> getBibsonomyData(String key){
return bibsonomyData.get(key);
}

public Optional<SaveOrderConfig> getSaveOrderConfig() {
return Optional.ofNullable(saveOrderConfig);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,46 @@

import java.util.Optional;

import net.sf.jabref.gui.JabRefFrame;

import org.bibsonomy.plugin.jabref.BibsonomyGlobals;
import org.bibsonomy.rest.client.util.MultiDirectoryFileFactory;

public class JabRefFileFactory extends MultiDirectoryFileFactory {

public JabRefFileFactory() {
private final JabRefFrame jabRefFrame;

public JabRefFileFactory(JabRefFrame jabRefFrame) {
super(null, null, null);
this.jabRefFrame = jabRefFrame;
}

@Override
public String getPsDirectory() {
String psFileDir = JabRefGlobalsHelper.getDBSpecificPSDirectory();
String psFileDir = JabRefGlobalsHelper.getDBSpecificPSDirectory(jabRefFrame);
if (psFileDir != null) return psFileDir;

return getFileDirectory();
}

@Override
public String getPdfDirectory() {
String pdfFileDir = JabRefGlobalsHelper.getDBSpecificPDFDirectory();
String pdfFileDir = JabRefGlobalsHelper.getDBSpecificPDFDirectory(jabRefFrame);
if (pdfFileDir != null) return pdfFileDir;

return getFileDirectory();
}

@Override
public String getFileDirectory() {
String fileDir = JabRefGlobalsHelper.getDBSpecificUserFileDirIndividual();
String fileDir = JabRefGlobalsHelper.getDBSpecificUserFileDirIndividual(jabRefFrame);
if (fileDir != null) return fileDir;

fileDir = JabRefGlobalsHelper.getDBSpecificUserFileDir();
fileDir = JabRefGlobalsHelper.getDBSpecificUserFileDir(jabRefFrame);
if (fileDir != null) return fileDir;

Optional<String> fileDirectoryOpt = BibsonomyMetaData.getMetaData().getDefaultFileDirectory();
if (BibsonomyMetaData.getMetaData() != null && fileDirectoryOpt.isPresent()) {
Optional<String> fileDirectoryOpt = jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getDefaultFileDirectory();
if (jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData() != null && fileDirectoryOpt.isPresent()) {
return fileDirectoryOpt.get();

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
package org.bibsonomy.plugin.jabref.util;

import java.util.Vector;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.JabRefFrame;

public class JabRefGlobalsHelper {

/**
* Returns database specific UserFileDir as String if exists, else null
*/
public static String getDBSpecificUserFileDir() {
return getMetaDataValue(Globals.prefs.get("userFileDir"));
public static String getDBSpecificUserFileDir(JabRefFrame jabRefFrame) {
return getMetaDataValue(jabRefFrame, Globals.prefs.get("userFileDir"));
}

/**
* Returns database specific UserFileDirIndividual as String if exists, else null
*/
public static String getDBSpecificUserFileDirIndividual() {
return getMetaDataValue(Globals.prefs.get("userFileDirIndividual"));
public static String getDBSpecificUserFileDirIndividual(JabRefFrame jabRefFrame) {
return getMetaDataValue(jabRefFrame, Globals.prefs.get("userFileDirIndividual"));
}

/**
* Returns database specific PDFDirectory as String if exists, else null
*/
public static String getDBSpecificPDFDirectory() {
return getMetaDataValue("pdfDirectory");
public static String getDBSpecificPDFDirectory(JabRefFrame jabRefFrame) {
return getMetaDataValue(jabRefFrame, "pdfDirectory");
}

/**
* Returns database specific PDFDirectory as String if exists, else null
*/
public static String getDBSpecificPSDirectory() {
return getMetaDataValue("psDirectory");
public static String getDBSpecificPSDirectory(JabRefFrame jabRefFrame) {
return getMetaDataValue(jabRefFrame, "psDirectory");
}

private static String getMetaDataValue(String key) {
/*
*TODO: Investigate changes in MetaData - zellerdev
*List<String> fileDI = BibsonomyMetaData.getMetaData().getData(key);
*if (fileDI != null && fileDI.size() >= 1) {
* return fileDI.get(0).trim();
*}
*/
private static String getMetaDataValue(JabRefFrame jabRefFrame, String key) {

//TODO: Investigate changes in MetaData - zellerdev
Vector<String> fileDI = jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().getBibsonomyData(key);
if (fileDI != null && fileDI.size() >= 1) {
return fileDI.get(0).trim();
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class AbstractBibsonomyWorker extends AbstractWorker {

public AbstractBibsonomyWorker(JabRefFrame jabRefFrame) {
this.jabRefFrame = jabRefFrame;
this.fileFactory = new JabRefFileFactory();
this.fileFactory = new JabRefFileFactory(jabRefFrame);
}

public synchronized void stopFetching() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

import javax.swing.JEditorPane;

Expand All @@ -13,7 +14,6 @@
import org.bibsonomy.model.BibTex;
import org.bibsonomy.model.Tag;
import org.bibsonomy.plugin.jabref.BibsonomyProperties;
import org.bibsonomy.plugin.jabref.util.BibsonomyMetaData;


/**
Expand All @@ -29,8 +29,6 @@ public class RefreshTagListWorker extends AbstractBibsonomyWorker {
private String groupingValue;
private List<Tag> tags;

private MetaData metaData = BibsonomyMetaData.getMetaData();

public RefreshTagListWorker(JabRefFrame jabRefFrame, JEditorPane tagCloud, GroupingEntity grouping, String groupingValue) {
super(jabRefFrame);
this.tagCloud = tagCloud;
Expand All @@ -40,10 +38,15 @@ public RefreshTagListWorker(JabRefFrame jabRefFrame, JEditorPane tagCloud, Group
}

public void run() {
List<String> keywords = null;
MetaData metaData = null;
//Vector<String> keywords = null;
Vector<String> keywords = null;
if (jabRefFrame.getCurrentBasePanel() != null) {
//TODO: Investigate changes in MetaData - zellerdev
//keywords = metaData.getData(MetaData.SELECTOR_META_PREFIX + "keywords");
metaData = jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData();
keywords = metaData.getBibsonomyData("keywords");

}

int start = 0, end = BibsonomyProperties.getTagCloudSize(), max = 1, min = 1;
Expand Down Expand Up @@ -116,6 +119,7 @@ public void run() {
if (metaData != null && keywords != null) {
//TODO: Investigate changes in MetaData - zellerdev
//metaData.putData(MetaData.SELECTOR_META_PREFIX + "keywords", keywords);
jabRefFrame.getCurrentBasePanel().getBibDatabaseContext().getMetaData().addBibsonomyData("keywords", keywords);
}
jabRefFrame.output(Localization.lang("Done"));
}
Expand Down

0 comments on commit 25e0ee8

Please sign in to comment.