==== Patch level 1 Source: fb8f25e6-7148-42da-a9a5-df68bcff033b:/local/jabref/branches/beta_2.3/jabref:2536 [local] Target: 15a67142-8137-0410-b105-af5202cce309:/branches/beta_2.3/jabref:2471 [mirrored] (https://jabref.svn.sourceforge.net/svnroot/jabref) Log: r2395@ali: fedor | 2007-09-21 14:17:32 +0200 copy of the site beta_2.3 branch r2407@ali: fedor | 2007-09-21 15:14:52 +0200 ARXIV download patch (sends User-Agent: now) r2439@ali: fedor | 2007-10-02 17:32:58 +0200 Added 'Open SPIRES' action (Merged with jabref?) r2440@ali: fedor | 2007-10-02 17:36:14 +0200 Removed Site modifications r2496@ali: fedor | 2007-10-31 09:02:14 +0100 Fixed the FileListTableModel getIcon method (allready made in trunc!) r2536@ali: fedor | 2007-11-14 10:55:18 +0100 Changed version to 2.3flb === src/java/net/sf/jabref/imports/SPIRESFetcher.java ================================================================== --- src/java/net/sf/jabref/imports/SPIRESFetcher.java (revision 2471) +++ src/java/net/sf/jabref/imports/SPIRESFetcher.java (patch spires2.3 level 1) @@ -0,0 +1,241 @@ +package net.sf.jabref.imports; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.util.Iterator; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import net.sf.jabref.BibtexDatabase; +import net.sf.jabref.BibtexEntry; +import net.sf.jabref.GUIGlobals; +import net.sf.jabref.Globals; +import net.sf.jabref.JabRefFrame; +import net.sf.jabref.imports.BibtexParser; +import net.sf.jabref.gui.ImportInspectionDialog; + +/** + * + * This class allows to access the Slac SPIRES database. + * + * It can either be a GeneralFetcher to pose requests to the database or fetch + * individual entries. + * + * @author Fedor Bezrukov + * + * @version $Id$ + * + */ +public class SPIRESFetcher implements EntryFetcher, Runnable { + + private static String spiresHost = "www-spires.slac.stanford.edu"; + + /* + * These are initialized by parseQuery if we are running the user query for + * GeneralFetcher + */ + private String query; + + private ImportInspectionDialog dialog; + + private JabRefFrame frame; + + public SPIRESFetcher() { + } + + /** + * Construct the query URL + * + * @param key + * The key of the OAI2 entry that the url should poitn to. + * + * @return a String denoting the query URL + */ + public String constructUrl(String key) { + String identifier = ""; + try { + identifier = URLEncoder.encode((String) key, "UTF-8"); + } catch (UnsupportedEncodingException e) { + return ""; + } + StringBuffer sb = new StringBuffer("http://").append(spiresHost) + .append("/"); + sb.append("spires/find/hep/www").append("?"); + sb.append("rawcmd=find+"); + sb.append(identifier); + sb.append("&FORMAT=WWWBRIEFBIBTEX&SEQUENCE="); + return sb.toString(); + } + + /** + * Constructs a SPIRES query url from slaccitation field + * + * @param slaccitation + * @return query string + */ + public static String constructUrlFromSlaccitation(String slaccitation) { + String cmd = "j"; + String key = slaccitation.replaceAll("^%%CITATION = ", "").replaceAll( + ";%%$", ""); + if (key.matches("^\\w*-\\w*[ /].*")) + cmd = "eprint"; + try { + key = URLEncoder.encode((String) key, "UTF-8"); + } catch (UnsupportedEncodingException e) { + } + StringBuffer sb = new StringBuffer("http://").append(spiresHost) + .append("/"); + sb.append("spires/find/hep/www").append("?"); + sb.append("rawcmd=find+").append(cmd).append("+"); + sb.append(key); + return sb.toString(); + } + + /** + * Construct an SPIRES query url from eprint field + * + * @param eprint + * @return query string + */ + public static String constructUrlFromEprint(String eprint) { + String key = eprint.replaceAll(" [.*]$", ""); + try { + key = URLEncoder.encode(key, "UTF-8"); + } catch (UnsupportedEncodingException e) { + return ""; + } + StringBuffer sb = new StringBuffer("http://").append(spiresHost) + .append("/"); + sb.append("spires/find/hep/www").append("?"); + sb.append("rawcmd=find+eprint+"); + sb.append(key); + return sb.toString(); + } + + /** + * Import an entry from an OAI2 archive. The BibtexEntry provided has to + * have the field OAI2_IDENTIFIER_FIELD set to the search string. + * + * @param key + * The OAI2 key to fetch from ArXiv. + * @return The imnported BibtexEntry or null if none. + */ + public BibtexDatabase importSpiresEntries(String key) { + String url = constructUrl(key); + try { + HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection(); + conn.setRequestProperty("User-Agent", "Jabref"); + InputStream inputStream = conn.getInputStream(); + + SPIRESBibtexFilterReader reader = new SPIRESBibtexFilterReader( + new InputStreamReader(inputStream)); + + ParserResult pr = BibtexParser.parse(reader); + + return pr.getDatabase(); + } catch (IOException e) { + JOptionPane.showMessageDialog(frame, Globals.lang( + "An Exception ocurred while accessing '%0'", url) + + "\n\n" + e.toString(), Globals.lang(getKeyName()), + JOptionPane.ERROR_MESSAGE); + } catch (RuntimeException e) { + JOptionPane.showMessageDialog(frame, Globals.lang( + "An Error occurred while fetching from SPIRES source (%0):", + new String[] { url }) + + "\n\n" + e.getMessage(), Globals.lang(getKeyName()), + JOptionPane.ERROR_MESSAGE); + } + return null; + } + + // public void addSpiresURL(BibtexEntry entry) { + // String url = "http://"+spiresHost+"/spires/find/hep/www?texkey+"; + // url = url+entry.getCiteKey(); + // entry.setField("url", url); + // } + // + // public void addSpiresURLtoDatabase(BibtexDatabase db) { + // Iterator iter = db.getEntries().iterator(); + // while (iter.hasNext()) + // addSpiresURL(iter.next()); + // } + + /* + * @see net.sf.jabref.imports.EntryFetcher + */ + public String getHelpPage() { + // there is no helppage + return null; + } + + public URL getIcon() { + return GUIGlobals.getIconUrl("www"); + } + + public String getKeyName() { + return "Fetch SPIRES"; + } + + public JPanel getOptionsPanel() { + // we have no additional options + return null; + } + + public String getTitle() { + return Globals.menuTitle(getKeyName()); + } + + public void processQuery(String query, ImportInspectionDialog dialog, + JabRefFrame frame) { + this.query = query; + this.dialog = dialog; + this.frame = frame; + (new Thread(this)).start(); + } + + /* + * @see net.sf.jabref.gui.ImportInspectionDialog.CallBack + */ + public void cancelled() { + } + + public void done(int entriesImported) { + } + + public void stopFetching() { + } + + /* + * @see java.lang.Runnable + */ + public void run() { + try { + dialog.setVisible(true); + /* multiple keys can be delimited by ; or space */ + frame.output(Globals.lang("Processing ") + query); + + /* query the archive and load the results into the BibtexEntry */ + BibtexDatabase bd = importSpiresEntries(query); + + /* addSpiresURLtoDatabase(bd); */ + + /* add the entry to the inspection dialog */ + if (bd.getEntryCount() > 0) + dialog.addEntries(bd.getEntries()); + + /* update the dialogs progress bar */ + // dialog.setProgress(i + 1, keys.length); + /* inform the inspection dialog, that we're done */ + dialog.entryListComplete(); + frame.output(""); + } catch (Exception e) { + frame.output(Globals.lang("Error while fetching from Spires: ") + + e.getMessage()); + e.printStackTrace(); + } + } +} Property changes on: src/java/net/sf/jabref/imports/SPIRESFetcher.java ___________________________________________________________________ Name: snv:keywords +Id === src/java/net/sf/jabref/imports/SPIRESBibtexFilterReader.java ================================================================== --- src/java/net/sf/jabref/imports/SPIRESBibtexFilterReader.java (revision 2471) +++ src/java/net/sf/jabref/imports/SPIRESBibtexFilterReader.java (patch spires2.3 level 1) @@ -0,0 +1,62 @@ +package net.sf.jabref.imports; + +import java.io.Reader; +import java.io.BufferedReader; +import java.io.FilterReader; +import java.io.IOException; + +/** + * + * Warning -- it is not a generic filter, only read is implemented! + * + * @author Fedor Bezrukov + * + * @version $Id$ + * + */ +public class SPIRESBibtexFilterReader extends FilterReader { + + protected BufferedReader in; + + private String line; + private int pos; + private boolean pre; + + SPIRESBibtexFilterReader(Reader _in) { + super(_in); + in = new BufferedReader(_in); + pos=-1; + pre=false; + } + + private String readpreLine() throws IOException { + String l; + do { + l=in.readLine(); + if (l==null) + return null; + if (l.equals("
")) {
+		pre = true;
+		l=in.readLine();
+	    }
+	    if (l.equals("
")) + pre = false; + } while (!pre); + return l; + } + + public int read() throws IOException { + if ( pos<0 ) { + line=readpreLine(); + pos=0; + if ( line == null ) + return -1; + } + if ( pos>=line.length() ) { + pos=-1; + return '\n'; + } + return line.charAt(pos++); + } + +} Property changes on: src/java/net/sf/jabref/imports/SPIRESBibtexFilterReader.java ___________________________________________________________________ Name: snv:keywords +Id === src/java/net/sf/jabref/BasePanel.java ================================================================== --- src/java/net/sf/jabref/BasePanel.java (revision 2471) +++ src/java/net/sf/jabref/BasePanel.java (patch spires2.3 level 1) @@ -69,6 +69,7 @@ import net.sf.jabref.gui.*; import net.sf.jabref.imports.AppendDatabaseAction; import net.sf.jabref.imports.BibtexParser; +import net.sf.jabref.imports.SPIRESFetcher; import net.sf.jabref.journals.AbbreviateAction; import net.sf.jabref.journals.UnabbreviateAction; import net.sf.jabref.labelPattern.LabelPatternUtil; @@ -1014,6 +1015,32 @@ } }); + actions.put("openSpires", new BaseAction() { + public void action() { + BibtexEntry[] bes = mainTable.getSelectedEntries(); + if ((bes != null) && (bes.length == 1)) { + Object link = null; + if (bes[0].getField("eprint") != null) + link = SPIRESFetcher.constructUrlFromEprint(bes[0].getField("eprint").toString()); + else if (bes[0].getField("slaccitation") != null) + link = SPIRESFetcher.constructUrlFromSlaccitation(bes[0].getField("slaccitation").toString()); + if (link != null) { + //output(Globals.lang("Calling external viewer...")); + try { + Util.openExternalViewer(metaData(), link.toString(), "url"); + output(Globals.lang("External viewer called")+"."); + } catch (IOException ex) { + output(Globals.lang("Error") + ": " + ex.getMessage()); + } + } + else + output(Globals.lang("No url defined")+"."); + } else + output(Globals.lang("No entries or multiple entries selected.")); + } + }); + + actions.put("replaceAll", new BaseAction() { public void action() { ReplaceStringDialog rsd = new ReplaceStringDialog(frame); === src/java/net/sf/jabref/gui/FileListTableModel.java ================================================================== --- src/java/net/sf/jabref/gui/FileListTableModel.java (revision 2471) +++ src/java/net/sf/jabref/gui/FileListTableModel.java (patch spires2.3 level 1) @@ -171,7 +171,9 @@ public static JLabel getFirstLabel(String content) { FileListTableModel tm = new FileListTableModel(); FileListEntry entry = tm.setContent(content, true, true); - return entry != null ? entry.getType().getIconLabel() : null; + if (entry == null || entry.getType()==null ) + return null; + return entry.getType().getIconLabel(); } === src/java/net/sf/jabref/JabRefPreferences.java ================================================================== --- src/java/net/sf/jabref/JabRefPreferences.java (revision 2471) +++ src/java/net/sf/jabref/JabRefPreferences.java (patch spires2.3 level 1) @@ -757,6 +757,7 @@ defKeyBinds.put("Open file", "F4"); defKeyBinds.put("Open PDF or PS", "shift F5"); defKeyBinds.put("Open URL or DOI", "F3"); + defKeyBinds.put("Open SPIRES entry", "ctrl F3"); defKeyBinds.put("Toggle entry preview", "ctrl F9"); defKeyBinds.put("Switch preview layout", "F9"); defKeyBinds.put("Edit entry", "ctrl E"); @@ -777,6 +778,9 @@ defKeyBinds.put("Fetch ArXiv.org", "shift F8"); defKeyBinds.put("Write XMP", "ctrl F4"); defKeyBinds.put("New file link", "ctrl N"); + + defKeyBinds.put("Fetch SPIRES", "ctrl F8"); + //defKeyBinds.put("Select value", "ctrl B"); } === src/java/net/sf/jabref/JabRefFrame.java ================================================================== --- src/java/net/sf/jabref/JabRefFrame.java (revision 2471) +++ src/java/net/sf/jabref/JabRefFrame.java (patch spires2.3 level 1) @@ -256,6 +256,9 @@ openUrl = new GeneralAction("openUrl", "Open URL or DOI", Globals.lang("Open URL or DOI"), prefs.getKey("Open URL or DOI")), + openSpires = new GeneralAction("openSpires", "Open SPIRES entry", + Globals.lang("Open SPIRES entry"), + prefs.getKey("Open SPIRES entry")), dupliCheck = new GeneralAction("dupliCheck", "Find duplicates"), //strictDupliCheck = new GeneralAction("strictDupliCheck", "Find and remove exact duplicates"), plainTextImport = new GeneralAction("plainTextImport", @@ -302,6 +305,8 @@ GeneralFetcher ieex; OAI2Fetcher arxivFetcher; GeneralFetcher arxiv; + SPIRESFetcher spiresFetcher; + GeneralFetcher spires; SearchManager2 searchManager; public GroupSelector groupSelector; @@ -410,6 +415,7 @@ ieeexplorerFetcher = new IEEEXploreFetcher(); arxivFetcher = new OAI2Fetcher(); + spiresFetcher = new SPIRESFetcher(); medlineFetcher = new MedlineFetcher(sidePaneManager); citeSeerFetcher = new CiteSeerFetcher(sidePaneManager); citeSeerFetcherPanel = new CiteSeerFetcherPanel(sidePaneManager, @@ -1118,6 +1124,7 @@ tools.add(openFile); tools.add(openPdf); tools.add(openUrl); + tools.add(openSpires); tools.addSeparator(); tools.add(newSubDatabaseAction); @@ -1137,8 +1144,10 @@ web.add(fetchCiteSeer); ieex = new GeneralFetcher(sidePaneManager, this, ieeexplorerFetcher); arxiv = new GeneralFetcher(sidePaneManager, this, arxivFetcher); + spires = new GeneralFetcher(sidePaneManager, this, spiresFetcher); web.add(ieex.getAction()); web.add(arxiv.getAction()); + web.add(spires.getAction()); mb.add(web); @@ -1375,11 +1384,11 @@ selectAll, copyKey, copyCiteKey, editPreamble, editStrings, toggleGroups, toggleSearch, makeKeyAction, normalSearch, incrementalSearch, replaceAll, importMenu, exportMenu, fetchMedline, fetchCiteSeer, - openPdf, openUrl, togglePreview, dupliCheck, /*strictDupliCheck,*/ highlightAll, + openPdf, openUrl, openSpires, togglePreview, dupliCheck, /*strictDupliCheck,*/ highlightAll, highlightAny, citeSeerPanelAction, newEntryAction, plainTextImport, closeDatabaseAction, switchPreview, integrityCheckAction, autoSetPdf, autoSetPs, toggleHighlightAny, toggleHighlightAll, databaseProperties, abbreviateIso, - abbreviateMedline, unabbreviate, ieex.getAction(), arxiv.getAction(), exportAll, exportSelected, + abbreviateMedline, unabbreviate, ieex.getAction(), arxiv.getAction(), spires.getAction(), exportAll, exportSelected, importCurrent, saveAll})); openDatabaseOnlyActions.addAll(Arrays.asList(newSpecificEntryAction)); --- src/resource/build.properties.flb 2007-11-14 11:21:39.000000000 +0100 +++ src/resource/build.properties 2007-11-14 11:21:32.000000000 +0100 @@ -1,3 +1,3 @@ builddate=November 8 2007 build=319 -version=2.3 \ No newline at end of file +version=2.3flb \ No newline at end of file --- build.xml.flb 2007-11-14 11:21:17.000000000 +0100 +++ build.xml 2007-11-14 11:19:53.000000000 +0100 @@ -47,7 +47,7 @@ ========================================================================================== --> - +