|
[HepData-svn] r1786 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pagesblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Apr 17 16:25:56 BST 2014
Author: watt Date: Thu Apr 17 16:25:56 2014 New Revision: 1786 Log: More robust treatment of DOIs in URLs Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/ViewBase.java Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/ViewBase.java ============================================================================== --- trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/ViewBase.java Thu Apr 17 12:56:50 2014 (r1785) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/webapp/pages/ViewBase.java Thu Apr 17 16:25:56 2014 (r1786) @@ -85,7 +85,6 @@ // Only initialise here, otherwise Tapestry pools the page object and session info is shared if (_params == null) _params = new TreeMap(); Matcher m = null; - Matcher mPTEP = null, mEPJC = null, mEPL = null, mJPG = null; String firstnextlast = "no"; @@ -113,11 +112,13 @@ continue; } - m = Pattern.compile("\\A" + "" + "(\\d+)\\Z").matcher(ps); - if (m.matches()) { - _params.put("irn", m.group(1)); - continue; - } + if (i==0) { + m = Pattern.compile("\\A" + "" + "(\\d+)\\Z").matcher(ps); + if (m.matches()) { + _params.put("irn", m.group(1)); + continue; + } + } m = Pattern.compile("\\A" + "ins" + "(\\d+)\\Z").matcher(ps); if (m.matches()) { @@ -130,24 +131,20 @@ continue; } - m = Pattern.compile("\\A" + "10.1" + "(\\d+)\\Z").matcher(ps); - mPTEP = Pattern.compile("\\A" + "10.1093" + "\\Z").matcher(ps); - mEPJC = Pattern.compile("\\A" + "10.1140" + "\\Z").matcher(ps); - mEPL = Pattern.compile("\\A" + "10.1209" + "\\Z").matcher(ps); - mJPG = Pattern.compile("\\A" + "10.1088" + "\\Z").matcher(ps); - int iimax = i+1; - if (mPTEP.matches() || mEPJC.matches()) { - iimax = i+2; - } else if (mEPL.matches()) { - iimax = i+3; - } else if (mJPG.matches()) { - iimax = i+4; - } - if (m.matches()) { + // G.W. 17/04/2014 More robust treatment of DOIs in URLs. + Pattern patt1 = Pattern.compile("\\A" + "(short|long|full|plain.txt|yoda|aida|pyroot.py|root|mpl|bdms|hepml|scavis.py|input|marcxml)" + "\\Z", Pattern.CASE_INSENSITIVE); + Pattern patt2 = Pattern.compile("\\A" + "d\\d+" + "\\Z", Pattern.CASE_INSENSITIVE); + m = Pattern.compile("\\A" + "10.1" + "\\d+\\Z").matcher(ps); + if (m.matches() && i==0) { String doi=""; - for (int ii=i; ii<=iimax; ii++) { - if(ii>i) { doi += "/"; } - doi += context.get(String.class, ii); + for (int ii=i; ii < context.getCount(); ii++) { + String ps1 = context.get(String.class, ii); + Matcher m1 = patt1.matcher(ps1); + Matcher m2 = patt2.matcher(ps1); + if (!m1.matches() && !m2.matches()) { + if(ii>i) { doi += "/"; } + doi += ps1; + } } _params.put("doi",doi); continue; @@ -312,8 +309,8 @@ ctx.add("red" + red); } else if (doi != null) { String[] ctx2 = doi.split("/"); - ctx.add(ctx2[0]); - ctx.add(ctx2[1]); + for (int i=0; i<ctx2.length; i++) + ctx.add(ctx2[i]); } else { return ctx; } @@ -373,8 +370,8 @@ if(getPaperNumber() != null) { if(getPaperNumber().startsWith("doi")) { String[] ctx2 = getPaperNumber().substring(3).split("/"); - ctx.add(ctx2[0]); - ctx.add(ctx2[1]); + for (int i=0; i<ctx2.length; i++) + ctx.add(ctx2[i]); } else{ ctx.add(getPaperNumber()); } @@ -388,8 +385,8 @@ if(getPaperNumber() != null) { if(getPaperNumber().startsWith("doi")) { String[] ctx2 = getPaperNumber().substring(3).split("/"); - ctx.add(ctx2[0]); - ctx.add(ctx2[1]); + for (int i=0; i<ctx2.length; i++) + ctx.add(ctx2[i]); } else{ ctx.add(getPaperNumber()); } @@ -404,8 +401,8 @@ if(getPaperNumber() != null) { if(getPaperNumber().startsWith("doi")) { String[] ctx2 = getPaperNumber().substring(3).split("/"); - ctx.add(ctx2[0]); - ctx.add(ctx2[1]); + for (int i=0; i<ctx2.length; i++) + ctx.add(ctx2[i]); } else{ ctx.add(getPaperNumber()); } @@ -420,8 +417,8 @@ if(getPaperNumber() != null) { if(getPaperNumber().startsWith("doi")) { String[] ctx2 = getPaperNumber().substring(3).split("/"); - ctx.add(ctx2[0]); - ctx.add(ctx2[1]); + for (int i=0; i<ctx2.length; i++) + ctx.add(ctx2[i]); } else{ ctx.add(getPaperNumber()); } @@ -436,8 +433,8 @@ if(getPaperNumber() != null) { if(getPaperNumber().startsWith("doi")) { String[] ctx2 = getPaperNumber().substring(3).split("/"); - ctx.add(ctx2[0]); - ctx.add(ctx2[1]); + for (int i=0; i<ctx2.length; i++) + ctx.add(ctx2[i]); } else{ ctx.add(getPaperNumber()); } @@ -631,7 +628,7 @@ } else if (getQueryParam("doi") != null) { pid = getQueryParam("doi"); qs.append(" p._doi like :pid"); - } + } Integer dsmin = getCounter(); Integer dsmax = getCounter() + getLength() - 1; if(dsmin == null && dsmax == null){
More information about the HepData-svn mailing list |