Skip to content

Instantly share code, notes, and snippets.

@exlcodeshare
Created June 2, 2015 11:44
Show Gist options
  • Save exlcodeshare/03a7bc09c134f3809cbd to your computer and use it in GitHub Desktop.
Save exlcodeshare/03a7bc09c134f3809cbd to your computer and use it in GitHub Desktop.
Primo Plug-in for Mendeley (PushTo Plug-in)
package com.primo.pushto.mendeley;
import java.io.IOException;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.exlibris.jaguar.xsd.search.DOCDocument.DOC;
import com.exlibris.primo.infra.utils.FileTransferUtil;
import com.exlibris.primo.interfaces.PushToInterface;
import com.exlibris.primo.xsd.commonData.PrimoResult;
public class MendeleyProcess implements PushToInterface {
private static final String VIEW_ID = "vid";
private static boolean isEmpty(String s) {
return (s == null) || (s.length() == 0);
}
private static String getViewId(HttpServletRequest request, boolean forceSession) {
String vid = null;
if (request != null) {
vid = request.getParameter(VIEW_ID);
if (isEmpty(vid)) {
vid = (String) request.getAttribute(VIEW_ID);
}
}
if (isEmpty(vid)) {
if (request != null) {
HttpSession session = request.getSession(false);
return (String) ((session != null) ? session.getAttribute(VIEW_ID) : "");
}
}
return vid;
}
public String pushTo(HttpServletRequest request, HttpServletResponse response,PrimoResult[] record,boolean fromBasket) throws Exception {
DOC resultDocumnet = record[0].getSEGMENTS().getJAGROOTArray(0).getRESULT().getDOCSET().getDOCArray(0);
String docId = resultDocumnet.getPrimoNMBib().getRecordArray(0).getControl().getRecordidArray(0);
String vid = getViewId(request, false);
String url = FileTransferUtil.getCurrentServerURL(request).replace("PushToAction.do","dlDisplay.do?") + "&afterPDS=true&docId=" + docId + "&vid=" + vid;
try {
url = URLEncoder.encode(url, "UTF-8");
} catch (Exception e) {
}
response.sendRedirect("http://www.mendeley.com/import/?url=" + url);
return null;
}
public String getFormAction(){
return null;
}
public String getContent(HttpServletRequest request,boolean fromBasket) throws IOException{
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment