From: kiramt Date: Fri, 21 Oct 2016 13:37:04 +0000 (+0100) Subject: Factored URL Link constants out into UrlConstants file. X-Git-Tag: Release_2_10_1^2~35 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=258cf48b8759cd20d44a1c8d170f950e84ccd23f;p=jalview.git Factored URL Link constants out into UrlConstants file. --- diff --git a/src/jalview/appletgui/IdPanel.java b/src/jalview/appletgui/IdPanel.java index ed96b55..2cb3060 100755 --- a/src/jalview/appletgui/IdPanel.java +++ b/src/jalview/appletgui/IdPanel.java @@ -20,6 +20,9 @@ */ package jalview.appletgui; +import static jalview.util.UrlConstants.EMBLEBI_STRING; +import static jalview.util.UrlConstants.SRS_STRING; + import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; @@ -82,19 +85,16 @@ public class IdPanel extends Panel implements MouseListener, } { // upgrade old SRS link - int srsPos = links - .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry"); + int srsPos = links.indexOf(SRS_STRING); if (srsPos > -1) { - links.setElementAt( - "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$", - srsPos); + links.setElementAt(EMBLEBI_STRING, srsPos); } } if (links.size() < 1) { links = new java.util.Vector(); - links.addElement("EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"); + links.addElement(EMBLEBI_STRING); } } diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 8dbe5e2..b43989a 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -20,6 +20,10 @@ */ package jalview.gui; +import static jalview.util.UrlConstants.EMBLEBI_STRING; +import static jalview.util.UrlConstants.SEQUENCE_ID; +import static jalview.util.UrlConstants.SRS_STRING; + import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.bin.Cache; import jalview.gui.Help.HelpId; @@ -110,10 +114,7 @@ public class Preferences extends GPreferences public static List groupURLLinks; static { - String string = Cache - .getDefault( - "SEQUENCE_LINKS", - "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"); + String string = Cache.getDefault("SEQUENCE_LINKS", EMBLEBI_STRING); sequenceURLLinks = new Vector(); try @@ -124,7 +125,7 @@ public class Preferences extends GPreferences String name = st.nextToken(); String url = st.nextToken(); // check for '|' within a regex - int rxstart = url.indexOf("$SEQUENCE_ID$"); + int rxstart = url.indexOf("$" + SEQUENCE_ID + "$"); while (rxstart == -1 && url.indexOf("/=$") == -1) { url = url + "|" + st.nextToken(); @@ -137,14 +138,10 @@ public class Preferences extends GPreferences } { // upgrade old SRS link - int srsPos = sequenceURLLinks - .indexOf("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry"); + int srsPos = sequenceURLLinks.indexOf(SRS_STRING); if (srsPos > -1) { - sequenceURLLinks - .setElementAt( - "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$", - srsPos); + sequenceURLLinks.setElementAt(EMBLEBI_STRING, srsPos); } } diff --git a/src/jalview/util/UrlConstants.java b/src/jalview/util/UrlConstants.java new file mode 100644 index 0000000..fc6dfdd --- /dev/null +++ b/src/jalview/util/UrlConstants.java @@ -0,0 +1,54 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.util; + +/** + * A class to hold constants relating to Url links used in Jalview + */ +public class UrlConstants +{ + /* + * Default sequence URL link string for EMBL-EBI search + */ + public static final String EMBLEBI_STRING = "EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$"; + + /* + * Default sequence URL link string for SRS + */ + public static final String SRS_STRING = "SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry"; + + /* + * Sequence ID string + */ + public static final String SEQUENCE_ID = "SEQUENCE_ID"; + + /* + * Sequence Name string + */ + public static final String SEQUENCE_NAME = "SEQUENCE_NAME"; + + /* + * not instantiable + */ + private UrlConstants() + { + } +} diff --git a/src/jalview/util/UrlLink.java b/src/jalview/util/UrlLink.java index 4297090..e196c8c 100644 --- a/src/jalview/util/UrlLink.java +++ b/src/jalview/util/UrlLink.java @@ -20,6 +20,8 @@ */ package jalview.util; +import static jalview.util.UrlConstants.SEQUENCE_ID; + import java.util.Vector; public class UrlLink @@ -48,7 +50,7 @@ public class UrlLink */ public UrlLink(String link) { - int sep = link.indexOf("|"), psqid = link.indexOf("$SEQUENCE_ID"); + int sep = link.indexOf("|"), psqid = link.indexOf("$" + SEQUENCE_ID); if (psqid > -1) { dynamic = true; @@ -77,7 +79,7 @@ public class UrlLink } // Parse URL : Whole URL string first url_prefix = link.substring(sep + 1, psqid); - if (link.indexOf("$SEQUENCE_ID=/") == psqid + if (link.indexOf("$" + SEQUENCE_ID + "=/") == psqid && (p = link.indexOf("/=$", psqid + 14)) > psqid + 14) { // Extract Regex and suffix @@ -102,7 +104,7 @@ public class UrlLink { regexReplace = null; // verify format is really correct. - if (link.indexOf("$SEQUENCE_ID$") == psqid) + if (link.indexOf("$" + SEQUENCE_ID + "$") == psqid) { url_suffix = link.substring(psqid + 13); regexReplace = null; @@ -295,12 +297,13 @@ public class UrlLink } } + @Override public String toString() { return label + "|" + url_prefix - + (dynamic ? ("$SEQUENCE_ID" + ((regexReplace != null) ? "=" + + (dynamic ? ("$" + SEQUENCE_ID + ((regexReplace != null) ? "=" + regexReplace + "=$" : "$")) : "") + ((url_suffix == null) ? "" : url_suffix); @@ -341,7 +344,8 @@ public class UrlLink * "PF3|http://us.expasy.org/cgi-bin/niceprot.pl?$SEQUENCE_ID=/PFAM:(.+)/=$" * , "NOTFER|http://notfer.org/$SEQUENCE_ID=/(?