Al 14/04/10 11:09, En/na ManuMohedano ha escrit:
Hi All.

Does anybody know if there is any way or patch (For 1.5.2 or 1.6 Dspace
versions) to add reference from dspace items in Refworks??

Thanks.

Manu


Hi Manu,

Yes, there is a patch for version 1.4.1 here:

http://www.mail-archive.com/[email protected]/msg10042.html

I'm attaching a modified version I've made recently for 1.5.2.

Cheers,
Àlex

=== added directory 'dspace-jspui/dspace-jspui-api/src/main/java/edu'
=== added directory 'dspace-jspui/dspace-jspui-api/src/main/java/edu/wisc'
=== added directory 'dspace-jspui/dspace-jspui-api/src/main/java/edu/wisc/doit'
=== added directory 'dspace-jspui/dspace-jspui-api/src/main/java/edu/wisc/doit/lira'
=== added directory 'dspace-jspui/dspace-jspui-api/src/main/java/edu/wisc/doit/lira/dspace'
=== added file 'dspace-jspui/dspace-jspui-api/src/main/java/edu/wisc/doit/lira/dspace/RefworksLinkTag.java'
--- dspace-jspui/dspace-jspui-api/src/main/java/edu/wisc/doit/lira/dspace/RefworksLinkTag.java	1970-01-01 00:00:00 +0000
+++ dspace-jspui/dspace-jspui-api/src/main/java/edu/wisc/doit/lira/dspace/RefworksLinkTag.java	2010-04-07 15:41:58 +0000
@@ -0,0 +1,91 @@
+/* 
+ * RefworksLinkTag.java
+ *
+ * Version: $Id: $
+ *
+ * Date: $Date: $
+ *
+ */
+package edu.wisc.doit.lira.dspace;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
+import org.dspace.core.ConfigurationManager;
+
+
+/**
+ * Renders an Refworks query link. 
+ * 
+ * 
+ * @author Rose Smith (adapted from Gabriela Mircea)
+ * @version $Revision: 1.0 $
+ */
+public class RefworksLinkTag extends TagSupport
+{
+    /** Item to display Refworks link for */
+    private String handle;
+
+    public RefworksLinkTag()
+    {
+        super();
+    }
+
+    public int doStartTag() throws JspException
+    {
+        try
+        {
+            String refServer = ConfigurationManager
+                    .getProperty("refworks.server.url");
+
+            String refServlet = ConfigurationManager
+                    .getProperty("refworks.servlet.path");
+
+           if ((refServer == null) || (refServlet == null))
+            {
+                // No RefWorks server or servlet
+                return SKIP_BODY;
+            }
+
+            HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
+            String thisURL = request.getRequestURL().toString();
+            String servletPath = request.getServletPath();
+            int i = thisURL.lastIndexOf(servletPath);
+            thisURL = thisURL.substring(0, i);
+            
+            pageContext.getOut().print(refServer  + URLEncoder.encode(thisURL + refServlet +  handle, "UTF-8") );
+        }
+        catch (IOException ie)
+        {
+            throw new JspException(ie);
+        }
+
+        return SKIP_BODY;
+    }
+
+    /**
+     * Get the handle this tag should display Refworks Link for
+     * 
+     * @return the handle
+     */
+    public String getHandle()
+    {
+        return handle;
+    }
+
+    /**
+     * Set the handle this tag should display Refworks Link for
+     * 
+     * @param handleIn
+     */
+    public void setHandle(String handleIn)
+    {
+        handle = handleIn;
+    }
+}
+
+

=== added file 'dspace-jspui/dspace-jspui-api/src/main/java/edu/wisc/doit/lira/dspace/RefworksServlet.java'
--- dspace-jspui/dspace-jspui-api/src/main/java/edu/wisc/doit/lira/dspace/RefworksServlet.java	1970-01-01 00:00:00 +0000
+++ dspace-jspui/dspace-jspui-api/src/main/java/edu/wisc/doit/lira/dspace/RefworksServlet.java	2010-04-07 15:41:58 +0000
@@ -0,0 +1,344 @@
+/*
+ * RefworksServlet.java
+ *
+ * Version: $Id: $
+ *
+ * Date: $Date: $
+ *
+ */
+
+package edu.wisc.doit.lira.dspace;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.sql.SQLException;
+import java.util.Date;
+import java.text.DateFormat;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
+import org.apache.log4j.Logger;
+
+import org.dspace.app.webui.servlet.DSpaceServlet;
+import org.dspace.content.DCPersonName;
+import org.dspace.content.DCValue;
+import org.dspace.content.Item;
+import org.dspace.core.Context;
+import org.dspace.core.LogManager;
+import org.dspace.handle.HandleManager;
+
+
+/**
+ * Servlet for exporting an item to RefWorks
+ *
+ * A handle is extracted from the query string
+ * and used to obtain the item and its DC metadata
+ * 
+ * A record in Refworks Tagged Format is assembled and output
+ * 
+ * @author Rose Smith (adapted from Gabriela Mircea)
+ * @version $Revision: 1.0 $
+ */
+public class RefworksServlet extends DSpaceServlet
+{
+    /** log4j category */
+    private static Logger log = Logger.getLogger(RefworksServlet.class);
+
+    protected void doDSGet(Context context, HttpServletRequest request,
+                           HttpServletResponse response)
+        throws ServletException, IOException, SQLException, UnsupportedEncodingException
+    {
+        // Obtain information from request
+        String handle = request.getParameter("handle");
+        Item item;
+        String exportString = null;
+                
+        if (handle != null && !handle.equals(""))
+        {
+            item = (Item) HandleManager.resolveToObject(context, handle);
+            if (item != null)
+            {
+                exportString = getExportOutput(item);
+                if (exportString != null && exportString.length() > 0) 
+                {
+                    //export the Refworks-formatted record
+                    response.setContentType("text/plain");
+                    PrintWriter out = response.getWriter();
+                    out.print(exportString);
+                    out.flush();
+                    out.close();
+                }
+            }
+            return;
+        }
+        else
+        {
+            log.info(LogManager.getHeader(context, "invalid handle", "handle=" + handle));
+            return;
+        }
+        
+    }
+
+    protected void doDSPost(Context context, HttpServletRequest request,
+                            HttpServletResponse response)
+        throws ServletException, IOException, SQLException, UnsupportedEncodingException
+    {
+        // Treat as a GET
+        doDSGet(context, request, response);
+    } 
+
+/**
+* Build the output that gets sent to Refworks
+* This code was taken from Gabriela Mircea's
+* RefworksLinkTag code for UToronto
+*/
+    private String getExportOutput(Item item) throws UnsupportedEncodingException
+    {
+        StringBuffer sb = new StringBuffer();
+        DCValue[] type = item.getDC("type", null, Item.ANY);
+        if (type.length > 0)
+        {
+            String s_type = type[0].value;
+
+            if (s_type.equals("Animation"))
+                s_type = "Computer Program";
+            else if (s_type.equals("Article"))
+                s_type = "Journal, Electronic";
+            else if (s_type.equals("Book"))
+                s_type = "Book, Whole";
+            else if (s_type.equals("Book chapter"))
+                s_type = "Book, Section";
+            else if (s_type.equals("Dataset"))
+                s_type = "Generic";
+            else if (s_type.equals("Image"))
+                s_type = "Artwork";
+            else if (s_type.equals("Image, 3-D"))
+                s_type = "Artwork";
+            else if (s_type.equals("Learning Object"))
+                s_type = "Generic";
+            else if (s_type.equals("Map"))
+                s_type = "Map";
+            else if (s_type.equals("Musical Score"))
+                s_type = "Music Score";
+            else if (s_type.equals("Other"))
+                s_type = "Generic";
+            else if (s_type.equals("Plan or blueprint"))
+                s_type = "Generic";
+            else if (s_type.equals("Preprint"))
+                s_type = "Generic";
+            else if (s_type.equals("Presentation"))
+                s_type = "Generic";
+            else if (s_type.equals("Recording, acoustical"))
+                s_type = "Sound Recording";
+            else if (s_type.equals("Recording, musical"))
+                s_type = "Sound Recording";
+            else if (s_type.equals("Recording, oral"))
+                s_type = "Sound Recording";
+            else if (s_type.equals("Software"))
+                s_type = "Computer Program";
+            else if (s_type.equals("Technical Report"))
+                s_type = "Report";
+            else if (s_type.equals("Thesis"))
+                s_type = "Dissertation/Thesis";
+            else if (s_type.equals("Video"))
+                s_type = "Video/DVD";
+            else if (s_type.equals("Working Paper"))
+                s_type = "Report";
+
+            sb.append("RT " + s_type + "\n");
+        }
+
+        DCValue[] titles = item.getDC("title", null, Item.ANY);
+ 
+        if (titles.length > 0)
+            sb.append("T1 " + titles[0].value + "\n");
+
+        DCValue[] titlesa = item.getDC("title", "alternative", Item.ANY);
+ 
+        if (titlesa.length > 0)
+            sb.append("T2 " + titlesa[0].value + "\n");
+
+        DCValue[] authors = item.getDC("contributor", "author", Item.ANY);
+    
+        if (authors.length > 0)
+        {
+            for (int i = 0; i < authors.length; i++ )
+            {
+                String auth = authors[i].value;
+                int commafirstIndex = auth.indexOf(",");
+                int commalastIndex = auth.lastIndexOf(",");
+                            
+                if ( commalastIndex > commafirstIndex)
+                {
+                    sb.append("A1 " + auth.substring(0, commalastIndex) +"\n");
+                    if (!auth.substring(commalastIndex+1).equals(null) ||!auth.substring(commalastIndex+1).equals(" ") )
+                        sb.append("AD " + auth.substring(commalastIndex+1) + "\n");
+                }
+                else
+                    sb.append("A1 " + auth +"\n");
+            }
+        }
+        
+               
+        DCValue[] editor = item.getDC("contributor", "editor", Item.ANY);
+    
+        if (editor.length > 0)
+        {
+            for (int i = 0; i < editor.length; i++ )
+            {
+            DCPersonName dpn = new DCPersonName(editor[i].value);
+            sb.append("A2 " + dpn.getLastName() + dpn.getFirstNames() +"\n");
+            }
+        }
+        
+        DCValue[] illustrator = item.getDC("contributor", "illustrator", Item.ANY);
+    
+        if (illustrator.length > 0)
+        {
+            for (int i = 0; i < illustrator.length; i++ )
+            {
+            DCPersonName dpn = new DCPersonName(illustrator[i].value);
+            sb.append("A2 " + dpn.getLastName() + dpn.getFirstNames() +"\n");
+            }
+        }
+    
+        DCValue[] other = item.getDC("contributor", "other", Item.ANY);
+    
+        if (other.length > 0)
+        {
+            for (int i = 0; i < other.length; i++ )
+            {
+            DCPersonName dpn = new DCPersonName(other[i].value);
+            sb.append("A2 " + dpn.getLastName() + dpn.getFirstNames() +"\n");
+            }
+        }
+        
+        DCValue[] keyword = item.getDC("subject", Item.ANY, Item.ANY);
+
+        if (keyword.length > 0)
+        {
+            for (int i = 0; i < keyword.length; i++ )
+            {    
+            sb.append("K1 " + keyword[i].value + "\n");
+            }
+        }
+
+        DCValue[] abs = item.getDC("description", "abstract", Item.ANY);
+    
+        if (abs.length > 0)
+        {
+            byte [] b_abs = ((abs[0].value).replaceAll("\n","").replaceAll("\r","")).getBytes("UTF-8");
+            String s_abs = new String(b_abs);
+            sb.append("AB " + s_abs + "\n");
+        }
+        
+        DCValue[] publisher = item.getDC("publisher", null, Item.ANY);
+    
+        if (publisher.length > 0)
+        {
+            sb.append("PB " + publisher[0].value + "\n");
+        }
+        
+        DCValue[] isbn = item.getDC("identifier", "isbn", Item.ANY);
+
+        if (isbn.length > 0)
+        {
+            sb.append("SN " + isbn[0].value + "\n");
+        }
+
+        DCValue[] issn = item.getDC("identifier", "issn", Item.ANY);
+
+        if (issn.length > 0)
+        {
+            sb.append("SN " + issn[0].value + "\n");
+        }
+
+        DCValue[] dates = item.getDC("date", "issued", Item.ANY);
+    
+        if (dates.length > 0)
+        {
+            String fullDate = dates[0].value;
+                   
+            String yearDate = fullDate.substring(0, 4);
+            
+            sb.append("YR " + yearDate + "\n");
+            
+            sb.append("FD " + fullDate + "\n");
+        }
+    
+        DCValue[] identifier = item.getDC("identifier", "uri", Item.ANY);
+           
+        if (identifier.length > 2)
+        {
+            for(int i =0; i < identifier.length; i++)
+                {
+                    if (identifier[i].value.startsWith("http://hdl.handle.net";))
+                        sb.append("LK " + identifier[i].value + "\n");
+                }
+        }
+        else
+        {
+            sb.append("LK " + identifier[0].value + "\n");
+        }
+         
+        DCValue[] uri = item.getDC("identifier", "uri", Item.ANY);
+        for (int i = 0; i < uri.length; i++ )
+        {
+            sb.append("UL " + uri[i].value + "\n");
+        }
+   
+        DCValue[] lang = item.getDC("language", "iso", Item.ANY);
+        if (lang.length > 0)
+        {
+            sb.append("LA " + lang[0].value + "\n");
+        }
+        
+        DCValue[] citation = item.getDC("identifier", "citation", Item.ANY);
+        DCValue[] descn = item.getDC("description", null, Item.ANY);
+        DCValue[] descs = item.getDC("description", "sponsorship", Item.ANY);
+        DCValue[] descst = item.getDC("description", "statementofresponsibility", Item.ANY);
+        DCValue[] desct = item.getDC("description", "tableofcontents", Item.ANY);
+        DCValue[] descu = item.getDC("description", "uri", Item.ANY);
+        
+        if (citation.length > 0)
+        {
+            sb.append("NO " + citation[0].value.replaceAll("\n","").replaceAll("\r","") + "\n");
+        }
+        if (descn.length > 0)
+        {
+            for (int i =0; i < descn.length; i++)
+            {
+            sb.append("NO " + descn[i].value.replaceAll("\n","").replaceAll("\r","") + "\n");
+            }
+        }
+        if (descs.length > 0)
+        {
+            sb.append("NO " + descs[0].value.replaceAll("\n","").replaceAll("\r","") + "\n");
+        }
+        if (descst.length >0)
+        {
+            sb.append("NO " + descst[0].value.replaceAll("\n","").replaceAll("\r","") + "\n");
+        }
+        if (desct.length >0)
+        {
+            sb.append("NO " + desct[0].value.replaceAll("\n","").replaceAll("\r","") + "\n");
+        }
+        if (descu.length >0)
+        {
+            byte [] b_descu = descu[0].value.replaceAll("\n","").replaceAll("\r","").getBytes("UTF-8");
+            String s_descu = new String(b_descu);
+            sb.append("NO " + s_descu + "\n");
+        }
+                 
+        sb.append("DS " + "mi...@uw" + "\n");
+         
+        Date d = new Date();
+        String df = DateFormat.getDateInstance(DateFormat.MEDIUM).format(d);
+        sb.append("RD " + df + "\n");
+         
+        return sb.toString();  
+    }
+}

=== modified file 'dspace-jspui/dspace-jspui-webapp/src/main/webapp/WEB-INF/dspace-tags.tld'
--- dspace-jspui/dspace-jspui-webapp/src/main/webapp/WEB-INF/dspace-tags.tld	2010-01-05 07:59:55 +0000
+++ dspace-jspui/dspace-jspui-webapp/src/main/webapp/WEB-INF/dspace-tags.tld	2010-04-07 15:41:58 +0000
@@ -476,5 +476,18 @@
     </attribute>    	  
   </tag>  
 
+<tag>
+   <name>reflink</name>
+   <tagclass>edu.wisc.doit.lira.dspace.RefworksLinkTag</tagclass>
+   <info>
+     Tag to display an Refworks query for a particular item.  This just gives the
+     query URL, it does not render an actual link.
+   </info>
+   <attribute>
+     <name>handle</name>
+     <required>true</required>
+     <rtexprvalue>true</rtexprvalue>
+   </attribute>
+ </tag> 
 
 </taglib>

=== modified file 'dspace-jspui/dspace-jspui-webapp/src/main/webapp/WEB-INF/web.xml'
--- dspace-jspui/dspace-jspui-webapp/src/main/webapp/WEB-INF/web.xml	2010-01-05 07:59:55 +0000
+++ dspace-jspui/dspace-jspui-webapp/src/main/webapp/WEB-INF/web.xml	2010-04-07 15:54:32 +0000
@@ -408,6 +408,10 @@
     <url-pattern>/shibboleth-login</url-pattern>
   </servlet-mapping>
  
+  <servlet>
+    <servlet-name>refworks-export</servlet-name>
+    <servlet-class>edu.wisc.doit.lira.dspace.RefworksServlet</servlet-class>
+  </servlet>
 
   <!-- Servlet Mappings -->
 
@@ -656,6 +660,15 @@
     <url-pattern>/subject-search</url-pattern>
   </servlet-mapping> 
 
+  <servlet-mapping>
+    <servlet-name>refworks-export</servlet-name>
+    <url-pattern>/refworks-export</url-pattern>
+  </servlet-mapping> 
+
+  <servlet-mapping>
+    <servlet-name>refworks-export</servlet-name>
+    <url-pattern>/refworks-export</url-pattern>
+  </servlet-mapping> 
 
   <!-- Icon MIME type -->
   <mime-mapping>

=== modified file 'dspace-jspui/dspace-jspui-webapp/src/main/webapp/display-item.jsp'
--- dspace-jspui/dspace-jspui-webapp/src/main/webapp/display-item.jsp	2010-01-05 07:59:55 +0000
+++ dspace-jspui/dspace-jspui-webapp/src/main/webapp/display-item.jsp	2010-04-07 15:41:58 +0000
@@ -242,6 +242,18 @@
 <%
     }
 %>
+    <%-- REF Link --%>
+<%
+    if (ConfigurationManager.getProperty("refworks.server.url") != null)
+    {
+%>
+    <p align="center">
+      <a href="<dspace:reflink handle="<%= handle %>"/>" target="RefWorksMain"><img src="<%= request.getContextPath() %>/image/refworks-export.png" border="0" alt="Refworks Export" /></a>
+    </p>
+<%
+    }
+%>
+
     <%-- SFX Link --%>
 <%
     if (ConfigurationManager.getProperty("sfx.server.url") != null)

=== modified file 'dspace/config/dspace.cfg'
--- dspace/config/dspace.cfg	2010-03-10 16:09:24 +0000
+++ dspace/config/dspace.cfg	2010-04-07 15:54:32 +0000
@@ -1320,6 +1320,18 @@
 # webui.mydspace.showgroupmemberships = false
 
 
+###### Refworks Citation Settings #####
+
+refworks.server.url = http://www.refworks.com/express/ExpressImport.asp?filter=Refworks%20Tagged%20Format&amp;vendor=MINDS%40UW&amp;url=
+refworks.servlet.path = /refworks-export?handle=
+
+
+###### Refworks Citation Settings #####
+
+refworks.server.url = http://www.refworks.com/express/ExpressImport.asp?filter=Refworks%20Tagged%20Format&amp;vendor=MINDS%40UW&amp;url=
+refworks.servlet.path = /refworks-export?handle=
+
+
 ##### SFX Server #####
 
 # SFX query is appended to this URL.  If this property is commented out or


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
DSpace-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-tech

Reply via email to